fix(apicompat): omit empty tool name on streamed arguments deltas - #5632
Open
3219378872 wants to merge 1 commit into
Open
fix(apicompat): omit empty tool name on streamed arguments deltas#56323219378872 wants to merge 1 commit into
3219378872 wants to merge 1 commit into
Conversation
The responses->chat streaming converter re-emits the tool name as an empty string on every function_call_arguments.delta because ChatFunctionCall.Name has no omitempty. OpenAI-compatible clients accumulate the name from the first tool-call delta, so the trailing "name":"" overwrites it and the call fails dispatch (unknown tool ""). Empty names also break the next round-trip upstream (missing field 'name'). Fixes Wei-Shaw#5631
Contributor
|
All contributors have signed the CLA. ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #5631
问题
/v1/chat/completions流式响应中,responses → chat转换器在每个function_call_arguments.delta里重复输出"name":""(ChatFunctionCall.Name缺少omitempty)。OpenAI 兼容客户端从首个 delta 累积工具名,空串把名字覆盖,导致工具调用失败(Error: unknown tool "");空名历史还会让下一轮被上游拒绝(missing field 'name')。改动
backend/internal/pkg/apicompat/types.go:ChatFunctionCall.Name改为json:"name,omitempty"—— 只有空名被省略,正常名字照常输出;参数增量不再携带 name 字段,与 OpenAI/上游原生流式行为一致。新增回归测试
responses_to_chatcompletions_tool_name_test.go:output_item.addeddelta 保留"name":"exec";function_call_arguments.delta的 JSON 不包含"name"字段。验证
"name":""出现在参数增量中),修复后通过。go test ./internal/pkg/apicompat/...✅go test ./internal/handler/ -run 'Chat|Responses|Stream'✅name;/v1/responses客户端(Codex)路径不受影响(未触碰账户路由)。影响面
仅影响流式 responses→chat 回程中"名字为空"的序列化;所有构造点中名字非空的场景输出逐字节不变。