ChatClientStructuredOutputExtensions.GetResponseAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
GetResponseAsync<T>(IChatClient, ChatMessage, ChatOptions, Nullable<Boolean>, CancellationToken)
Sends a chat message, requesting a response matching the type T
.
public static System.Threading.Tasks.Task<Microsoft.Extensions.AI.ChatResponse<T>> GetResponseAsync<T>(this Microsoft.Extensions.AI.IChatClient chatClient, Microsoft.Extensions.AI.ChatMessage chatMessage, Microsoft.Extensions.AI.ChatOptions? options = default, bool? useJsonSchemaResponseFormat = default, System.Threading.CancellationToken cancellationToken = default);
static member GetResponseAsync : Microsoft.Extensions.AI.IChatClient * Microsoft.Extensions.AI.ChatMessage * Microsoft.Extensions.AI.ChatOptions * Nullable<bool> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Extensions.AI.ChatResponse<'T>>
<Extension()>
Public Function GetResponseAsync(Of T) (chatClient As IChatClient, chatMessage As ChatMessage, Optional options As ChatOptions = Nothing, Optional useJsonSchemaResponseFormat As Nullable(Of Boolean) = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ChatResponse(Of T))
Type Parameters
- T
The type of structured output to request.
Parameters
- chatClient
- IChatClient
The IChatClient.
- chatMessage
- ChatMessage
The chat message to send.
- options
- ChatOptions
The chat options to configure the request.
true
to set a JSON schema on the ChatResponseFormat; otherwise, false
. The default is true
.
Using a JSON schema improves reliability if the underlying model supports native structured output with a schema, but might cause an error if the model does not support it.
- cancellationToken
- CancellationToken
The CancellationToken to monitor for cancellation requests. The default is None.
Returns
The response messages generated by the client.
Applies to
GetResponseAsync<T>(IChatClient, IEnumerable<ChatMessage>, ChatOptions, Nullable<Boolean>, CancellationToken)
Sends chat messages, requesting a response matching the type T
.
public static System.Threading.Tasks.Task<Microsoft.Extensions.AI.ChatResponse<T>> GetResponseAsync<T>(this Microsoft.Extensions.AI.IChatClient chatClient, System.Collections.Generic.IEnumerable<Microsoft.Extensions.AI.ChatMessage> messages, Microsoft.Extensions.AI.ChatOptions? options = default, bool? useJsonSchemaResponseFormat = default, System.Threading.CancellationToken cancellationToken = default);
static member GetResponseAsync : Microsoft.Extensions.AI.IChatClient * seq<Microsoft.Extensions.AI.ChatMessage> * Microsoft.Extensions.AI.ChatOptions * Nullable<bool> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Extensions.AI.ChatResponse<'T>>
<Extension()>
Public Function GetResponseAsync(Of T) (chatClient As IChatClient, messages As IEnumerable(Of ChatMessage), Optional options As ChatOptions = Nothing, Optional useJsonSchemaResponseFormat As Nullable(Of Boolean) = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ChatResponse(Of T))
Type Parameters
- T
The type of structured output to request.
Parameters
- chatClient
- IChatClient
The IChatClient.
- messages
- IEnumerable<ChatMessage>
The chat content to send.
- options
- ChatOptions
The chat options to configure the request.
true
to set a JSON schema on the ChatResponseFormat; otherwise, false
. The default is true
.
Using a JSON schema improves reliability if the underlying model supports native structured output with a schema, but might cause an error if the model does not support it.
- cancellationToken
- CancellationToken
The CancellationToken to monitor for cancellation requests. The default is None.
Returns
The response messages generated by the client.
Applies to
GetResponseAsync<T>(IChatClient, String, ChatOptions, Nullable<Boolean>, CancellationToken)
Sends a user chat text message, requesting a response matching the type T
.
public static System.Threading.Tasks.Task<Microsoft.Extensions.AI.ChatResponse<T>> GetResponseAsync<T>(this Microsoft.Extensions.AI.IChatClient chatClient, string chatMessage, Microsoft.Extensions.AI.ChatOptions? options = default, bool? useJsonSchemaResponseFormat = default, System.Threading.CancellationToken cancellationToken = default);
static member GetResponseAsync : Microsoft.Extensions.AI.IChatClient * string * Microsoft.Extensions.AI.ChatOptions * Nullable<bool> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Extensions.AI.ChatResponse<'T>>
<Extension()>
Public Function GetResponseAsync(Of T) (chatClient As IChatClient, chatMessage As String, Optional options As ChatOptions = Nothing, Optional useJsonSchemaResponseFormat As Nullable(Of Boolean) = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ChatResponse(Of T))
Type Parameters
- T
The type of structured output to request.
Parameters
- chatClient
- IChatClient
The IChatClient.
- chatMessage
- String
The text content for the chat message to send.
- options
- ChatOptions
The chat options to configure the request.
true
to set a JSON schema on the ChatResponseFormat; otherwise, false
.
Using a JSON schema improves reliability if the underlying model supports native structured output with a schema, but might cause an error if the model does not support it.
- cancellationToken
- CancellationToken
The CancellationToken to monitor for cancellation requests. The default is None.
Returns
The response messages generated by the client.
See also
Applies to
GetResponseAsync<T>(IChatClient, ChatMessage, JsonSerializerOptions, ChatOptions, Nullable<Boolean>, CancellationToken)
Sends a chat message, requesting a response matching the type T
.
public static System.Threading.Tasks.Task<Microsoft.Extensions.AI.ChatResponse<T>> GetResponseAsync<T>(this Microsoft.Extensions.AI.IChatClient chatClient, Microsoft.Extensions.AI.ChatMessage chatMessage, System.Text.Json.JsonSerializerOptions serializerOptions, Microsoft.Extensions.AI.ChatOptions? options = default, bool? useJsonSchemaResponseFormat = default, System.Threading.CancellationToken cancellationToken = default);
static member GetResponseAsync : Microsoft.Extensions.AI.IChatClient * Microsoft.Extensions.AI.ChatMessage * System.Text.Json.JsonSerializerOptions * Microsoft.Extensions.AI.ChatOptions * Nullable<bool> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Extensions.AI.ChatResponse<'T>>
<Extension()>
Public Function GetResponseAsync(Of T) (chatClient As IChatClient, chatMessage As ChatMessage, serializerOptions As JsonSerializerOptions, Optional options As ChatOptions = Nothing, Optional useJsonSchemaResponseFormat As Nullable(Of Boolean) = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ChatResponse(Of T))
Type Parameters
- T
The type of structured output to request.
Parameters
- chatClient
- IChatClient
The IChatClient.
- chatMessage
- ChatMessage
The chat message to send.
- serializerOptions
- JsonSerializerOptions
The JSON serialization options to use.
- options
- ChatOptions
The chat options to configure the request.
true
to set a JSON schema on the ChatResponseFormat; otherwise, false
. The default is true
.
Using a JSON schema improves reliability if the underlying model supports native structured output with a schema, but might cause an error if the model does not support it.
- cancellationToken
- CancellationToken
The CancellationToken to monitor for cancellation requests. The default is None.
Returns
The response messages generated by the client.
Applies to
GetResponseAsync<T>(IChatClient, IEnumerable<ChatMessage>, JsonSerializerOptions, ChatOptions, Nullable<Boolean>, CancellationToken)
Sends chat messages, requesting a response matching the type T
.
public static System.Threading.Tasks.Task<Microsoft.Extensions.AI.ChatResponse<T>> GetResponseAsync<T>(this Microsoft.Extensions.AI.IChatClient chatClient, System.Collections.Generic.IEnumerable<Microsoft.Extensions.AI.ChatMessage> messages, System.Text.Json.JsonSerializerOptions serializerOptions, Microsoft.Extensions.AI.ChatOptions? options = default, bool? useJsonSchemaResponseFormat = default, System.Threading.CancellationToken cancellationToken = default);
static member GetResponseAsync : Microsoft.Extensions.AI.IChatClient * seq<Microsoft.Extensions.AI.ChatMessage> * System.Text.Json.JsonSerializerOptions * Microsoft.Extensions.AI.ChatOptions * Nullable<bool> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Extensions.AI.ChatResponse<'T>>
<Extension()>
Public Function GetResponseAsync(Of T) (chatClient As IChatClient, messages As IEnumerable(Of ChatMessage), serializerOptions As JsonSerializerOptions, Optional options As ChatOptions = Nothing, Optional useJsonSchemaResponseFormat As Nullable(Of Boolean) = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ChatResponse(Of T))
Type Parameters
- T
The type of structured output to request.
Parameters
- chatClient
- IChatClient
The IChatClient.
- messages
- IEnumerable<ChatMessage>
The chat content to send.
- serializerOptions
- JsonSerializerOptions
The JSON serialization options to use.
- options
- ChatOptions
The chat options to configure the request.
true
to set a JSON schema on the ChatResponseFormat; otherwise, false
. The default is true
.
Using a JSON schema improves reliability if the underlying model supports native structured output with a schema, but might cause an error if the model does not support it.
- cancellationToken
- CancellationToken
The CancellationToken to monitor for cancellation requests. The default is None.
Returns
The response messages generated by the client.
Exceptions
chatClient
or messages
or serializerOptions
is null
.
Applies to
GetResponseAsync<T>(IChatClient, String, JsonSerializerOptions, ChatOptions, Nullable<Boolean>, CancellationToken)
Sends a user chat text message, requesting a response matching the type T
.
public static System.Threading.Tasks.Task<Microsoft.Extensions.AI.ChatResponse<T>> GetResponseAsync<T>(this Microsoft.Extensions.AI.IChatClient chatClient, string chatMessage, System.Text.Json.JsonSerializerOptions serializerOptions, Microsoft.Extensions.AI.ChatOptions? options = default, bool? useJsonSchemaResponseFormat = default, System.Threading.CancellationToken cancellationToken = default);
static member GetResponseAsync : Microsoft.Extensions.AI.IChatClient * string * System.Text.Json.JsonSerializerOptions * Microsoft.Extensions.AI.ChatOptions * Nullable<bool> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Extensions.AI.ChatResponse<'T>>
<Extension()>
Public Function GetResponseAsync(Of T) (chatClient As IChatClient, chatMessage As String, serializerOptions As JsonSerializerOptions, Optional options As ChatOptions = Nothing, Optional useJsonSchemaResponseFormat As Nullable(Of Boolean) = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ChatResponse(Of T))
Type Parameters
- T
The type of structured output to request.
Parameters
- chatClient
- IChatClient
The IChatClient.
- chatMessage
- String
The text content for the chat message to send.
- serializerOptions
- JsonSerializerOptions
The JSON serialization options to use.
- options
- ChatOptions
The chat options to configure the request.
true
to set a JSON schema on the ChatResponseFormat; otherwise, false
. The default is true
.
Using a JSON schema improves reliability if the underlying model supports native structured output with a schema, but might cause an error if the model does not support it.
- cancellationToken
- CancellationToken
The CancellationToken to monitor for cancellation requests. The default is None.
Returns
The response messages generated by the client.