Skip to content

Commit

Permalink
fix: hermes tool parser None checks & formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Mistele committed Nov 1, 2024
1 parent 93a76dd commit ab05e8c
Showing 1 changed file with 14 additions and 2 deletions.
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

0 comments on commit ab05e8c

Please sign in to comment.