ChatClientStructuredOutputExtensions.GetResponseAsync Method

Definition

Overloads

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

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

C#
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? useNativeJsonSchema = default, System.Threading.CancellationToken cancellationToken = default);

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.

useNativeJsonSchema
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 underlying provider's default will be used.

cancellationToken
CancellationToken

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

Returns

The response messages generated by the client.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)

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

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

C#
public static System.Threading.Tasks.Task<Microsoft.Extensions.AI.ChatResponse<T>> GetResponseAsync<T>(this Microsoft.Extensions.AI.IChatClient chatClient, System.Collections.Generic.IList<Microsoft.Extensions.AI.ChatMessage> chatMessages, Microsoft.Extensions.AI.ChatOptions? options = default, bool? useNativeJsonSchema = default, System.Threading.CancellationToken cancellationToken = default);

Type Parameters

T

The type of structured output to request.

Parameters

chatClient
IChatClient

The IChatClient.

chatMessages
IList<ChatMessage>

The chat content to send.

options
ChatOptions

The chat options to configure the request.

useNativeJsonSchema
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 underlying provider's default will be used.

cancellationToken
CancellationToken

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

Returns

The response messages generated by the client.

Remarks

The returned messages will not have been added to chatMessages. However, any intermediate messages generated implicitly by the client, including any messages for roundtrips to the model as part of the implementation of this request, will be included.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)

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

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

C#
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? useNativeJsonSchema = default, System.Threading.CancellationToken cancellationToken = default);

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.

useNativeJsonSchema
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 underlying provider's default will be used.

cancellationToken
CancellationToken

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

Returns

The response messages generated by the client.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)

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

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

C#
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? useNativeJsonSchema = default, System.Threading.CancellationToken cancellationToken = default);

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.

useNativeJsonSchema
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 underlying provider's default will be used.

cancellationToken
CancellationToken

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

Returns

The response messages generated by the client.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)

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

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

C#
public static System.Threading.Tasks.Task<Microsoft.Extensions.AI.ChatResponse<T>> GetResponseAsync<T>(this Microsoft.Extensions.AI.IChatClient chatClient, System.Collections.Generic.IList<Microsoft.Extensions.AI.ChatMessage> chatMessages, System.Text.Json.JsonSerializerOptions serializerOptions, Microsoft.Extensions.AI.ChatOptions? options = default, bool? useNativeJsonSchema = default, System.Threading.CancellationToken cancellationToken = default);

Type Parameters

T

The type of structured output to request.

Parameters

chatClient
IChatClient

The IChatClient.

chatMessages
IList<ChatMessage>

The chat content to send.

serializerOptions
JsonSerializerOptions

The JSON serialization options to use.

options
ChatOptions

The chat options to configure the request.

useNativeJsonSchema
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 underlying provider's default will be used.

cancellationToken
CancellationToken

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

Returns

The response messages generated by the client.

Remarks

The returned messages will not have been added to chatMessages. However, any intermediate messages generated implicitly by the client, including any messages for roundtrips to the model as part of the implementation of this request, will be included.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)

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

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

C#
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? useNativeJsonSchema = default, System.Threading.CancellationToken cancellationToken = default);

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.

useNativeJsonSchema
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 underlying provider's default will be used.

cancellationToken
CancellationToken

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

Returns

The response messages generated by the client.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided)