Skip to content

Conversation

@majiayu000
Copy link

Fixes #1073

Changes

  • Changed Stream field from bool to *bool in ChatCompletionRequest and CompletionRequest
  • Added TruePtr() and FalsePtr() helper functions for setting stream values
  • Updated internal stream handling and tests accordingly

This allows users to explicitly set stream=false in JSON serialization, which was previously omitted due to omitempty behavior on boolean zero values.

🤖 Generated with Claude Code

Change Stream field from bool to *bool in ChatCompletionRequest and
CompletionRequest to allow explicit stream=false in JSON serialization.

Previously, the Stream field used `json:"stream,omitempty"` which caused
stream=false to be omitted from JSON since false is the zero value for bool.
Some API implementations require stream=false to be explicitly present.

With this change:
- Stream: nil → field omitted (user doesn't care)
- Stream: FalsePtr() → "stream": false explicitly in JSON
- Stream: TruePtr() → "stream": true explicitly in JSON

Also adds TruePtr() and FalsePtr() helper functions for convenience.

Fixes sashabaranov#1073

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Signed-off-by: majiayu000 <[email protected]>
@codecov
Copy link

codecov bot commented Dec 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.62%. Comparing base (5d7a276) to head (823ddb6).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1099      +/-   ##
==========================================
+ Coverage   99.59%   99.62%   +0.02%     
==========================================
  Files          34       34              
  Lines        2209     1847     -362     
==========================================
- Hits         2200     1840     -360     
+ Misses          6        4       -2     
  Partials        3        3              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
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 fixes an issue where the stream=false field was being omitted from JSON serialization due to Go's omitempty behavior with boolean zero values. The PR changes the Stream field from bool to *bool in both ChatCompletionRequest and CompletionRequest, allowing explicit control over whether the field is included in the JSON output.

Changes:

  • Changed Stream field type from bool to *bool in ChatCompletionRequest and CompletionRequest structures
  • Added TruePtr() and FalsePtr() helper functions for convenient stream value assignment
  • Updated all internal usages and tests to use pointer-based stream handling

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
chat.go Added helper functions TruePtr() and FalsePtr(), changed Stream field to *bool, updated nil check in CreateChatCompletion
completion.go Changed Stream field to *bool, updated nil check in CreateCompletion
chat_stream.go Updated to use TruePtr() when setting Stream in CreateChatCompletionStream
stream.go Updated to use TruePtr() when setting Stream in CreateCompletionStream
chat_test.go Added comprehensive tests for stream field JSON marshaling behavior, updated existing test to use pointer
chat_stream_test.go Updated all test usages to use TruePtr()
stream_test.go Updated all test usages to use TruePtr()
completion_test.go Updated test to use pointer-based stream value
example_test.go Updated examples to use TruePtr()
api_integration_test.go Updated integration test to use TruePtr()
README.md Updated documentation examples to use TruePtr()

💡 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.

CreateChatCompletion field stream=false is necessary

1 participant