feat : BaseToolParser.feed 增加可选 token_ids 参数

- format_chunk ABC 改为 (token, **kwargs),body/token_ids 通过 kw 传入
- ProtocolHandler._handle_stream 逐 token encode 并透传
- Anthropic builder 用 **kwargs 吸收不使用的参数,零变更
- 新增 3 个 token_ids 参数测试
This commit is contained in:
2026-06-06 11:19:30 +08:00
parent 52aa4d01d5
commit 9e31d4ef2b
6 changed files with 105 additions and 13 deletions
+2 -2
View File
@@ -121,7 +121,7 @@ class TestOpenAIResponseBuilder:
assert p["choices"][0]["finish_reason"] is None
def test_format_chunk(self, builder):
events = builder.format_chunk("hello", "hello")
events = builder.format_chunk("hello", body="hello")
payload = json.loads(events[0].split("data: ", 1)[1])
assert payload["choices"][0]["delta"]["content"] == "hello"
assert payload["choices"][0]["finish_reason"] is None
@@ -192,7 +192,7 @@ class TestAnthropicResponseBuilder:
assert payloads[1]["type"] == "content_block_start"
def test_format_chunk(self, builder):
events = builder.format_chunk("tok", "tok")
events = builder.format_chunk("tok", body="tok")
payload = json.loads(events[0].split("data: ", 1)[1])
assert payload["type"] == "content_block_delta"
assert payload["delta"]["text"] == "tok"