Skip to content

Commit b962f4a

Browse files
authored
fix(vllm): parse tool_call function arguments before applying the chat template (#10256)
Signed-off-by: pos-ei-don <1822533+pos-ei-don@users.noreply.github.com>
1 parent b6fcb3e commit b962f4a

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

backend/python/vllm/backend.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,24 @@ def _messages_to_dicts(self, messages):
150150
d["reasoning_content"] = msg.reasoning_content
151151
if msg.tool_calls:
152152
try:
153-
d["tool_calls"] = json.loads(msg.tool_calls)
153+
tool_calls = json.loads(msg.tool_calls)
154154
except json.JSONDecodeError:
155155
pass
156+
else:
157+
# OpenAI wire format carries function.arguments as a
158+
# JSON-encoded string, but chat templates (e.g. Qwen3)
159+
# iterate over it as a mapping. vLLM's own OpenAI server
160+
# parses arguments before applying the template, so do
161+
# the same here.
162+
if isinstance(tool_calls, list):
163+
for tc in tool_calls:
164+
func = tc.get("function") if isinstance(tc, dict) else None
165+
if isinstance(func, dict) and isinstance(func.get("arguments"), str):
166+
try:
167+
func["arguments"] = json.loads(func["arguments"])
168+
except json.JSONDecodeError:
169+
pass
170+
d["tool_calls"] = tool_calls
156171
result.append(d)
157172
return result
158173

0 commit comments

Comments
 (0)