Skip to main content
Version: 0.3.x (0.3.0)

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 build the schema with options of their own, which no transform reaches: each value object of the answer is published as 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 from Result, whose code reads, for the application to ask again.

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, by default.

schemaName string?

The name of the schema: by default the type's , or its name with every character outside [0-9A-Za-z_] replaced by _, as names it.

schemaDescription string?

The description of the schema, the type's by default.

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​

NotSupportedException

The resolver of serializerOptions has no contract for T.