.Net: OpenAI - Support response_format type of json_schema
The latest OpenAI models allow passing json_schema as the response_format type property, and supplying the schema itself under the schema property. This enforces conformance to the schema by validating output tokens, rather than best LLM effort.
Announced here: https://openai.com/index/introducing-structured-outputs-in-the-api/
This is obviously massively useful to any application using json output, especially when deserialising the json to C# types. Please consider adding support for these properties through the SemanticKernel abstractions and .Net client in the short term.
Update with more context.
Created issue in OpenAI SDK .Net to keep track.
- https://github.com/openai/openai-dotnet/issues/160
POST /v1/chat/completions
{
"model": "gpt-4o-2024-08-06",
"messages": [
{
"role": "system",
"content": "You are a helpful math tutor."
},
{
"role": "user",
"content": "solve 8x + 31 = 2"
}
],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "math_response",
"strict": true,
"schema": {
"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
}
}
}
}
It looks like OpenAI SDK work has been completed! Looking forward to having this in SK soon!
This is complete in Python as of #8958.
This issue is stale because it has been open for 90 days with no activity.