[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:
Vadim Gimpelson
2026-10-08 21:20:49 -07:00
committed by GitHub
co-authored by Claude Flora Feng
parent 112a282915
commit 9824159d94
2 changed files with 39 additions and 4 deletions
@@ -10,6 +10,7 @@ from tests.tool_parsers.common_tests import (
ToolParserTestConfig,
ToolParserTests,
)
from tests.tool_parsers.utils import run_tool_extraction_streaming
from vllm.tokenizers import TokenizerLike
from vllm.tool_parsers.internlm2_tool_parser import Internlm2ToolParser
@@ -162,3 +163,30 @@ def test_streaming_arguments_in_single_delta(default_tokenizer: TokenizerLike) -
streamed += arguments
assert json.loads(streamed) == {"city": "Dallas", "state": "TX"}
@pytest.mark.parametrize(
"arguments_deltas",
[
['{"location": "Beijing', '", "days": 3}}<|action_end|>'],
[*'{"location": "Beijing", "days": 3}}', "<|action_end|>"],
],
ids=["split_inside_string", "char_by_char"],
)
def test_streaming_arguments_match_final_arguments(
default_tokenizer: TokenizerLike, arguments_deltas: list[str]
) -> None:
"""Streamed argument deltas must add up to the final arguments, wherever
the chunk boundaries fall."""
parser = Internlm2ToolParser(default_tokenizer)
deltas = [
'<|action_start|><|plugin|>{"name": "get_weather", "parameters": ',
*arguments_deltas,
]
reconstructor = run_tool_extraction_streaming(parser, deltas)
assert len(reconstructor.tool_calls) == 1
streamed = reconstructor.tool_calls[0].function.arguments
streamed += parser.get_remaining_unstreamed_args()
assert streamed == '{"location": "Beijing", "days": 3}'