ChatCompletionsResponseFormat.CreateJsonFormat 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
CreateJsonFormat() |
Creates a new ChatCompletionsResponseFormat requesting valid JSON, a.k.a. JSON mode. |
CreateJsonFormat(String, IDictionary<String,BinaryData>, String, Nullable<Boolean>) |
Creates a new ChatCompletionsResponseFormat requesting adherence to the specified JSON schema, a.k.a. structured outputs. |
CreateJsonFormat()
Creates a new ChatCompletionsResponseFormat requesting valid JSON, a.k.a. JSON mode.
public static Azure.AI.Inference.ChatCompletionsResponseFormat CreateJsonFormat();
static member CreateJsonFormat : unit -> Azure.AI.Inference.ChatCompletionsResponseFormat
Public Shared Function CreateJsonFormat () As ChatCompletionsResponseFormat
Returns
Applies to
CreateJsonFormat(String, IDictionary<String,BinaryData>, String, Nullable<Boolean>)
Creates a new ChatCompletionsResponseFormat requesting adherence to the specified JSON schema, a.k.a. structured outputs.
public static Azure.AI.Inference.ChatCompletionsResponseFormat CreateJsonFormat(string jsonSchemaFormatName, System.Collections.Generic.IDictionary<string,BinaryData> jsonSchema, string jsonSchemaFormatDescription = default, bool? jsonSchemaIsStrict = default);
static member CreateJsonFormat : string * System.Collections.Generic.IDictionary<string, BinaryData> * string * Nullable<bool> -> Azure.AI.Inference.ChatCompletionsResponseFormat
Public Shared Function CreateJsonFormat (jsonSchemaFormatName As String, jsonSchema As IDictionary(Of String, BinaryData), Optional jsonSchemaFormatDescription As String = Nothing, Optional jsonSchemaIsStrict As Nullable(Of Boolean) = Nothing) As ChatCompletionsResponseFormat
Parameters
- jsonSchemaFormatName
- String
The name of the response format.
- jsonSchema
- IDictionary<String,BinaryData>
The schema of the response format, described as a JSON schema. Learn more in the structured outputs guide. and the JSON schema reference documentation.
You can easily create a JSON schema via the factory methods of the BinaryData class, such as FromBytes(Byte[]) or FromString(String). For example, the following code defines a simple schema for step-by-step responses to math problems:
BinaryData jsonSchema = BinaryData.FromBytes("""
{
"type": "object",
"properties": {
"steps": {
"type": "array",
"items": {
"type": "object",
"properties": {
"explanation": {"type": "string"},
"output": {"type": "string"}
},
"required": ["explanation", "output"],
"additionalProperties": false
}
},
"final_answer": {"type": "string"}
},
"required": ["steps", "final_answer"],
"additionalProperties": false
}
"""U8.ToArray());
- jsonSchemaFormatDescription
- String
The description of what the response format is for, which is used by the model to determine how to respond in the format.
Whether to enable strict schema adherence when generating the response. If set to true
, the
model will follow the exact schema defined in jsonSchema
.
Only a subset of the JSON schema specification is supported when this is set to true
. Learn more
in the
structured outputs guide.
Returns
Exceptions
jsonSchemaFormatName
or jsonSchema
is null.
jsonSchemaFormatName
is an empty string, and was expected to be non-empty.
Applies to
Azure SDK for .NET