From 852017c1df2007d3bdf331b977b4e5e121a25892 Mon Sep 17 00:00:00 2001 From: cedonley Date: Sat, 30 Nov 2024 01:48:43 +0000 Subject: [PATCH] [Bugfix] Fixed additional Hermes tool parser edge cases Signed-off-by: cedonley --- .../openai/tool_parsers/hermes_tool_parser.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/vllm/entrypoints/openai/tool_parsers/hermes_tool_parser.py b/vllm/entrypoints/openai/tool_parsers/hermes_tool_parser.py index aaf9d7ddb51c0..16ca5e779c300 100644 --- a/vllm/entrypoints/openai/tool_parsers/hermes_tool_parser.py +++ b/vllm/entrypoints/openai/tool_parsers/hermes_tool_parser.py @@ -91,7 +91,8 @@ def extract_tool_calls( function=FunctionCall( name=function_call["name"], # function call args are JSON but as a string - arguments=json.dumps(function_call["arguments"]))) + arguments=json.dumps(function_call["arguments"], + ensure_ascii=False))) for function_call in raw_function_calls ] @@ -226,6 +227,8 @@ def extract_tool_calls_streaming( # case - we haven't sent the tool name yet. If it's available, send # it. otherwise, wait until it's available. if not self.current_tool_name_sent: + if (current_tool_call is None): + return None function_name: Union[str, None] = current_tool_call.get("name") if function_name: self.current_tool_name_sent = True @@ -285,13 +288,17 @@ def extract_tool_calls_streaming( # autocompleting the JSON elif cur_arguments and not prev_arguments: - cur_arguments_json = json.dumps(cur_arguments) + cur_arguments_json = json.dumps(cur_arguments, + ensure_ascii=False) logger.debug("finding %s in %s", delta_text, cur_arguments_json) # get the location where previous args differ from current - args_delta_start_loc = cur_arguments_json.index(delta_text) \ - + len(delta_text) + args_delta_start_loc = cur_arguments_json. \ + rindex(delta_text[:-2]) + \ + len(delta_text) + if (args_delta_start_loc > len(cur_arguments_json) - 2): + args_delta_start_loc = len(cur_arguments_json) - 2 # use that to find the actual delta arguments_delta = cur_arguments_json[:args_delta_start_loc]