Class ValueObjectResponseFormat
Namespace: AdCodicem.ValueObjects.AI
Assembly: AdCodicem.ValueObjects.AI.dll
Builds the JSON schema response format of a structured output whose value objects carry their rules.
public static class ValueObjectResponseFormat
Inheritance
object ← ValueObjectResponseFormat
Inherited Members
object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()
Remarks
GetResponseAsync<T> and true, and a list of
them as "items": {}. This builds the same format with the rules of every value object it holds, and the
answer is read the way GetResponseAsync<T> reads it:
ChatResponse response = await chatClient.GetResponseAsync(
messages,
new ChatOptions { ResponseFormat = ValueObjectResponseFormat.ForJsonSchema<Order>(AppJsonContext.Default.Options) });
var order = new ChatResponse<Order>(response, AppJsonContext.Default.Options).Result;
The same rules validate the answer as it is read: a value the model wrote that a value object refuses throws a
Result, whose code
Methods
ForJsonSchema<T>(JsonSerializerOptions?, string?, string?)
Creates a JSON schema response format for T, with the rules of every value object it holds.
public static ChatResponseFormatJson ForJsonSchema<T>(JsonSerializerOptions? serializerOptions = null, string? schemaName = null, string? schemaDescription = null)
Parameters
serializerOptions JsonSerializerOptions?
The options the answer is read with,
schemaName string?
The name of the schema: by default the type's [0-9A-Za-z_] replaced by _, as
schemaDescription string?
The description of the schema, the type's
Returns
ChatResponseFormatJson
The response format, its schema led by $schema, as Microsoft.Extensions.AI writes one.
Type Parameters
T
The type of the structured output, which serializes as a JSON object.
Exceptions
The resolver of serializerOptions has no contract for T.