semantic-kernel icon indicating copy to clipboard operation
semantic-kernel copied to clipboard

.Net: OpenAI - Support response_format type of json_schema

Open jonnermut opened this issue 1 year ago • 1 comments

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.

jonnermut avatar Aug 07 '24 01:08 jonnermut

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
      }
    }
  }
}

rogerbarreto avatar Aug 07 '24 08:08 rogerbarreto

It looks like OpenAI SDK work has been completed! Looking forward to having this in SK soon!

papa-pep avatar Aug 27 '24 17:08 papa-pep

This is complete in Python as of #8958.

moonbox3 avatar Oct 31 '24 15:10 moonbox3

This issue is stale because it has been open for 90 days with no activity.

github-actions[bot] avatar Apr 29 '25 02:04 github-actions[bot]