Share via


ChatClientStructuredOutputExtensions.GetResponseAsync Method

Definition

Overloads

GetResponseAsync<T>(IChatClient, ChatMessage, ChatOptions, Nullable<Boolean>, CancellationToken)

Sends a chat message, requesting a response matching the type T.

GetResponseAsync<T>(IChatClient, IEnumerable<ChatMessage>, ChatOptions, Nullable<Boolean>, CancellationToken)

Sends chat messages, requesting a response matching the type T.

GetResponseAsync<T>(IChatClient, String, ChatOptions, Nullable<Boolean>, CancellationToken)

Sends a user chat text message, requesting a response matching the type T.

GetResponseAsync<T>(IChatClient, ChatMessage, JsonSerializerOptions, ChatOptions, Nullable<Boolean>, CancellationToken)

Sends a chat message, requesting a response matching the type T.

GetResponseAsync<T>(IChatClient, IEnumerable<ChatMessage>, JsonSerializerOptions, ChatOptions, Nullable<Boolean>, CancellationToken)

Sends chat messages, requesting a response matching the type T.

GetResponseAsync<T>(IChatClient, String, JsonSerializerOptions, ChatOptions, Nullable<Boolean>, CancellationToken)

Sends a user chat text message, requesting a response matching the type T.

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? useJsonSchema = 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 useJsonSchema 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.

useJsonSchema
Nullable<Boolean>

Optionally specifies whether to set a JSON schema on the ChatResponseFormat. This improves reliability if the underlying model supports native structured output with a schema, but may cause an error if the model does not support it. If not specified, the default value is true.

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? useJsonSchema = 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 useJsonSchema 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.

useJsonSchema
Nullable<Boolean>

Optionally specifies whether to set a JSON schema on the ChatResponseFormat. This improves reliability if the underlying model supports native structured output with a schema, but may cause an error if the model does not support it. If not specified, the default value is true.

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? useJsonSchema = 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 useJsonSchema 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.

useJsonSchema
Nullable<Boolean>

Optionally specifies whether to set a JSON schema on the ChatResponseFormat. This improves reliability if the underlying model supports native structured output with a schema, but may cause an error if the model does not support it. If not specified, the default value is determined by the implementation. If a specific value is required, it must be specified by the caller.

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, 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? useJsonSchema = 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 useJsonSchema 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.

useJsonSchema
Nullable<Boolean>

Optionally specifies whether to set a JSON schema on the ChatResponseFormat. This improves reliability if the underlying model supports native structured output with a schema, but may cause an error if the model does not support it. If not specified, the default value is true.

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? useJsonSchema = 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 useJsonSchema 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.

useJsonSchema
Nullable<Boolean>

Optionally specifies whether to set a JSON schema on the ChatResponseFormat. This improves reliability if the underlying model supports native structured output with a schema, but may cause an error if the model does not support it. If not specified, the default value is true.

cancellationToken
CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

The response messages generated by the client.

Exceptions

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? useJsonSchema = 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 useJsonSchema 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.

useJsonSchema
Nullable<Boolean>

Optionally specifies whether to set a JSON schema on the ChatResponseFormat. This improves reliability if the underlying model supports native structured output with a schema, but may cause an error if the model does not support it. If not specified, the default value is true.

cancellationToken
CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

The response messages generated by the client.

Applies to