Skip to content

Commit

Permalink
[Bugfix] Added additional failure checks and fixed mistral tool_id ge…
Browse files Browse the repository at this point in the history
…nerator to be consistent with non-streaming

Signed-off-by: cedonley <[email protected]>
  • Loading branch information
cedonley committed Dec 7, 2024
1 parent 7d47d24 commit a3b4117
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 8 additions & 0 deletions vllm/entrypoints/openai/tool_parsers/hermes_tool_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ def extract_tool_calls_streaming(
# case -- the current tool call is being closed.
elif (cur_tool_start_count == cur_tool_end_count
and cur_tool_end_count >= prev_tool_end_count):
if (self.prev_tool_call_arr is None
or len(self.prev_tool_call_arr) == 0):
logger.debug(
"attempting to close tool call, but no tool call")
return None
diff = self.prev_tool_call_arr[self.current_tool_id].get(
"arguments")
if diff:
Expand Down Expand Up @@ -236,6 +241,9 @@ def extract_tool_calls_streaming(
except partial_json_parser.core.exceptions.MalformedJSON:
logger.debug('not enough tokens to parse into JSON yet')
return None
except json.decoder.JSONDecodeError:
logger.debug("unable to parse JSON")
return None

# case - we haven't sent the tool name yet. If it's available, send
# it. otherwise, wait until it's available.
Expand Down
3 changes: 1 addition & 2 deletions vllm/entrypoints/openai/tool_parsers/mistral_tool_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
extract_intermediate_diff)
from vllm.logger import init_logger
from vllm.transformers_utils.tokenizer import AnyTokenizer, MistralTokenizer
from vllm.utils import random_uuid

logger = init_logger(__name__)

Expand Down Expand Up @@ -233,7 +232,7 @@ def extract_tool_calls_streaming(
delta = DeltaMessage(tool_calls=[
DeltaToolCall(index=self.current_tool_id,
type="function",
id=f"chatcmpl-tool-{random_uuid()}",
id="".join(choices(ALPHANUMERIC, k=9)),
function=DeltaFunctionCall(
name=function_name).model_dump(
exclude_none=True))
Expand Down

0 comments on commit a3b4117

Please sign in to comment.