fix: ensure assistant messages with tool_calls include content field (#7076)
Signed-off-by: fl-sean03 <sean@opspawn.com> Co-authored-by: fl-sean03 <sean@opspawn.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: OpSpawn <opspawn@users.noreply.github.com>
This commit is contained in:
@@ -247,6 +247,15 @@ pub fn format_messages(messages: &[Message], image_format: &ImageFormat) -> Vec<
|
||||
converted["content"] = json!(text_array.join("\n"));
|
||||
}
|
||||
|
||||
// Some strict OpenAI-compatible providers require "content" to be present
|
||||
// (even as null) when tool_calls are provided. See #6717.
|
||||
if message.role == Role::Assistant
|
||||
&& converted.get("tool_calls").is_some()
|
||||
&& converted.get("content").is_none()
|
||||
{
|
||||
converted["content"] = json!(null);
|
||||
}
|
||||
|
||||
if converted.get("content").is_some() || converted.get("tool_calls").is_some() {
|
||||
output.insert(0, converted);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user