Skip to content

Commit 16b5299

Browse files
schoennenbeckabadea-ionos
authored andcommitted
[Bugfix] Consistent ascii handling in tool parsers (#17704)
Signed-off-by: Sebastian Schönnenbeck <sebastian.schoennenbeck@comma-soft.com> Signed-off-by: Alexandru Badea <george-alexandru.badea@ionos.com>
1 parent 3015d56 commit 16b5299

File tree

7 files changed

+53
-29
lines changed

7 files changed

+53
-29
lines changed

vllm/entrypoints/openai/tool_parsers/granite_20b_fc_tool_parser.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ def extract_tool_calls(
8080
function=FunctionCall(
8181
name=function_call["name"],
8282
# function call args are JSON but as a string
83-
arguments=json.dumps(function_call["arguments"]),
83+
arguments=json.dumps(function_call["arguments"],
84+
ensure_ascii=False),
8485
),
8586
) for function_call in raw_function_calls
8687
]
@@ -166,7 +167,8 @@ def extract_tool_calls_streaming(
166167
if self.current_tool_id >= 0:
167168
cur_arguments = current_tool_call.get("arguments")
168169
if cur_arguments:
169-
cur_args_json = json.dumps(cur_arguments)
170+
cur_args_json = json.dumps(cur_arguments,
171+
ensure_ascii=False)
170172
sent = len(
171173
self.streamed_args_for_tool[self.current_tool_id])
172174
argument_diff = cur_args_json[sent:]
@@ -218,15 +220,17 @@ def extract_tool_calls_streaming(
218220
if cur_arguments:
219221
sent = len(
220222
self.streamed_args_for_tool[self.current_tool_id])
221-
cur_args_json = json.dumps(cur_arguments)
223+
cur_args_json = json.dumps(cur_arguments,
224+
ensure_ascii=False)
222225
prev_arguments = self.prev_tool_call_arr[
223226
self.current_tool_id].get("arguments")
224227

225228
argument_diff = None
226229
if is_complete[self.current_tool_id]:
227230
argument_diff = cur_args_json[sent:]
228231
elif prev_arguments:
229-
prev_args_json = json.dumps(prev_arguments)
232+
prev_args_json = json.dumps(prev_arguments,
233+
ensure_ascii=False)
230234
if cur_args_json != prev_args_json:
231235

232236
prefix = find_common_prefix(

vllm/entrypoints/openai/tool_parsers/granite_tool_parser.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ def extract_tool_calls(
6767
function=FunctionCall(
6868
name=function_call["name"],
6969
# function call args are JSON but as a string
70-
arguments=json.dumps(function_call["arguments"]),
70+
arguments=json.dumps(function_call["arguments"],
71+
ensure_ascii=False),
7172
),
7273
) for function_call in raw_function_calls
7374
]
@@ -151,7 +152,8 @@ def extract_tool_calls_streaming(
151152
if self.current_tool_id >= 0:
152153
cur_arguments = current_tool_call.get("arguments")
153154
if cur_arguments:
154-
cur_args_json = json.dumps(cur_arguments)
155+
cur_args_json = json.dumps(cur_arguments,
156+
ensure_ascii=False)
155157
sent = len(
156158
self.streamed_args_for_tool[self.current_tool_id])
157159
argument_diff = cur_args_json[sent:]
@@ -197,15 +199,17 @@ def extract_tool_calls_streaming(
197199
if cur_arguments:
198200
sent = len(
199201
self.streamed_args_for_tool[self.current_tool_id])
200-
cur_args_json = json.dumps(cur_arguments)
202+
cur_args_json = json.dumps(cur_arguments,
203+
ensure_ascii=False)
201204
prev_arguments = self.prev_tool_call_arr[
202205
self.current_tool_id].get("arguments")
203206

204207
argument_diff = None
205208
if is_complete[self.current_tool_id]:
206209
argument_diff = cur_args_json[sent:]
207210
elif prev_arguments:
208-
prev_args_json = json.dumps(prev_arguments)
211+
prev_args_json = json.dumps(prev_arguments,
212+
ensure_ascii=False)
209213
if cur_args_json != prev_args_json:
210214
prefix = find_common_prefix(
211215
prev_args_json, cur_args_json)

vllm/entrypoints/openai/tool_parsers/internlm2_tool_parser.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ def extract_tool_calls_streaming(
133133
delta = None
134134
# first time to get parameters
135135
elif cur_arguments and not prev_arguments:
136-
cur_arguments_json = json.dumps(cur_arguments)
136+
cur_arguments_json = json.dumps(cur_arguments,
137+
ensure_ascii=False)
137138

138139
arguments_delta = cur_arguments_json[:cur_arguments_json.
139140
index(delta_text) +
@@ -148,8 +149,10 @@ def extract_tool_calls_streaming(
148149
self.current_tool_id] += arguments_delta
149150
# both prev and cur parameters, send the increase parameters
150151
elif cur_arguments and prev_arguments:
151-
cur_args_json = json.dumps(cur_arguments)
152-
prev_args_json = json.dumps(prev_arguments)
152+
cur_args_json = json.dumps(cur_arguments,
153+
ensure_ascii=False)
154+
prev_args_json = json.dumps(prev_arguments,
155+
ensure_ascii=False)
153156

154157
argument_diff = extract_intermediate_diff(
155158
cur_args_json, prev_args_json)
@@ -190,7 +193,8 @@ def extract_tool_calls(
190193
action_dict = json.loads(action)
191194
name, parameters = action_dict['name'], json.dumps(
192195
action_dict.get('parameters', action_dict.get('arguments',
193-
{})))
196+
{})),
197+
ensure_ascii=False)
194198

195199
if not tools or name not in [t.function.name for t in tools]:
196200
ExtractedToolCallInformation(tools_called=False,

vllm/entrypoints/openai/tool_parsers/jamba_tool_parser.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ def extract_tool_calls(
9696
function=FunctionCall(
9797
name=function_call["name"],
9898
# function call args are JSON but as a string
99-
arguments=json.dumps(function_call["arguments"])))
100-
for function_call in raw_function_calls
99+
arguments=json.dumps(function_call["arguments"],
100+
ensure_ascii=False),
101+
)) for function_call in raw_function_calls
101102
]
102103

103104
content = model_output[:model_output.
@@ -187,7 +188,7 @@ def extract_tool_calls_streaming(
187188
diff: Union[str, None] = current_tool_call.get("arguments")
188189

189190
if diff:
190-
diff = json.dumps(diff).replace(
191+
diff = json.dumps(diff, ensure_ascii=False).replace(
191192
self.streamed_args_for_tool[self.current_tool_id],
192193
"")
193194
delta = DeltaMessage(tool_calls=[
@@ -248,7 +249,8 @@ def extract_tool_calls_streaming(
248249
"mid-arguments")
249250
delta = None
250251
elif cur_arguments and not prev_arguments:
251-
cur_arguments_json = json.dumps(cur_arguments)
252+
cur_arguments_json = json.dumps(cur_arguments,
253+
ensure_ascii=False)
252254
logger.debug("finding %s in %s", new_text,
253255
cur_arguments_json)
254256

@@ -267,8 +269,10 @@ def extract_tool_calls_streaming(
267269
self.current_tool_id] += arguments_delta
268270

269271
elif cur_arguments and prev_arguments:
270-
cur_args_json = json.dumps(cur_arguments)
271-
prev_args_json = json.dumps(prev_arguments)
272+
cur_args_json = json.dumps(cur_arguments,
273+
ensure_ascii=False)
274+
prev_args_json = json.dumps(prev_arguments,
275+
ensure_ascii=False)
272276
logger.debug("Searching for diff between \n%s\n%s",
273277
cur_args_json, prev_args_json)
274278

vllm/entrypoints/openai/tool_parsers/llama_tool_parser.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ def extract_tool_calls(
8888
# function call args are JSON but as a string
8989
arguments=json.dumps(raw_function_call["arguments"] \
9090
if "arguments" in raw_function_call \
91-
else raw_function_call["parameters"])))
91+
else raw_function_call["parameters"],
92+
ensure_ascii=False)))
9293
for raw_function_call in function_call_arr
9394
]
9495

@@ -174,7 +175,8 @@ def extract_tool_calls_streaming(
174175
if self.current_tool_id >= 0:
175176
cur_arguments = current_tool_call.get("arguments")
176177
if cur_arguments:
177-
cur_args_json = json.dumps(cur_arguments)
178+
cur_args_json = json.dumps(cur_arguments,
179+
ensure_ascii=False)
178180
sent = len(
179181
self.streamed_args_for_tool[self.current_tool_id])
180182
argument_diff = cur_args_json[sent:]
@@ -226,15 +228,17 @@ def extract_tool_calls_streaming(
226228
if cur_arguments:
227229
sent = len(
228230
self.streamed_args_for_tool[self.current_tool_id])
229-
cur_args_json = json.dumps(cur_arguments)
231+
cur_args_json = json.dumps(cur_arguments,
232+
ensure_ascii=False)
230233
prev_arguments = self.prev_tool_call_arr[
231234
self.current_tool_id].get("arguments")
232235

233236
argument_diff = None
234237
if is_complete[self.current_tool_id]:
235238
argument_diff = cur_args_json[sent:]
236239
elif prev_arguments:
237-
prev_args_json = json.dumps(prev_arguments)
240+
prev_args_json = json.dumps(prev_arguments,
241+
ensure_ascii=False)
238242
if cur_args_json != prev_args_json:
239243

240244
prefix = find_common_prefix(

vllm/entrypoints/openai/tool_parsers/phi4mini_tool_parser.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ def extract_tool_calls(
7979
name=raw_function_call["name"],
8080
# function call args are JSON but as a string
8181
arguments=json.dumps(
82-
raw_function_call["arguments"] if "arguments" in
83-
raw_function_call else
84-
raw_function_call["parameters"])))
85-
for raw_function_call in function_call_arr
82+
raw_function_call["arguments"]
83+
if "arguments" in raw_function_call else
84+
raw_function_call["parameters"],
85+
ensure_ascii=False),
86+
)) for raw_function_call in function_call_arr
8687
]
8788

8889
# get any content before the tool call

vllm/entrypoints/openai/tool_parsers/pythonic_tool_parser.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,12 @@ def _handle_single_tool(call: ast.Call) -> ToolCall:
200200
arguments = {}
201201
for keyword in call.keywords:
202202
arguments[keyword.arg] = _get_parameter_value(keyword.value)
203-
return ToolCall(type="function",
204-
function=FunctionCall(name=function_name,
205-
arguments=json.dumps(arguments)))
203+
return ToolCall(
204+
type="function",
205+
function=FunctionCall(name=function_name,
206+
arguments=json.dumps(arguments,
207+
ensure_ascii=False)),
208+
)
206209

207210

208211
def _make_valid_python(text: str) -> Union[tuple[str, str], None]:

0 commit comments

Comments
 (0)