[Bugfix] fix tool_parser error handling when serve a model not support it (#8709)

This commit is contained in:
Yanyi Liu
2024-10-06 12:51:08 +00:00
committed by GitHub
parent b22b798471
commit fdf59d30ea
3 changed files with 31 additions and 10 deletions
@@ -61,8 +61,13 @@ class MistralToolParser(ToolParser):
self.streamed_args_for_tool: List[str] = [
] # map what has been streamed for each tool so far to a list
self.bot_token = "[TOOL_CALLS]"
self.bot_token_id = self.model_tokenizer.get_vocab()[self.bot_token]
self.bot_token_id = self.model_tokenizer.get_vocab().get(
self.bot_token, None)
self.tool_call_regex = re.compile(r"\[{.*?}\]", re.DOTALL)
if not self.bot_token_id:
raise RuntimeError(
"Mistral Tool Parser could not locate the tool call token in "
"the tokenizer!")
def extract_tool_calls(
self,