Skip to content

Commit

Permalink
[Bugfix] Fixed additional Hermes tool parser edge cases
Browse files Browse the repository at this point in the history
Signed-off-by: cedonley <[email protected]>
  • Loading branch information
cedonley committed Nov 30, 2024
1 parent 23c4405 commit 0b99d2d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions vllm/entrypoints/openai/tool_parsers/hermes_tool_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
]

Expand Down Expand Up @@ -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 == None):

Check failure on line 230 in vllm/entrypoints/openai/tool_parsers/hermes_tool_parser.py

View workflow job for this annotation

GitHub Actions / ruff (3.12)

Ruff (E711)

vllm/entrypoints/openai/tool_parsers/hermes_tool_parser.py:230:42: E711 Comparison to `None` should be `cond is None`
return None
function_name: Union[str, None] = current_tool_call.get("name")
if function_name:
self.current_tool_name_sent = True
Expand Down Expand Up @@ -285,13 +288,16 @@ 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) \
args_delta_start_loc = cur_arguments_json.rindex(delta_text[:-2]) \

Check failure on line 297 in vllm/entrypoints/openai/tool_parsers/hermes_tool_parser.py

View workflow job for this annotation

GitHub Actions / ruff (3.12)

Ruff (E501)

vllm/entrypoints/openai/tool_parsers/hermes_tool_parser.py:297:81: E501 Line too long (83 > 80)
+ 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]
Expand Down

0 comments on commit 0b99d2d

Please sign in to comment.