Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make "Content" field in "ChatCompletionMessage" omitempty #926

Merged

Conversation

saileshd1402
Copy link
Contributor

@saileshd1402 saileshd1402 commented Jan 24, 2025

Describe the change
According to the OpenAI API spec, the content field of ChatCompletionMessage should be nullable. Right now when we try to marshal the struct with empty string, we get "content": "", but ideally, the content key should exist if that field is empty

Provide OpenAI documentation link
https://platform.openai.com/docs/api-reference/chat/object
Under: choices -> message -> content
image

Describe your solution
We can fix this my adding an omitempty json tag to the "content" field in the "ChatCompletionMessage" struct

Tests
Tested this by sending a completion request with empty content field to a Nvidia NIM Inference Server

@saileshd1402 saileshd1402 changed the title Make "Content" field in "ChatCompletionMessage" nullable Make "Content" field in "ChatCompletionMessage" omitempty Jan 24, 2025
Copy link

codecov bot commented Jan 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.69%. Comparing base (774fc9d) to head (7f7d2c5).
Report is 81 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #926      +/-   ##
==========================================
+ Coverage   98.46%   98.69%   +0.23%     
==========================================
  Files          24       26       +2     
  Lines        1364     1761     +397     
==========================================
+ Hits         1343     1738     +395     
- Misses         15       16       +1     
- Partials        6        7       +1     

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

@saileshd1402 saileshd1402 marked this pull request as ready for review January 24, 2025 14:49
Copy link

@Datta0 Datta0 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Owner

@sashabaranov sashabaranov left a comment

Choose a reason for hiding this comment

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

Thank you!

@sashabaranov sashabaranov merged commit 45aa996 into sashabaranov:master Jan 31, 2025
3 checks passed
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.

3 participants