Repository navigation
feat(bridge): support image input (multimodal) - #1
Merged
Merged
Conversation
- ConvertIncomingMessage extracts image parts and builds Qoder contents
with {type:image_url, image_url:{url}} before the text part
- image-only user messages are no longer silently dropped
- ExtractMessageImages handles OpenAI image_url, Responses input_image and
Claude image blocks (base64 + url sources), with a contents[] fallback
- reject non data:/http(s) image URLs
- add unit tests and an end-to-end test asserting the encoded upstream body
carries the image part
Owner
|
牛谢谢好兄弟维护 |
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.
背景
当前
bridge只处理文本与 tool calls:ConvertIncomingMessage用NormalizeMessageContent提取文本后,content 数组里的图片块会被静默丢弃(且纯图片消息因text == ""直接返回 nil 被整条丢掉)。本 PR 让qoder2api支持图片输入(多模态)。改动
internal/bridge/messages.go:ConvertIncomingMessage新增images := ExtractMessageImages(msg);丢弃条件由text == ""改为text == "" && len(images) == 0(纯图片消息不再被丢);user 分支改用BuildUserMessageWithImages(text, images)。BuildUserMessageWithImages:按 Qoder 协议构造contents—— 图片在前{type:image_url, image_url:{url}},文本在后{type:text, text}(与官方客户端一致)。ExtractMessageImages,覆盖三种形态:{type:image_url, image_url:{url}}{type:input_image, image_url:"..."}{type:image, source:{type:base64|url, ...}}(转成 data/http URL)contents数组回退(图片可能直接放在 contents 里)。imageURLFromPart/claudeImageToURL/looksLikeImageURL:只放行data:与http(s),其余丢弃。BuildUserMessage(text)保留为薄封装,向后兼容。因为
chat.go/claude.go/codex.go三个入口都走BuildQoderMessages → ConvertIncomingMessage,OpenAI / Claude / Codex 三条协议一次性覆盖。测试
新增
image_test.go(7 个单元用例)与image_integration_test.go(1 个端到端用例:起 mock 上游,走完整BuildQoderMessages → CallQoderWithOpts → cosy.Encode,把上游收到的 body 解码回来断言含 image part)。真机验证
导入真实 Qoder 账号(OAuth)后实测:
The image length and width do not meet the model restrictions. [height:1 or width:1 must be larger than 10],证明图片 part 已被上游当作图片解析;兼容性
BuildUserMessage签名不变。