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:
fl-sean03
2026-02-11 07:15:23 -07:00
committed by GitHub
parent 7be6fc93e8
commit 0e7294835c
@@ -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);
}