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
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the streaming chat completion model types to support Structured Outputs refusals, aligning the streaming response structures with the existing non-streaming ChatResult equivalents.

Changes:

  • Add refusal: String? to ChatStreamResult.Choice.ChoiceDelta and include it in CodingKeys so it decodes from choices.delta.refusal.
  • Add refusal: [ChatCompletionTokenLogprob]? to ChatStreamResult.Choice.ChoiceLogprobs to match non-streaming logprobs support.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

2 participants