Open jonnermut opened 2 months ago
Update with more context.
Created issue in OpenAI SDK .Net to keep track.
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!
The latest OpenAI models allow passing
json_schema
as theresponse_format
type
property, and supplying the schema itself under theschema
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.