Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix] Hermes tool parser fails to check for & handle None values in some cases #9908

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions vllm/entrypoints/openai/tool_parsers/hermes_tool_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ def extract_tool_calls_streaming(

try:

# try to load the tool call if it's present
current_tool_call = partial_json_parser.loads(
tool_call_portion or "{}",
flags) if tool_call_portion else None
Expand All @@ -221,6 +222,11 @@ def extract_tool_calls_streaming(
logger.debug('not enough tokens to parse into JSON yet')
return None

if not current_tool_call:
logger.debug(
'current_tool_call is none. waiting for more tokens')
return None

# 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:
Expand Down Expand Up @@ -260,8 +266,14 @@ def extract_tool_calls_streaming(

# main logic for tool parsing here - compare prev. partially-parsed
# JSON to the current partially-parsed JSON
prev_arguments = (
self.prev_tool_call_arr[self.current_tool_id].get("arguments"))
prev_call_state = self.prev_tool_call_arr[self.current_tool_id]

# get the previous and current versions of the arguments for the
# call if they exist.
if prev_call_state:
prev_arguments = prev_call_state.get('arguments')
else:
prev_arguments = None
cur_arguments = current_tool_call.get("arguments")

logger.debug("diffing old arguments: %s", prev_arguments)
Expand Down