[Bugfix] Fix InternLM2 tool parser dropping characters from streamed arguments (#60709)
Signed-off-by: Vadim Gimpelson <vadim.gimpelson@gmail.com> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Flora Feng <4florafeng@gmail.com>
This commit is contained in:
co-authored by
Claude
Flora Feng
parent
112a282915
commit
9824159d94
@@ -26,7 +26,7 @@ from vllm.tool_parsers.abstract_tool_parser import (
|
||||
Tool,
|
||||
ToolParser,
|
||||
)
|
||||
from vllm.tool_parsers.utils import extract_intermediate_diff, is_complete_json
|
||||
from vllm.tool_parsers.utils import find_common_prefix, is_complete_json
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
@@ -172,10 +172,17 @@ class Internlm2ToolParser(ToolParser):
|
||||
elif cur_arguments and prev_arguments:
|
||||
cur_args_json = json.dumps(cur_arguments, ensure_ascii=False)
|
||||
prev_args_json = json.dumps(prev_arguments, ensure_ascii=False)
|
||||
sent = len(self.streamed_args_for_tool[self.current_tool_id])
|
||||
|
||||
argument_diff = extract_intermediate_diff(
|
||||
cur_args_json, prev_args_json
|
||||
)
|
||||
# Partial JSON is serialized with synthetic closers, so
|
||||
# only the part shared with the previous parse is final.
|
||||
if is_complete_json(parsable_arr):
|
||||
argument_diff = cur_args_json[sent:]
|
||||
elif cur_args_json != prev_args_json:
|
||||
prefix = find_common_prefix(prev_args_json, cur_args_json)
|
||||
argument_diff = prefix[sent:]
|
||||
else:
|
||||
argument_diff = ""
|
||||
|
||||
delta = DeltaMessage(
|
||||
tool_calls=[
|
||||
|
||||
Reference in New Issue
Block a user