Skip to content

Improve Structured Outputs Support: Add refusal field to Chat Completion Object #249

@nezhyborets

Description

@nezhyborets

Is your feature request related to a problem? Please describe.
Structured Outputs have been implemented thanks to @andgordio. With Structured Outputs they've added additional field for when model is unable to generate response in a specified format: refusal, see Refusals in Structured Outputs Guide. For more info.

The field appears in both streamable and regular chat completion objects:

  1. Chat Completion Object - choices.message.refusal API reference
  2. Chat Completion Chunk Object - choices.delta.refusal API Reference

Describe the solution you'd like
Simply add the field to our structures that represent choices.message and choices.delta. It might require refactoring though. Currently we use ChatCompletionMessageParam to both create chat completion and parse Chat Completion Object in a response. But looking at the API reference, it seems that request body and response format are different and so different Swift structured may be used for clearer distinction. Also, the separation into different types makes sense for a request, but not so much for response: API Reference does not specify such distinction, and I don't think we should either.

Describe alternatives you've considered
An alternative would be to continue using ChatCompletionMessageParam to decode Chat Completion Object, it may be faster to implement this way.

Additional context
Add any other context or screenshots about the feature request here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions