語言

ChatResponseFormat.ForJsonSchema 方法

定義

建立 ChatResponseFormatJson 一個代表結構化 JSON 資料,並附上指定的結構化 JSON。

多載

名稱 Description
ForJsonSchema(JsonElement, String, String)

建立 ChatResponseFormatJson 一個代表結構化 JSON 資料,並附上指定的結構化 JSON。

ForJsonSchema(Type, JsonSerializerOptions, String, String)

建立 ChatResponseFormatJson 一個以結構化 JSON 為基礎 schemaType的結構化 JSON 資料。

ForJsonSchema<T>(JsonSerializerOptions, String, String)

建立 ChatResponseFormatJson 一個以結構化 JSON 為基礎 T的結構化 JSON 資料。

ForJsonSchema(JsonElement, String, String)

建立 ChatResponseFormatJson 一個代表結構化 JSON 資料,並附上指定的結構化 JSON。

public static Microsoft.Extensions.AI.ChatResponseFormatJson ForJsonSchema(System.Text.Json.JsonElement schema, string? schemaName = default, string? schemaDescription = default);
static member ForJsonSchema : System.Text.Json.JsonElement * string * string -> Microsoft.Extensions.AI.ChatResponseFormatJson
Public Shared Function ForJsonSchema (schema As JsonElement, Optional schemaName As String = Nothing, Optional schemaDescription As String = Nothing) As ChatResponseFormatJson

參數

schema
JsonElement

JSON 架構。

schemaName
String

架構的可選名稱。 例如,若該結構代表特定類別,則該類別名稱可能。

schemaDescription
String

這是該結構的可選描述。

傳回

ChatResponseFormatJson 執行個體。

適用於

ForJsonSchema(Type, JsonSerializerOptions, String, String)

建立 ChatResponseFormatJson 一個以結構化 JSON 為基礎 schemaType的結構化 JSON 資料。

public static Microsoft.Extensions.AI.ChatResponseFormatJson ForJsonSchema(Type schemaType, System.Text.Json.JsonSerializerOptions? serializerOptions = default, string? schemaName = default, string? schemaDescription = default);
static member ForJsonSchema : Type * System.Text.Json.JsonSerializerOptions * string * string -> Microsoft.Extensions.AI.ChatResponseFormatJson
Public Shared Function ForJsonSchema (schemaType As Type, Optional serializerOptions As JsonSerializerOptions = Nothing, Optional schemaName As String = Nothing, Optional schemaDescription As String = Nothing) As ChatResponseFormatJson

參數

schemaType
Type

Type該模式應匯出並作為回應架構使用。

serializerOptions
JsonSerializerOptions

可以使用 JSON 序列化選項。

schemaName
String

架構的可選名稱。 預設情況下,此值將由 推斷出 schemaType。

schemaDescription
String

這是該結構的可選描述。 預設情況下,此值將由 推斷出 schemaType。

傳回

ChatResponseFormatJson 執行個體。

例外狀況

schemaType 是 null。

備註

許多支援結構化輸出的 AI 服務要求 JSON 架構頂層的「type=object」。 如果schemaType是像 、 、 StringInt32或 這樣的原始型別Boolean,或是以 JSON 陣列序列化的型態,嘗試使用這些服務的結構可能會失敗。 在這種情況下,可以考慮使用 一個 schemaType 將實際型別包裝成類別或結構體,使其序列化為帶有原始型別的 JSON 物件。

適用於

ForJsonSchema<T>(JsonSerializerOptions, String, String)

建立 ChatResponseFormatJson 一個以結構化 JSON 為基礎 T的結構化 JSON 資料。

public static Microsoft.Extensions.AI.ChatResponseFormatJson ForJsonSchema<T>(System.Text.Json.JsonSerializerOptions? serializerOptions = default, string? schemaName = default, string? schemaDescription = default);
static member ForJsonSchema : System.Text.Json.JsonSerializerOptions * string * string -> Microsoft.Extensions.AI.ChatResponseFormatJson
Public Shared Function ForJsonSchema(Of T) (Optional serializerOptions As JsonSerializerOptions = Nothing, Optional schemaName As String = Nothing, Optional schemaDescription As String = Nothing) As ChatResponseFormatJson

類型參數

T

應匯出並用作回應結構的型別。

參數

serializerOptions
JsonSerializerOptions

可以使用 JSON 序列化選項。

schemaName
String

架構的可選名稱。 預設情況下,此值將由 推斷出 T。

schemaDescription
String

這是該結構的可選描述。 預設情況下,此值將由 推斷出 T。

傳回

ChatResponseFormatJson 執行個體。

備註

許多支援結構化輸出的 AI 服務要求 JSON 架構頂層的「type=object」。 如果T是像 、 、 StringInt32或 這樣的原始型別Boolean,或是以 JSON 陣列序列化的型態,嘗試使用這些服務的結構可能會失敗。 在這種情況下,可以考慮使用 一個 T 將實際型別包裝成類別或結構體,使其序列化為帶有原始型別的 JSON 物件。

適用於