Skip to content

Commit

Permalink
[Bugfix] Fixed Mistral tool streaming with non-ascii characters
Browse files Browse the repository at this point in the history
Signed-off-by: cedonley <[email protected]>
  • Loading branch information
cedonley committed Nov 29, 2024
1 parent f630a0c commit 23c4405
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions vllm/entrypoints/openai/tool_parsers/mistral_tool_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ def extract_tool_calls(
function=FunctionCall(
name=raw_function_call["name"],
# function call args are JSON but as a string
arguments=json.dumps(raw_function_call["arguments"])))
arguments=json.dumps(raw_function_call["arguments"],
ensure_ascii=False)))
for raw_function_call in function_call_arr
]

Expand Down Expand Up @@ -199,7 +200,7 @@ def extract_tool_calls_streaming(
diff: Union[str, None] = current_tool_call.get("arguments")

if diff:
diff = json.dumps(diff).replace(
diff = json.dumps(diff, ensure_ascii=False).replace(
self.streamed_args_for_tool[self.current_tool_id],
"")
delta = DeltaMessage(tool_calls=[
Expand Down Expand Up @@ -260,7 +261,8 @@ def extract_tool_calls_streaming(
"mid-arguments")
delta = None
elif cur_arguments and not prev_arguments:
cur_arguments_json = json.dumps(cur_arguments)[:-2]
cur_arguments_json = json.dumps(cur_arguments,
ensure_ascii=False)[:-2]
logger.debug("finding %s in %s", new_text,
cur_arguments_json)

Expand All @@ -279,8 +281,10 @@ def extract_tool_calls_streaming(
self.current_tool_id] += arguments_delta

elif cur_arguments and prev_arguments:
cur_args_json = json.dumps(cur_arguments)
prev_args_json = json.dumps(prev_arguments)
cur_args_json = json.dumps(cur_arguments,
ensure_ascii=False)
prev_args_json = json.dumps(prev_arguments,
ensure_ascii=False)
logger.debug("Searching for diff between \n%s\n%s",
cur_args_json, prev_args_json)

Expand Down

0 comments on commit 23c4405

Please sign in to comment.