fix: stream Qwen3 tool call string arguments (#46351)

Signed-off-by: Rui Yin <2260891073@qq.com>
Co-authored-by: abinggo <107740309+abinggo@users.noreply.github.com>
This commit is contained in:
Rui Yin
2026-06-23 10:26:37 +08:00
committed by GitHub
co-authored by abinggo
parent 33f50773cb
commit 8db12169a4
4 changed files with 177 additions and 9 deletions
+40 -1
View File
@@ -1339,6 +1339,42 @@ class TestArgDeltaWithConverter:
assert parsed == {"count": 5, "name": "test"}
assert isinstance(parsed["count"], int)
def test_streamable_string_keys_cached_after_name_delta(self, monkeypatch):
tool = _make_tool(
"f",
{
"name": {"type": "string"},
"count": {"type": "integer"},
},
)
engine = _make_engine(_converter_config(), tools=[tool])
original = ParserEngine._streamable_string_keys
calls: list[dict] = []
def wrapped(properties: dict) -> set[str] | None:
calls.append(properties)
return original(properties)
monkeypatch.setattr(
ParserEngine,
"_streamable_string_keys",
staticmethod(wrapped),
)
_run_streaming_tool(
engine,
"f",
["name=alice ", "count=4", "2"],
)
assert calls == [
{
"name": {"type": "string"},
"count": {"type": "integer"},
}
]
# ── TestSafeArgPrefix ────────────────────────────────────────────
@@ -1351,7 +1387,7 @@ class TestSafeArgPrefix:
[
('{"a": 1}', '{"a": '),
('{"a": 1, "b": 2}', '{"a": 1, "b": '),
('{"a": "hello", "b": "world"}', '{"a": "hello", "b": '),
('{"a": "hello", "b": "world"}', '{"a": "hello", "b": "world'),
('{"obj": {"x": 1}, "b": 2}', '{"obj": {"x": 1}, "b": '),
('{"url": "http://x:80", "b": 1}', '{"url": "http://x:80", "b": '),
('{"a": 1', '{"a": '),
@@ -1360,6 +1396,9 @@ class TestSafeArgPrefix:
("", ""),
('{"k":1}', '{"k":'),
('{"k": 1, "v":2}', '{"k": 1, "v":'),
('{"k":"value"}', '{"k":"value'),
('{"k":"unterminated', '{"k":"unterminated'),
(r'{"k":"escaped \" quote"}', r'{"k":"escaped \" quote'),
],
)
def test_safe_arg_prefix(self, json_str, expected):