[Tool Call] Steamline function arguments when tool_choice="auto" for deepseekv31_detector (#11589)

This commit is contained in:
Muqi Li
2025-11-13 23:06:02 -08:00
committed by GitHub
parent 04848ba7cb
commit fc5da1e80b
@@ -114,13 +114,14 @@ class DeepSeekV31Detector(BaseFormatDetector):
calls: list[ToolCallItem] = [] calls: list[ToolCallItem] = []
try: try:
partial_match = re.search( partial_match = re.search(
pattern=r"<|tool▁call▁begin|>(.*)<|tool▁sep|>(.*)<|tool▁call▁end|>", pattern=r"<|tool▁call▁begin|>(.*)<|tool▁sep|>(.*?)(<|tool▁call▁end|>|$)",
string=current_text, string=current_text,
flags=re.DOTALL, flags=re.DOTALL,
) )
if partial_match: if partial_match:
func_name = partial_match.group(1).strip() func_name = partial_match.group(1).strip()
func_args_raw = partial_match.group(2).strip() func_args_raw = partial_match.group(2).strip()
is_tool_end = partial_match.group(3)
# Initialize state if this is the first tool call # Initialize state if this is the first tool call
if self.current_tool_id == -1: if self.current_tool_id == -1:
@@ -179,15 +180,9 @@ class DeepSeekV31Detector(BaseFormatDetector):
pass pass
# Find the end of the current tool call and remove only that part from buffer # Find the end of the current tool call and remove only that part from buffer
tool_call_end_pattern = ( if is_tool_end:
r"<|tool▁call▁begin|>.*?<|tool▁call▁end|>"
)
match = re.search(
tool_call_end_pattern, current_text, re.DOTALL
)
if match:
# Remove the completed tool call from buffer, keep any remaining content # Remove the completed tool call from buffer, keep any remaining content
self._buffer = current_text[match.end() :] self._buffer = current_text[partial_match.end(3) :]
else: else:
self._buffer = "" self._buffer = ""