fix: kimi_k2 return empty tool call list (#22149)

Signed-off-by: tlipoca9 <tlipoca9@gmail.com>
This commit is contained in:
tlipoca9 2025-08-05 10:15:31 +08:00 committed by GitHub
parent d7b28f3415
commit 8a6e108e76
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -38,15 +38,15 @@ class KimiK2ToolParser(ToolParser):
self.tool_call_end_token: str = "<|tool_call_end|>"
self.tool_call_regex = re.compile(
r"<\|tool_call_begin\|>\s*(?P<tool_call_id>[\w\.]+:\d+)\s*<\|tool_call_argument_begin\|>\s*(?P<function_arguments>.*?)\s*<\|tool_call_end\|>"
r"<\|tool_call_begin\|>\s*(?P<tool_call_id>.+:\d+)\s*<\|tool_call_argument_begin\|>\s*(?P<function_arguments>.*?)\s*<\|tool_call_end\|>"
)
self.stream_tool_call_portion_regex = re.compile(
r"(?P<tool_call_id>[\w\.]+:\d+)\s*<\|tool_call_argument_begin\|>\s*(?P<function_arguments>.*)"
r"(?P<tool_call_id>.+:\d+)\s*<\|tool_call_argument_begin\|>\s*(?P<function_arguments>.*)"
)
self.stream_tool_call_name_regex = re.compile(
r"(?P<tool_call_id>[\w\.]+:\d+)\s*")
r"(?P<tool_call_id>.+:\d+)\s*")
if not self.model_tokenizer:
raise ValueError(
@ -374,4 +374,4 @@ class KimiK2ToolParser(ToolParser):
except Exception:
logger.exception("Error trying to handle streaming tool call.")
return None # do not stream a delta. skip this token ID.
return None # do not stream a delta. skip this token ID.