File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments