[Bugfix] Fix step3p5 parser when using mtp (#33690)
Signed-off-by: mariohong <mariohong128@gmail.com>
This commit is contained in:
1435
tests/tool_parsers/test_step3p5_tool_parser.py
Normal file
1435
tests/tool_parsers/test_step3p5_tool_parser.py
Normal file
File diff suppressed because it is too large
Load Diff
@@ -97,11 +97,26 @@ class StreamingXMLToolCallParser:
|
||||
"""
|
||||
# Record delta count before processing
|
||||
initial_delta_count = len(self.deltas)
|
||||
entry_call_id = self.current_call_id
|
||||
entry_tool_call_index = self.tool_call_index
|
||||
|
||||
self.streaming_buffer += xml_chunk
|
||||
|
||||
found_elements = self._process_complete_xml_elements()
|
||||
|
||||
fallback_call_id = None
|
||||
if entry_call_id is not None:
|
||||
if (
|
||||
self.current_call_id == entry_call_id
|
||||
and self.tool_call_index == entry_tool_call_index
|
||||
):
|
||||
fallback_call_id = entry_call_id
|
||||
elif (
|
||||
self.current_call_id is not None
|
||||
and self.tool_call_index == entry_tool_call_index + 1
|
||||
):
|
||||
fallback_call_id = self.current_call_id
|
||||
|
||||
if found_elements:
|
||||
# If complete elements found, check if end events were missed
|
||||
# some tags may not have been triggered
|
||||
@@ -110,7 +125,7 @@ class StreamingXMLToolCallParser:
|
||||
# If this chunk contains </function>
|
||||
# but didn't generate '}', then complete it
|
||||
if (
|
||||
self.current_call_id is not None
|
||||
fallback_call_id is not None
|
||||
and self.function_end_token in xml_chunk
|
||||
):
|
||||
# - Added '}' (non-empty parameter ending)
|
||||
@@ -121,7 +136,7 @@ class StreamingXMLToolCallParser:
|
||||
and any(
|
||||
(
|
||||
tc.function
|
||||
and tc.id == self.current_call_id
|
||||
and tc.id == fallback_call_id
|
||||
and isinstance(tc.function.arguments, str)
|
||||
and (tc.function.arguments in ("}", "{}"))
|
||||
)
|
||||
@@ -139,7 +154,7 @@ class StreamingXMLToolCallParser:
|
||||
# If this chunk contains </tool_call>
|
||||
# but didn't generate final empty delta, then complete it
|
||||
if (
|
||||
self.current_call_id is not None
|
||||
fallback_call_id is not None
|
||||
and self.tool_call_end_token in xml_chunk
|
||||
):
|
||||
has_toolcall_close = any(
|
||||
@@ -150,7 +165,7 @@ class StreamingXMLToolCallParser:
|
||||
tc.type == "function"
|
||||
and tc.function
|
||||
and tc.function.arguments == ""
|
||||
and tc.id == self.current_call_id
|
||||
and tc.id == fallback_call_id
|
||||
)
|
||||
for tc in td.tool_calls
|
||||
)
|
||||
@@ -186,7 +201,7 @@ class StreamingXMLToolCallParser:
|
||||
# Only execute when still on the same call as when entered,
|
||||
# to prevent accidentally closing new calls
|
||||
# in multi <tool_call> scenarios
|
||||
if self.current_call_id is not None and (
|
||||
if fallback_call_id is not None and (
|
||||
self.function_end_token in xml_chunk
|
||||
or self.tool_call_end_token in xml_chunk
|
||||
):
|
||||
|
||||
Reference in New Issue
Block a user