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

Don't serialise empty content on ChatCompletionMessage #841

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

greysteil
Copy link
Contributor

Describe the change

Updates the JSON serialisation for ChatCompletionMessage structs to omit empty Content. This avoids a bug in the OpenAI API where sending a message that has both a tool call and empty content returns a 500.

Provide OpenAI documentation link

https://platform.openai.com/docs/api-reference/chat/object#chat/object-choices

Describe your solution

Since the content field can be a string or null, representing it as a string is technically wrong. Changing that would be a breaking change, but we can at least ensure that empty strings (which are unlikely to ever serve any purpose) aren't sent to OpenAI

Tests

Added an integration test. If my change is removed OpenAI returns a 500.

Additional context

I'll also report the 500s to OpenAI.

@greysteil greysteil force-pushed the dont-serialize-content-on-function-call-messages branch from 1cdc6e1 to 3058f9e Compare September 1, 2024 23:56
Copy link

codecov bot commented Sep 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.02%. Comparing base (774fc9d) to head (4381429).
Report is 46 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #841      +/-   ##
==========================================
+ Coverage   98.46%   99.02%   +0.55%     
==========================================
  Files          24       26       +2     
  Lines        1364     1429      +65     
==========================================
+ Hits         1343     1415      +72     
+ Misses         15        8       -7     
  Partials        6        6              

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

@greysteil greysteil force-pushed the dont-serialize-content-on-function-call-messages branch from 39fa8a2 to 4381429 Compare September 2, 2024 00:15
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.

1 participant