Add explicit content=None to assistant tool-call messages in Chat Completions converter #2238
+6
−0
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.
Resolved: #2237
This PR ensures that assistant messages with tool calls include an explicit
contentkey with the valueNonewhen using the Chat Completions API.Background
When using the Chat Completions API, assistant messages that contain tool calls are currently sent back to the server without a
contentkey.Current behavior:
{ "role": "assistant", "tool_calls": [...] }Expected behavior:
{ "role": "assistant", "content": null, "tool_calls": [...] }Why keep the
contentkey even when it isNone?In the Chat Completions API, assistant messages that trigger function or tool calls include
"content": null.(i.e., the returned message did contain the
contentfield, even when it is null).When sending messages back to the server, this structure should stay the same.
This is also shown in official examples. For example, in the OpenAI Cookbook:
https://github.com/openai/openai-cookbook/blob/bceb1173eb4b8ffb620279dd36c1e2942860f89a/examples/How_to_call_functions_with_chat_models.ipynb
This sends the full assistant message, including
"content": None, back to the Chat Completions API.Currently, the SDK drops the
contentkey during the conversion from Responses API items to Chat Completions messages.This PR adds it back.
If an assistant message has a non-None content value, this change does not overwrite or modify it. The content key is only added when it is missing.
Impact