Don't serialise empty content on ChatCompletionMessage #841
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Describe the change
Updates the JSON serialisation for
ChatCompletionMessage
structs to omit emptyContent
. 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 OpenAITests
Added an integration test. If my change is removed OpenAI returns a 500.
Additional context
I'll also report the 500s to OpenAI.