Skip to content

Commit 4d63b38

Browse files
committed
Ensuring function name is sent in a single chunk
Signed-off-by: avigny <[email protected]>
1 parent fa990df commit 4d63b38

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

tests/tool_use/test_mistral_tool_parser.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ def _test_extract_tool_calls_streaming(tool_parser, tokenizer, model_output,
306306
if tool_call.index != tool_call_idx:
307307
tool_call_idx = tool_call.index
308308
function_args_strs.append("")
309-
function_names.append("")
310309
tool_call_ids.append(None)
311310

312311
# if a tool call ID is streamed, make sure one hasn't been already
@@ -319,7 +318,7 @@ def _test_extract_tool_calls_streaming(tool_parser, tokenizer, model_output,
319318
# IN ENTIRETY, exactly one time.
320319
if tool_call.function.name:
321320
assert isinstance(tool_call.function.name, str)
322-
function_names[tool_call.index] += tool_call.function.name
321+
function_names.append(tool_call.function.name)
323322

324323
if tool_call.function.arguments:
325324
# make sure they're a string and then add them to the list

vllm/entrypoints/openai/tool_parsers/mistral_tool_parser.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -261,24 +261,27 @@ def _generate_delta_tool_call(self,
261261
self.streaming_state = StreamingState.PARSING_NAME
262262
delta_text = delta_text.replace(self.bot_token, "", 1)
263263
if self.streaming_state == StreamingState.PARSING_NAME:
264+
if self.current_tool_name is None:
265+
self.current_tool_name = ""
264266
# The name stops where the arguments start
265267
# And the arguments start with the `{` char
266268
if "{" in delta_text:
267269
delta_function_name = delta_text.split("{")[0]
270+
self.current_tool_name += delta_function_name
268271
delta_text = delta_text[len(delta_function_name):]
269272
self.streaming_state = StreamingState.PARSING_ARGUMENTS
270273
else:
271-
delta_function_name = delta_text
272-
return [
273-
DeltaToolCall(
274+
# we want to send the tool name once it's complete
275+
self.current_tool_name += delta_text
276+
if tool_id is not None:
277+
return [
278+
DeltaToolCall(
274279
index=self.current_tool_id,
275280
type="function",
276-
id=tool_id,
277-
function=DeltaFunctionCall(
278-
name=delta_function_name).model_dump(
279-
exclude_none=True),
280-
)
281-
]
281+
id=tool_id
282+
)]
283+
else:
284+
return []
282285
if self.streaming_state == StreamingState.PARSING_ARGUMENTS:
283286
next_function_text = None
284287
if self.bot_token in delta_text:
@@ -297,11 +300,12 @@ def _generate_delta_tool_call(self,
297300
type="function",
298301
id=tool_id,
299302
function=DeltaFunctionCall(
300-
name=delta_function_name,
303+
name=self.current_tool_name,
301304
arguments=delta_arguments).model_dump(
302305
exclude_none=True),
303306
)
304307
]
308+
self.current_tool_name = None
305309
if next_function_text:
306310
ret += self._generate_delta_tool_call(next_function_text)
307311
return ret

0 commit comments

Comments
 (0)