diff --git a/src/Libraries/Microsoft.Extensions.AI/ChatCompletion/ChatClientStructuredOutputExtensions.cs b/src/Libraries/Microsoft.Extensions.AI/ChatCompletion/ChatClientStructuredOutputExtensions.cs index 0e7b20bade6..d7bc12a1a41 100644 --- a/src/Libraries/Microsoft.Extensions.AI/ChatCompletion/ChatClientStructuredOutputExtensions.cs +++ b/src/Libraries/Microsoft.Extensions.AI/ChatCompletion/ChatClientStructuredOutputExtensions.cs @@ -33,7 +33,7 @@ public static class ChatClientStructuredOutputExtensions /// The . /// The chat content to send. /// The chat options to configure the request. - /// + /// /// to set a JSON schema on the ; otherwise, . The default is . /// 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. /// @@ -44,19 +44,17 @@ public static Task> GetResponseAsync( this IChatClient chatClient, IEnumerable messages, ChatOptions? options = null, - bool? useJsonSchema = null, + bool? useJsonSchemaResponseFormat = null, CancellationToken cancellationToken = default) => - GetResponseAsync(chatClient, messages, AIJsonUtilities.DefaultOptions, options, useJsonSchema, cancellationToken); + GetResponseAsync(chatClient, messages, AIJsonUtilities.DefaultOptions, options, useJsonSchemaResponseFormat, cancellationToken); /// Sends a user chat text message, requesting a response matching the type . /// The . /// The text content for the chat message to send. /// The chat options to configure the request. - /// + /// /// to set a JSON schema on the ; otherwise, . /// 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. - /// If not specified, the default value is determined by the implementation. - /// If a specific value is required, it must be specified by the caller. /// /// The to monitor for cancellation requests. The default is . /// The response messages generated by the client. @@ -66,15 +64,15 @@ public static Task> GetResponseAsync( this IChatClient chatClient, string chatMessage, ChatOptions? options = null, - bool? useJsonSchema = null, + bool? useJsonSchemaResponseFormat = null, CancellationToken cancellationToken = default) => - GetResponseAsync(chatClient, new ChatMessage(ChatRole.User, chatMessage), options, useJsonSchema, cancellationToken); + GetResponseAsync(chatClient, new ChatMessage(ChatRole.User, chatMessage), options, useJsonSchemaResponseFormat, cancellationToken); /// Sends a chat message, requesting a response matching the type . /// The . /// The chat message to send. /// The chat options to configure the request. - /// + /// /// to set a JSON schema on the ; otherwise, . The default is . /// 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. /// @@ -85,16 +83,16 @@ public static Task> GetResponseAsync( this IChatClient chatClient, ChatMessage chatMessage, ChatOptions? options = null, - bool? useJsonSchema = null, + bool? useJsonSchemaResponseFormat = null, CancellationToken cancellationToken = default) => - GetResponseAsync(chatClient, [chatMessage], options, useJsonSchema, cancellationToken); + GetResponseAsync(chatClient, [chatMessage], options, useJsonSchemaResponseFormat, cancellationToken); /// Sends a user chat text message, requesting a response matching the type . /// The . /// The text content for the chat message to send. /// The JSON serialization options to use. /// The chat options to configure the request. - /// + /// /// to set a JSON schema on the ; otherwise, . The default is . /// 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. /// @@ -106,16 +104,16 @@ public static Task> GetResponseAsync( string chatMessage, JsonSerializerOptions serializerOptions, ChatOptions? options = null, - bool? useJsonSchema = null, + bool? useJsonSchemaResponseFormat = null, CancellationToken cancellationToken = default) => - GetResponseAsync(chatClient, new ChatMessage(ChatRole.User, chatMessage), serializerOptions, options, useJsonSchema, cancellationToken); + GetResponseAsync(chatClient, new ChatMessage(ChatRole.User, chatMessage), serializerOptions, options, useJsonSchemaResponseFormat, cancellationToken); /// Sends a chat message, requesting a response matching the type . /// The . /// The chat message to send. /// The JSON serialization options to use. /// The chat options to configure the request. - /// + /// /// to set a JSON schema on the ; otherwise, . The default is . /// 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. /// @@ -127,16 +125,16 @@ public static Task> GetResponseAsync( ChatMessage chatMessage, JsonSerializerOptions serializerOptions, ChatOptions? options = null, - bool? useJsonSchema = null, + bool? useJsonSchemaResponseFormat = null, CancellationToken cancellationToken = default) => - GetResponseAsync(chatClient, [chatMessage], serializerOptions, options, useJsonSchema, cancellationToken); + GetResponseAsync(chatClient, [chatMessage], serializerOptions, options, useJsonSchemaResponseFormat, cancellationToken); /// Sends chat messages, requesting a response matching the type . /// The . /// The chat content to send. /// The JSON serialization options to use. /// The chat options to configure the request. - /// + /// /// to set a JSON schema on the ; otherwise, . The default is . /// 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. /// @@ -149,7 +147,7 @@ public static async Task> GetResponseAsync( IEnumerable messages, JsonSerializerOptions serializerOptions, ChatOptions? options = null, - bool? useJsonSchema = null, + bool? useJsonSchemaResponseFormat = null, CancellationToken cancellationToken = default) { _ = Throw.IfNull(chatClient); @@ -192,8 +190,8 @@ public static async Task> GetResponseAsync( // We default to assuming that models support JSON schema because developers will normally use // GetResponseAsync only with models that do. If the model doesn't support JSON schema, it may - // throw or it may ignore the schema. In these cases developers should pass useJsonSchema: false. - if (useJsonSchema.GetValueOrDefault(true)) + // throw or it may ignore the schema. In these cases developers should pass useJsonSchemaResponseFormat: false. + if (useJsonSchemaResponseFormat ?? true) { // When using native structured output, we don't add any additional prompt, because // the LLM backend is meant to do whatever's needed to explain the schema to the LLM. diff --git a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ChatClientIntegrationTests.cs b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ChatClientIntegrationTests.cs index 22531e14e22..0e4311a227a 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ChatClientIntegrationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ChatClientIntegrationTests.cs @@ -942,7 +942,7 @@ public virtual async Task GetResponseAsync_StructuredOutput_NonNative() var response = await captureOutputChatClient.GetResponseAsync(""" Supply an object to represent Jimbo Smith from Cardiff. - """, useJsonSchema: false); + """, useJsonSchemaResponseFormat: false); Assert.Equal("Jimbo Smith", response.Result.FullName); Assert.Contains("Cardiff", response.Result.HomeTown); diff --git a/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/ChatClientStructuredOutputExtensionsTests.cs b/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/ChatClientStructuredOutputExtensionsTests.cs index 557eecc3c29..aae985c4c4b 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/ChatClientStructuredOutputExtensionsTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/ChatClientStructuredOutputExtensionsTests.cs @@ -139,7 +139,7 @@ public async Task SuccessUsage_NoJsonSchema() }; var chatHistory = new List { new(ChatRole.User, "Hello") }; - var response = await client.GetResponseAsync(chatHistory, useJsonSchema: false, serializerOptions: JsonContext2.Default.Options); + var response = await client.GetResponseAsync(chatHistory, useJsonSchemaResponseFormat: false, serializerOptions: JsonContext2.Default.Options); // The response contains the deserialized result and other response properties Assert.Equal(1, response.Result.Id);