[Bugfix] Fix Hermes tool parser when stream interval > 1 (#38168)

Signed-off-by: sfeng33 <4florafeng@gmail.com>
This commit is contained in:
Flora Feng
2026-03-27 14:42:26 +08:00
committed by GitHub
parent 0ae89f18fd
commit aee4c14689
3 changed files with 348 additions and 381 deletions
+2 -18
View File
@@ -16,23 +16,7 @@ class LongcatFlashToolParser(Hermes2ProToolParser):
self.tool_call_end_token: str = "</longcat_tool_call>"
self.tool_call_regex = re.compile(
r"<longcat_tool_call>(.*?)</longcat_tool_call>|<longcat_tool_call>(.*)",
r"<longcat_tool_call>(.*?)</longcat_tool_call>"
r"|<longcat_tool_call>(.*)",
re.DOTALL,
)
self.tool_call_start_token_ids = self.model_tokenizer.encode(
self.tool_call_start_token, add_special_tokens=False
)
self.tool_call_end_token_ids = self.model_tokenizer.encode(
self.tool_call_end_token, add_special_tokens=False
)
self.tool_call_start_token_array = [
self.model_tokenizer.decode([token_id])
for token_id in self.tool_call_start_token_ids
]
self.tool_call_end_token_array = [
self.model_tokenizer.decode([token_id])
for token_id in self.tool_call_end_token_ids
]