mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
.Net: Add Structured output ChatClientAgent samples (#250)
* WIP * Structured Output sample * Update dotnet/samples/GettingStarted/Steps/Step06_ChatClientAgent_StructuredOutputs.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Address xml and comment targeting the Structured Output context * Update with proposed fix for Persistent ChatClient * Address PR feedback --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Chris <66376200+crickman@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
caee8bfa90
commit
139f033b05
@@ -371,13 +371,35 @@ namespace Azure.AI.Agents.Persistent
|
||||
{
|
||||
if (options.ResponseFormat is ChatResponseFormatJson jsonFormat)
|
||||
{
|
||||
runOptions.ResponseFormat = jsonFormat.Schema is { } schema ?
|
||||
BinaryData.FromBytes(JsonSerializer.SerializeToUtf8Bytes(new Dictionary<string, object?>()
|
||||
if (jsonFormat.Schema is JsonElement schema)
|
||||
{
|
||||
var schemaNode = JsonSerializer.SerializeToNode(schema, AgentsChatClientJsonContext.Default.JsonElement)!;
|
||||
|
||||
var jsonSchemaObject = new JsonObject
|
||||
{
|
||||
["type"] = "json_schema",
|
||||
["json_schema"] = JsonSerializer.SerializeToNode(schema, AgentsChatClientJsonContext.Default.JsonNode),
|
||||
}, AgentsChatClientJsonContext.Default.JsonObject)) :
|
||||
BinaryData.FromString("""{ "type": "json_object" }""");
|
||||
["schema"] = schemaNode
|
||||
};
|
||||
|
||||
if (jsonFormat.SchemaName is not null)
|
||||
{
|
||||
jsonSchemaObject["name"] = jsonFormat.SchemaName;
|
||||
}
|
||||
if (jsonFormat.SchemaDescription is not null)
|
||||
{
|
||||
jsonSchemaObject["description"] = jsonFormat.SchemaDescription;
|
||||
}
|
||||
|
||||
runOptions.ResponseFormat =
|
||||
BinaryData.FromBytes(JsonSerializer.SerializeToUtf8Bytes(new()
|
||||
{
|
||||
["type"] = "json_schema",
|
||||
["json_schema"] = jsonSchemaObject,
|
||||
}, AgentsChatClientJsonContext.Default.JsonObject));
|
||||
}
|
||||
else
|
||||
{
|
||||
runOptions.ResponseFormat = BinaryData.FromString("""{ "type": "json_object" }""");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user