Repository navigation
fix(relayconvert): Responses→Chat 工具输出图片改为提升到后续 user 消息 - #7510
Conversation
A function_call_output whose output is a Responses content-part array was stringified into the Chat tool message, so image data URLs travelled upstream as base64 text instead of vision input. Text parts now stay on the tool message (joined with newlines) and media parts are mapped like regular content parts, then emitted as one user message once the contiguous tool batch ends so parallel tool outputs stay adjacent to their assistant tool_calls message. Media-only outputs carry an "[image]"-style placeholder because upstreams reject empty tool content; payloads that are not content-part arrays keep the stringified form. Closes #7498
|
Understand this PR’s impact Explore downstream dependencies and potential security impact with Blast Radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. WalkthroughThe Responses-to-Chat conversion now separates tool output text from media. Media is emitted in trailing user messages, while tool messages remain contiguous for each assistant tool-call batch. Tests cover recognized parts, fallback payloads, parallel outputs, and trailing media. ChangesTool output media conversion
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Bug fix · Severity of issue fixed: Medium Sequence Diagram(s)sequenceDiagram
participant ResponsesRequest
participant ResponsesToChatConverter
participant ChatCompletionsRequest
ResponsesRequest->>ResponsesToChatConverter: function_call_output items
ResponsesToChatConverter->>ChatCompletionsRequest: contiguous tool messages with text
ResponsesToChatConverter->>ChatCompletionsRequest: trailing user message with media
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. A rabbit sorts the tool-call stream Comment |
…age (QuantumNous#7510) A function_call_output whose output is a Responses content-part array was stringified into the Chat tool message, so image data URLs travelled upstream as base64 text instead of vision input. Text parts now stay on the tool message (joined with newlines) and media parts are mapped like regular content parts, then emitted as one user message once the contiguous tool batch ends so parallel tool outputs stay adjacent to their assistant tool_calls message. Media-only outputs carry an "[image]"-style placeholder because upstreams reject empty tool content; payloads that are not content-part arrays keep the stringified form. Closes QuantumNous#7498 Co-Authored-By: MOON-DREAM-STARS <[email protected]>
…age (QuantumNous#7510) A function_call_output whose output is a Responses content-part array was stringified into the Chat tool message, so image data URLs travelled upstream as base64 text instead of vision input. Text parts now stay on the tool message (joined with newlines) and media parts are mapped like regular content parts, then emitted as one user message once the contiguous tool batch ends so parallel tool outputs stay adjacent to their assistant tool_calls message. Media-only outputs carry an "[image]"-style placeholder because upstreams reject empty tool content; payloads that are not content-part arrays keep the stringified form. Closes QuantumNous#7498 Co-Authored-By: MOON-DREAM-STARS <[email protected]> (cherry picked from commit 6e9de44)
…age (QuantumNous#7510) A function_call_output whose output is a Responses content-part array was stringified into the Chat tool message, so image data URLs travelled upstream as base64 text instead of vision input. Text parts now stay on the tool message (joined with newlines) and media parts are mapped like regular content parts, then emitted as one user message once the contiguous tool batch ends so parallel tool outputs stay adjacent to their assistant tool_calls message. Media-only outputs carry an "[image]"-style placeholder because upstreams reject empty tool content; payloads that are not content-part arrays keep the stringified form. Closes QuantumNous#7498 Co-Authored-By: MOON-DREAM-STARS <[email protected]>
…age (QuantumNous#7510) A function_call_output whose output is a Responses content-part array was stringified into the Chat tool message, so image data URLs travelled upstream as base64 text instead of vision input. Text parts now stay on the tool message (joined with newlines) and media parts are mapped like regular content parts, then emitted as one user message once the contiguous tool batch ends so parallel tool outputs stay adjacent to their assistant tool_calls message. Media-only outputs carry an "[image]"-style placeholder because upstreams reject empty tool content; payloads that are not content-part arrays keep the stringified form. Closes QuantumNous#7498 Co-Authored-By: MOON-DREAM-STARS <[email protected]>
…age (QuantumNous#7510) A function_call_output whose output is a Responses content-part array was stringified into the Chat tool message, so image data URLs travelled upstream as base64 text instead of vision input. Text parts now stay on the tool message (joined with newlines) and media parts are mapped like regular content parts, then emitted as one user message once the contiguous tool batch ends so parallel tool outputs stay adjacent to their assistant tool_calls message. Media-only outputs carry an "[image]"-style placeholder because upstreams reject empty tool content; payloads that are not content-part arrays keep the stringified form. Closes QuantumNous#7498 Co-Authored-By: MOON-DREAM-STARS <[email protected]>
…age (QuantumNous#7510) A function_call_output whose output is a Responses content-part array was stringified into the Chat tool message, so image data URLs travelled upstream as base64 text instead of vision input. Text parts now stay on the tool message (joined with newlines) and media parts are mapped like regular content parts, then emitted as one user message once the contiguous tool batch ends so parallel tool outputs stay adjacent to their assistant tool_calls message. Media-only outputs carry an "[image]"-style placeholder because upstreams reject empty tool content; payloads that are not content-part arrays keep the stringified form. Closes QuantumNous#7498 Co-Authored-By: MOON-DREAM-STARS <[email protected]>
🔗 关联任务 / Related Issue
🚀 变更类型 / Type of change
📝 变更描述 / Description
Responses→Chat 转换器把
function_call_output.output的内容块数组整体 JSON 字符串化进 tool 消息,图片 data URL 以 base64 文本形式发往上游:图片不再是视觉输入,且其字节被上游按文本计数。修复(仅
relaykit/relayconvert/internal/oai_responses/to_oai_chat_req.go):output为内容块数组时,文本块(input_text/output_text/text)以换行拼接留在 tool 消息;媒体块(input_image/input_file/input_audio/input_video)复用现有responsesContentPartsToChatContent映射成 Chat 内容块。function_call_output结束后(或输入结束时)合并成一条 user 消息。Chat Completions 要求同一 assistanttool_calls的 tool 回复必须连续,并行工具调用时若在中间插 user 消息会被上游 400。[image]、[image] [file]这类占位,避免上游拒绝空 tool 内容。不改 Claude→Chat、Gemini→Chat 路径,不改计费逻辑。
📸 运行证明 / Proof of Work
单元测试(relaykit 模块,
GOWORK=off)TestResponsesRequestToChatCompletionsRequestToolOutputContentParts(8 个形态)与TestResponsesRequestToChatCompletionsRequestHoistsToolOutputMediaAfterToolBatch(并行工具输出保持连续、输入末尾刷出媒体)。go test ./... -count=1、go vet ./...、go build ./...、gofmt -l relayconvert/internal/oai_responses/全部通过。根模块:go vet ./...、go build ./...通过;make test(根模块 + relaykit)52 个包 ok、0 失败。本地 live 复现与验证(一次性 new-api 实例 + 捕获代理 + 本地网关上游,Advanced Custom 渠道把
/v1/responses路由到上游/v1/chat/completions,converteropenai_responses_to_openai_chat_completions)请求:user 提问 → 两个并行
function_call(截图、读文件)→ 截图的function_call_output.output为[input_text, input_image(30 KB PNG data URL)],读文件的 output 为字符串。origin/main)data:image/png;base64,…的 JSON 字符串(30,147 字符),无任何image_url消息Black LIVE_TOOL_MEDIA_05c4047f(颜色错误)screenshot captured/note.txt: …;末尾 user 消息含image_urlRed LIVE_TOOL_MEDIA_58224119Red LIVE_TOOL_MEDIA_f158cafc同一张 22.5 KB 的红色噪点 PNG:修复前 base64 被上游按文本分词,一次请求消耗 21,010 prompt tokens,模型只能从 base64 文本猜颜色并答错;修复后图片按视觉输入计费(274 tokens)且颜色答对。上游 usage 与消费日志、四项额度变动一致。
✅ 提交前检查项 / Checklist
New feature,我已关联对应 Issue;若尚无 Issue,我已先自行创建。go build通过或测试通过,不视为有效证明。