You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Rename useJsonSchema parameter
The `GetResponseAsync<T>` methods accept a `bool?` parameter currently called `useJsonSchema`. This is confusing, because the whole point of the method is to create and use a JSON schema from the `T`. The parameter actually controls _how_ that schema is used, whether it's included as part of the messages (false), as part of a ChatResponseFormat in the ChatOptions (true), or up to the system to decide.
I've clarified it by renaming it from `useJsonSchema` to `useJsonSchemaResponseFormat`. It's wordier, but it disambiguates the intent.
* Update src/Libraries/Microsoft.Extensions.AI/ChatCompletion/ChatClientStructuredOutputExtensions.cs
Co-authored-by: Eirik Tsarpalis <[email protected]>
---------
Co-authored-by: Eirik Tsarpalis <[email protected]>
/// <param name="messages">The chat content to send.</param>
35
35
/// <param name="options">The chat options to configure the request.</param>
36
-
/// <param name="useJsonSchema">
36
+
/// <param name="useJsonSchemaResponseFormat">
37
37
/// <see langword="true" /> to set a JSON schema on the <see cref="ChatResponseFormat"/>; otherwise, <see langword="false" />. The default is <see langword="true" />.
38
38
/// 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.
39
39
/// </param>
@@ -44,19 +44,17 @@ public static Task<ChatResponse<T>> GetResponseAsync<T>(
/// <param name="chatMessage">The text content for the chat message to send.</param>
54
54
/// <param name="options">The chat options to configure the request.</param>
55
-
/// <param name="useJsonSchema">
55
+
/// <param name="useJsonSchemaResponseFormat">
56
56
/// <see langword="true" /> to set a JSON schema on the <see cref="ChatResponseFormat"/>; otherwise, <see langword="false" />.
57
57
/// 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.
58
-
/// If not specified, the default value is determined by the implementation.
59
-
/// If a specific value is required, it must be specified by the caller.
60
58
/// </param>
61
59
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
62
60
/// <returns>The response messages generated by the client.</returns>
@@ -66,15 +64,15 @@ public static Task<ChatResponse<T>> GetResponseAsync<T>(
/// <param name="chatMessage">The chat message to send.</param>
76
74
/// <param name="options">The chat options to configure the request.</param>
77
-
/// <param name="useJsonSchema">
75
+
/// <param name="useJsonSchemaResponseFormat">
78
76
/// <see langword="true" /> to set a JSON schema on the <see cref="ChatResponseFormat"/>; otherwise, <see langword="false" />. The default is <see langword="true" />.
79
77
/// 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.
80
78
/// </param>
@@ -85,16 +83,16 @@ public static Task<ChatResponse<T>> GetResponseAsync<T>(
/// <param name="chatMessage">The text content for the chat message to send.</param>
95
93
/// <param name="serializerOptions">The JSON serialization options to use.</param>
96
94
/// <param name="options">The chat options to configure the request.</param>
97
-
/// <param name="useJsonSchema">
95
+
/// <param name="useJsonSchemaResponseFormat">
98
96
/// <see langword="true" /> to set a JSON schema on the <see cref="ChatResponseFormat"/>; otherwise, <see langword="false" />. The default is <see langword="true" />.
99
97
/// 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.
100
98
/// </param>
@@ -106,16 +104,16 @@ public static Task<ChatResponse<T>> GetResponseAsync<T>(
/// <param name="chatMessage">The chat message to send.</param>
116
114
/// <param name="serializerOptions">The JSON serialization options to use.</param>
117
115
/// <param name="options">The chat options to configure the request.</param>
118
-
/// <param name="useJsonSchema">
116
+
/// <param name="useJsonSchemaResponseFormat">
119
117
/// <see langword="true" /> to set a JSON schema on the <see cref="ChatResponseFormat"/>; otherwise, <see langword="false" />. The default is <see langword="true" />.
120
118
/// 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.
121
119
/// </param>
@@ -127,16 +125,16 @@ public static Task<ChatResponse<T>> GetResponseAsync<T>(
/// <param name="messages">The chat content to send.</param>
137
135
/// <param name="serializerOptions">The JSON serialization options to use.</param>
138
136
/// <param name="options">The chat options to configure the request.</param>
139
-
/// <param name="useJsonSchema">
137
+
/// <param name="useJsonSchemaResponseFormat">
140
138
/// <see langword="true" /> to set a JSON schema on the <see cref="ChatResponseFormat"/>; otherwise, <see langword="false" />. The default is <see langword="true" />.
141
139
/// 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.
142
140
/// </param>
@@ -149,7 +147,7 @@ public static async Task<ChatResponse<T>> GetResponseAsync<T>(
149
147
IEnumerable<ChatMessage>messages,
150
148
JsonSerializerOptionsserializerOptions,
151
149
ChatOptions?options=null,
152
-
bool?useJsonSchema=null,
150
+
bool?useJsonSchemaResponseFormat=null,
153
151
CancellationTokencancellationToken=default)
154
152
{
155
153
_=Throw.IfNull(chatClient);
@@ -192,8 +190,8 @@ public static async Task<ChatResponse<T>> GetResponseAsync<T>(
192
190
193
191
// We default to assuming that models support JSON schema because developers will normally use
194
192
// GetResponseAsync<T> only with models that do. If the model doesn't support JSON schema, it may
195
-
// throw or it may ignore the schema. In these cases developers should pass useJsonSchema: false.
196
-
if(useJsonSchema.GetValueOrDefault(true))
193
+
// throw or it may ignore the schema. In these cases developers should pass useJsonSchemaResponseFormat: false.
194
+
if(useJsonSchemaResponseFormat??true)
197
195
{
198
196
// When using native structured output, we don't add any additional prompt, because
199
197
// the LLM backend is meant to do whatever's needed to explain the schema to the LLM.
0 commit comments