Skip to content

Add support for response_format type json_schema #377

@craigmiller160

Description

@craigmiller160

Feature Description

OpenAI has added support for structured outputs in its API: https://openai.com/index/introducing-structured-outputs-in-the-api/

Ultimately, this means the existing ChatResponseFormat is inadequate. While I could use the class to declare a type of json_schema in the response format, ultimately I won't be able to actually provide the schema in this fashion.

Problem it Solves

Adding support for this OpenAPI feature.

Proposed Solution

If you don't have time to fully implement this, a simpler and more flexible option would be as follows:

  1. Make a parent interface for ChatResponseFormat that is implemented by the current class. Let's call it GenericChatResponseFormat, you can decide on a better name.
  2. Make ChatCompletionRequest.responseFormat be of this new type (GenericChatResponseFormat).
  3. Anyone can now implement their own response format.
  4. Your code just serializes the format and provides it to OpenAI in the request.

Obviously a full implementation of the structured output would be desirable, but this may be an alternative approach to quickly achieve the same thing.

Additional Context

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions