Fix "Invalid value for 'content': expected a string, got null." openai error in case of empty assistant messages #17921
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.
Description
This is a fix for OpenAI errors such as:
They happen when there are messages in the chat history from the assistant that do not contain text, but are also not function or tool calls. E.g. in our application, that can happen if the user cancels a request and therefore there was no response received.
According to docs at https://platform.openai.com/docs/api-reference/chat/create, if neither
tool_calls
norfunction_call
is set, content must not be set to None.Please check if maybe additional checks are required additionally to the pure check for existance of
'function_call'
/'tool_calls'
keys inmessage.additional_kwargs
being performed right now - should we maybe also check that those are notNone
?Version Bump?
Did I bump the version in the
pyproject.toml
file of the package I am updating? (Except for thellama-index-core
package)Type of Change
Please delete options that are not relevant.
How Has This Been Tested?
Your pull-request will likely not be merged unless it is covered by some form of impactful unit testing.