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