mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 01:10:23 +08:00
fix(openai): tool_call delta 重复携带 id/type,修复严格客户端兼容性
部分 OpenAI 兼容客户端要求每个 tool_call delta chunk 都包含 id 和 type 字段,否则会将后续 delta 视为无效。通过 block_to_tool_id 映射在 ContentBlockStart 时记录 tool_id,确保后续 ToolCallDelta 能正确回填。
This commit is contained in:
@@ -857,15 +857,21 @@ def test_tool_call_stream_index_stable_across_deltas() -> None:
|
||||
|
||||
# 收集所有 tool_calls chunk
|
||||
tc_indices: list[int] = []
|
||||
tc_ids: list[str] = []
|
||||
for event in all_events:
|
||||
for choice in event.get("choices", []):
|
||||
tcs = choice.get("delta", {}).get("tool_calls")
|
||||
if isinstance(tcs, list):
|
||||
for tc in tcs:
|
||||
tc_indices.append(tc["index"])
|
||||
tc_ids.append(str(tc.get("id") or ""))
|
||||
|
||||
assert len(tc_indices) >= 2, f"expected at least 2 tool_call chunks, got {len(tc_indices)}"
|
||||
# 同一个 tool call 的所有 chunk 必须使用相同的 index
|
||||
assert all(
|
||||
idx == tc_indices[0] for idx in tc_indices
|
||||
), f"tool_call index should be stable, got: {tc_indices}"
|
||||
assert all(tc_id == "fc_001" for tc_id in tc_ids), (
|
||||
"tool_call id should be repeated on every delta for strict OpenAI-compatible clients, "
|
||||
f"got: {tc_ids}"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user