-
Notifications
You must be signed in to change notification settings - Fork 4.6k
fix: ensure assistant messages with tool_calls include content field #7076
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
cd9d2dd
5270889
fba64c1
feacc37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
| } | ||
|
Comment on lines
+250
to
+257
|
||
|
|
||
| if converted.get("content").is_some() || converted.get("tool_calls").is_some() { | ||
| output.insert(0, converted); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just leave this line of this comment describing the reason for the code.