Skip to content

feat: add refusal field to streaming chat completion delta#408

Open
mvanhorn wants to merge 1 commit intoMacPaw:mainfrom
mvanhorn:feat/stream-refusal-field
Open

feat: add refusal field to streaming chat completion delta#408
mvanhorn wants to merge 1 commit intoMacPaw:mainfrom
mvanhorn:feat/stream-refusal-field

Conversation

@mvanhorn
Copy link
Copy Markdown

Summary

  • Adds refusal: String? to ChatStreamResult.Choice.ChoiceDelta, matching the existing field in ChatResult.Choice.Message
  • Adds refusal: [ChatCompletionTokenLogprob]? to ChatStreamResult.Choice.ChoiceLogprobs, matching the non-streaming logprobs
  • Adds refusal to the CodingKeys enum for correct JSON deserialization
  • swift build passes cleanly

Per the OpenAI API reference, choices.delta.refusal is returned when the model refuses to generate a response in the requested Structured Output format.

Closes #249

Test plan

  • swift build succeeds
  • Verify streaming responses with Structured Outputs that trigger a refusal now populate the refusal field

Adds the `refusal` field to the streaming chat completion delta and
logprobs, matching the existing field in ChatResult.Choice.Message.
This completes Structured Outputs support for streaming responses
per the OpenAI API specification.

Closes MacPaw#249
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant