fix(models): emit explicit empty content for assistant tool-call turns (#3605)
Assistant history messages that carry tool_calls but empty text previously omitted the content field entirely on the wire. Strict local OpenAI-compatible engines (vLLM / Xinference serving Qwen-family Jinja chat templates) treat the missing field as undefined/null and crash while rendering the next turn, surfacing as "I'm sorry, I was unable to generate a response". Always serialize "content": "" for assistant tool-call turns. The empty string is accepted by every standard OpenAI-compatible endpoint. Fixes #1487 Co-authored-by: LuckVd <LuckVd@users.noreply.github.com>main
parent
a729d1fc8c
commit
ea7cf8d5d7
|
|
@ -364,7 +364,11 @@ func TestMessages_RolesToolsAndReasoningReplay(t *testing.T) {
|
|||
assistant := msgs[2].(map[string]any)
|
||||
assert.Equal(t, "thinking...", assistant["reasoning_content"])
|
||||
_, hasContent := assistant["content"]
|
||||
assert.False(t, hasContent, "empty content omitted next to tool_calls")
|
||||
// Issue #1487: assistant tool-call turns must carry an explicit
|
||||
// `"content": ""` — vLLM/Xinference Qwen-family Jinja templates crash on
|
||||
// a missing (undefined/null) content field when replaying history.
|
||||
assert.True(t, hasContent, "empty content must be emitted next to tool_calls")
|
||||
assert.Equal(t, "", assistant["content"], "emitted content must be empty string")
|
||||
tc := assistant["tool_calls"].([]any)[0].(map[string]any)
|
||||
assert.Equal(t, "call_1", tc["id"])
|
||||
assert.Equal(t, `{"q":"x"}`, tc["function"].(map[string]any)["arguments"])
|
||||
|
|
|
|||
|
|
@ -121,6 +121,17 @@ func (c *Client) convertMessages(messages []api.Message) []wireMessage {
|
|||
default:
|
||||
if msg.Content != "" || len(msg.ToolCalls) == 0 {
|
||||
wm.Content = msg.Content
|
||||
} else {
|
||||
// Assistant tool-call turn with empty content: emit an
|
||||
// explicit `"content": ""` instead of omitting the field.
|
||||
// Strict local engines (vLLM / Xinference serving Qwen-family
|
||||
// Jinja chat templates) treat a missing content field as
|
||||
// undefined/null and crash when rendering the assistant turn
|
||||
// for the next round. Issue #1487. The *string keeps
|
||||
// `omitempty` from dropping the field: a non-nil interface
|
||||
// holding a pointer serializes as "".
|
||||
empty := ""
|
||||
wm.Content = &empty
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue