fix: preserve OpenAI image edit reference fields - #4646
Conversation
WalkthroughThree files are modified to support JSON-based image edit requests. ImageRequest DTO gains three new fields. ConvertImageRequest adds JSON detection to skip multipart processing for JSON image edits. Helper code replaces json.Marshal with common.Marshal for consistency. ChangesJSON-Based Image Edit Support
Sequence DiagramsequenceDiagram
participant Client
participant ConvertImageRequest
participant isJSONRequest
participant DoRequest
participant Helper as valid_request
Client->>ConvertImageRequest: ImageEdits request (JSON)
ConvertImageRequest->>isJSONRequest: Check content-type
isJSONRequest-->>ConvertImageRequest: true
ConvertImageRequest-->>Client: Return early (skip multipart)
Client->>DoRequest: Forward JSON request
DoRequest->>DoRequest: Check isJSONRequest + ImagesEdits
DoRequest-->>Client: Process as JSON (no form)
alt Multipart Path
Client->>ConvertImageRequest: ImageEdits request (form)
ConvertImageRequest->>isJSONRequest: Check content-type
isJSONRequest-->>ConvertImageRequest: false
ConvertImageRequest->>Helper: Build multipart payload
Helper->>Helper: Encode with common.Marshal
Helper-->>ConvertImageRequest: multipart body
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
relay/channel/openai/adaptor.go (1)
603-613: ⚡ Quick winConsider adding server-side image presence validation for the JSON path
The multipart path guards against an imageless request:
if !foundArrayImages && (len(imageFiles) == 0) { return nil, errors.New("image is required") }The JSON path has no equivalent check — if neither
imagenorimagesis set in the JSON body, the request goes upstream and OpenAI returns a provider-level error rather than a clear local one. A lightweight guard inConvertImageRequestwould match the multipart UX:✨ Proposed addition in ConvertImageRequest (JSON branch)
case relayconstant.RelayModeImagesEdits: if isJSONRequest(c) { + if len(request.Image) == 0 && len(request.Images) == 0 { + return nil, errors.New("image or images is required for image edit") + } return request, nil }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@relay/channel/openai/adaptor.go` around lines 603 - 613, DoRequest routes image-edit requests to either the multipart form path or the JSON path, but ConvertImageRequest (the JSON branch) lacks the multipart-equivalent validation that ensures an image is present; add a lightweight server-side guard in ConvertImageRequest to detect absence of both "image" and "images" fields (or empty arrays/strings) and return a clear error (e.g., "image is required") before proxying upstream so that image-edit JSON requests fail locally like the multipart branch does. Ensure the check mirrors the multipart logic (used where foundArrayImages/imageFiles are checked) and returns an appropriate error type and message from ConvertImageRequest so DoRequest callers receive the local validation error.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@relay/channel/openai/adaptor.go`:
- Around line 603-613: DoRequest routes image-edit requests to either the
multipart form path or the JSON path, but ConvertImageRequest (the JSON branch)
lacks the multipart-equivalent validation that ensures an image is present; add
a lightweight server-side guard in ConvertImageRequest to detect absence of both
"image" and "images" fields (or empty arrays/strings) and return a clear error
(e.g., "image is required") before proxying upstream so that image-edit JSON
requests fail locally like the multipart branch does. Ensure the check mirrors
the multipart logic (used where foundArrayImages/imageFiles are checked) and
returns an appropriate error type and message from ConvertImageRequest so
DoRequest callers receive the local validation error.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 322709dd-813f-4588-a224-887ad6cf7fa5
📒 Files selected for processing (3)
dto/openai_image.gorelay/channel/openai/adaptor.gorelay/helper/valid_request.go
- OpenAI image edit: preserve reference image and metadata (QuantumNous#4646) - UI: migrate Select to Base UI items API (QuantumNous#4655) - feat: add model performance badges to model lists - fix: improve billing settings forms - refactor: move top_up_link from status API to topup info API Preserved local hupijiao payment integration across all merge conflicts. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix: preserve OpenAI image edit reference fields * feat: support json image edit requests
* fix: preserve OpenAI image edit reference fields * feat: support json image edit requests
* fix: preserve OpenAI image edit reference fields * feat: support json image edit requests
… edit - ImageRequest 新增 images/mask/input_fidelity 字段,避免 image edit 引用字段丢失 - 当请求为 application/json 时,image edit 直接透传 JSON 而非强制走 multipart form (ConvertImageRequest 早返回 + DoRequest 条件加 !isJSONRequest) - valid_request.go 不改:该行已是 common.Marshal,encoding/json 仍被 json.RawMessage 类型使用 upstream 38a3314 QuantumNous#4646
Important
📝 变更描述 / Description
(简述:做了什么?为什么这样改能生效?请基于你对代码逻辑的理解来写,避免粘贴未经整理的内容)
补充图片编辑参数,支持application/json传入参数
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
(请在此粘贴截图、关键日志或测试报告,以证明变更生效)
Summary by CodeRabbit