fix: support OpenAI image dynamic resolution#57
Conversation
|
CodeAnt AI is reviewing your PR. Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the OpenAI image generation capabilities by introducing support for the 'gpt-image-2' model and enabling dynamic resolution and aspect ratio controls. It also fixes a timeout reconciliation issue to ensure 'openai-image' tasks receive the correct configuration and enables reference image support across the board. The desktop application version has been bumped to 2.8.2 to reflect these changes. Highlights
Ignored Files
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
| if (useQuality) { | ||
| formData.append('quality', config.imageQuality); | ||
| } |
There was a problem hiding this comment.
🟠 Architect Review — HIGH
Multipart image-to-image requests now include a quality field from the frontend, but the backend multipart parsing (ParseGenerateRequestFromMultipart) and GenerateWithImagesHandler never read or forward quality into taskParams, so OpenAI Images quality settings are ignored for reference-image flows.
Suggestion: Extend the multipart contract so that quality is parsed into MultipartRequest and included in taskParams in GenerateWithImagesHandler, and add a test covering an OpenAI Images reference-image request to verify that changing quality affects the upstream call.
Fix in Cursor | Fix in VSCode Claude
(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖
This is an **Architect / Logical Review** comment left during a code review. These reviews are first-class, important findings — not optional suggestions. Do NOT dismiss this as a 'big architectural change' just because the title says architect review; most of these can be resolved with a small, localized fix once the intent is understood.
**Path:** desktop/src/hooks/useGenerate.ts
**Line:** 460:462
**Comment:**
*HIGH: Multipart image-to-image requests now include a `quality` field from the frontend, but the backend multipart parsing (`ParseGenerateRequestFromMultipart`) and `GenerateWithImagesHandler` never read or forward `quality` into taskParams, so OpenAI Images quality settings are ignored for reference-image flows.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
If a suggested approach is provided above, use it as the authoritative instruction. If no explicit code suggestion is given, you MUST still draft and apply your own minimal, localized fix — do not punt back with 'no suggestion provided, review manually'. Keep the change as small as possible: add a guard clause, gate on a loading state, reorder an await, wrap in a conditional, etc. Do not refactor surrounding code or expand scope beyond the finding.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix| export const usesDynamicOpenAIImageSize = (provider: string, model?: string): boolean => ( | ||
| provider === 'openai-image' && String(model || '').toLowerCase().includes('gpt-image-2') | ||
| ); | ||
| export const supportsReferenceImages = (_provider: string): boolean => true; |
There was a problem hiding this comment.
🟠 Architect Review — HIGH
supportsReferenceImages now always returns true, so the UI enables reference images for openai-image and accepts JPG/WebP uploads, but OpenAIImageProvider.collectOpenAIImageReferences rejects any non-PNG reference; typical JPEG/WebP reference uploads with OpenAI Images now fail at generation time instead of being prevented or normalized.
Suggestion: Either gate reference-image support per provider/model and format (disallow non-PNG refs for openai-image in the UI), or normalize reference images to PNG before sending and/or surface a clear pre-submit validation error when the format is incompatible.
Fix in Cursor | Fix in VSCode Claude
(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖
This is an **Architect / Logical Review** comment left during a code review. These reviews are first-class, important findings — not optional suggestions. Do NOT dismiss this as a 'big architectural change' just because the title says architect review; most of these can be resolved with a small, localized fix once the intent is understood.
**Path:** desktop/src/store/configStore.ts
**Line:** 86:86
**Comment:**
*HIGH: `supportsReferenceImages` now always returns true, so the UI enables reference images for `openai-image` and accepts JPG/WebP uploads, but `OpenAIImageProvider.collectOpenAIImageReferences` rejects any non-PNG reference; typical JPEG/WebP reference uploads with OpenAI Images now fail at generation time instead of being prevented or normalized.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
If a suggested approach is provided above, use it as the authoritative instruction. If no explicit code suggestion is given, you MUST still draft and apply your own minimal, localized fix — do not punt back with 'no suggestion provided, review manually'. Keep the change as small as possible: add a guard clause, gate on a loading state, reorder an await, wrap in a conditional, etc. Do not refactor surrounding code or expand scope beyond the finding.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix| if (useQuality) { | ||
| formData.append('quality', config.imageQuality); |
There was a problem hiding this comment.
Suggestion: The multipart flow now sends a quality field, but the backend multipart parser does not read or forward quality into task params, so quality control is silently ignored whenever reference images are used. This creates inconsistent behavior between JSON generation and image-to-image generation. Update the multipart parsing/handler path to include quality (and pass it into provider params) so this new field actually takes effect. [logic error]
Severity Level: Major ⚠️
- ⚠️ OpenAI image-to-image ignores selected quality parameter.
- ⚠️ Quality dropdown ineffective whenever reference images are used.
- ⚠️ Behavior diverges between /tasks/generate and /tasks/generate-with-images.Steps of Reproduction ✅
1. In the desktop app, open the ConfigPanel
(desktop/src/components/ConfigPanel/index.tsx:4-10) and select the image provider
`openai-image`, which enables the quality dropdown in BatchSettings
(desktop/src/components/ConfigPanel/BatchSettings.tsx:67-75) because
`supportsQualityControl(imageProvider)` returns true for `openai-image`
(desktop/src/store/configStore.ts:12-19). Choose a non-default `imageQuality` (e.g.
"high") and add at least one reference image so that `refFiles.length > 0` (configStore
fields `imageQuality` and `refFiles` are defined in
desktop/src/store/configStore.ts:31-37).
2. Click the "Generate" button, whose onClick calls `generate` from `useGenerate()`
(desktop/src/components/ConfigPanel/index.tsx:34-41). Inside `useGenerate`, `useQuality`
is set from `supportsQualityControl(config.imageProvider)`
(desktop/src/hooks/useGenerate.ts:413) and `allowReferenceImages` is true with
`config.refFiles.length > 0`, so `submitSingleGenerate` or the single-task branch builds a
`FormData` and appends `quality` when `useQuality` is true
(desktop/src/hooks/useGenerate.ts:460-461 and 634-635). The hook then calls
`generateBatchWithImages(formData)` (desktop/src/hooks/useGenerate.ts:101 and 480), which
POSTs this multipart body to `/tasks/generate-with-images`
(desktop/src/services/generateApi.ts:13-17).
3. On the backend, the route `POST /v1/tasks/generate-with-images` is wired to
`GenerateWithImagesHandler` (backend/cmd/server/main.go:276-277).
`GenerateWithImagesHandler` (backend/internal/api/handlers.go:521-524) immediately calls
`ParseGenerateRequestFromMultipart(c)` to parse the multipart form.
`ParseGenerateRequestFromMultipart` and its fallback `parseWithStandardLibrary`
(backend/internal/api/multipart_helper.go:21-35, 37-52, 95-115, and 128-151) register
handlers for fields like `provider`, `model_id`, `prompt`, `aspectRatio`, `imageSize`,
`count`, `verbose_logging`, `prompt_optimize_*`, `refPaths`, and `refImages`, but there is
no registration or parsing of a `quality` field (confirmed by no `"quality"` matches in
multipart_helper.go via Grep).
4. After parsing, `GenerateWithImagesHandler` constructs `taskParams` containing `prompt`,
`provider`, `model_id`, `aspect_ratio`, `resolution_level`, `count`, and
`reference_images` (backend/internal/api/handlers.go:74-88) and passes this map to the
provider. The `OpenAIImageProvider` expects an optional `quality` parameter and validates
it (backend/internal/provider/openai_image.go:16-21) and then forwards it into the OpenAI
request body (`buildImagesGenerationRequestBody` sets `body.Quality` from
`params["quality"]` at backend/internal/provider/openai_image.go:107-115, and
`openAIImageEditFields` includes it in the multipart fields at 334-338). Because
`taskParams` from the multipart path never includes `quality`, `params["quality"]` is
empty, so `body.Quality` stays unset and no `quality` field is sent to OpenAI for image
edits. In contrast, the JSON text-to-image path `/tasks/generate` uses `GenerateHandler`
(backend/internal/api/handlers.go:399-419), which passes `req.Params` (including `quality`
from `buildImageParams` in desktop/src/hooks/useGenerate.ts:415-417 and 51-60) directly to
the provider, and `buildConfigSnapshot` records `params["quality"]`
(backend/internal/api/handlers.go:104-108), so the selected quality only takes effect when
no reference images are used.Fix in Cursor | Fix in VSCode Claude
(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** desktop/src/hooks/useGenerate.ts
**Line:** 460:461
**Comment:**
*Logic Error: The multipart flow now sends a `quality` field, but the backend multipart parser does not read or forward `quality` into task params, so quality control is silently ignored whenever reference images are used. This creates inconsistent behavior between JSON generation and image-to-image generation. Update the multipart parsing/handler path to include `quality` (and pass it into provider params) so this new field actually takes effect.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix|
CodeAnt AI finished reviewing your PR. |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 34 |
| Duplication | 2 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
There was a problem hiding this comment.
Code Review
This pull request introduces support for the 'openai-image' model, including backend logic updates to handle provider timeouts and frontend configuration changes to support dynamic image sizes and quality control. The review comments suggest renaming several boolean helper functions in 'desktop/src/store/configStore.ts' to follow the project's naming convention of prefixing boolean variables and functions with 'is/has/should'.
| export const usesDynamicOpenAIImageSize = (provider: string, model?: string): boolean => ( | ||
| provider === 'openai-image' && String(model || '').toLowerCase().includes('gpt-image-2') | ||
| ); |
There was a problem hiding this comment.
根据项目代码审查规范第 106 条,布尔值变量和函数应以 is/has/should 开头。建议将 usesDynamicOpenAIImageSize 重命名为 isUsingDynamicOpenAIImageSize 以符合命名规范。
| export const usesDynamicOpenAIImageSize = (provider: string, model?: string): boolean => ( | |
| provider === 'openai-image' && String(model || '').toLowerCase().includes('gpt-image-2') | |
| ); | |
| export const isUsingDynamicOpenAIImageSize = (provider: string, model?: string): boolean => ( | |
| provider === 'openai-image' && String(model || '').toLowerCase().includes('gpt-image-2') | |
| ); |
References
- React/TypeScript 命名规范:布尔值以 is/has/should 开头 (link)
| export const usesDynamicOpenAIImageSize = (provider: string, model?: string): boolean => ( | ||
| provider === 'openai-image' && String(model || '').toLowerCase().includes('gpt-image-2') | ||
| ); | ||
| export const supportsReferenceImages = (_provider: string): boolean => true; |
There was a problem hiding this comment.
根据项目代码审查规范第 106 条,布尔值变量和函数应以 is/has/should 开头。建议将 supportsReferenceImages 重命名为 isReferenceImageSupported。
| export const supportsReferenceImages = (_provider: string): boolean => true; | |
| export const isReferenceImageSupported = (_provider: string): boolean => true; |
References
- React/TypeScript 命名规范:布尔值以 is/has/should 开头 (link)
| export const usesNativeImageSize = (provider: string, model?: string): boolean => ( | ||
| provider === 'openai-image' && !usesDynamicOpenAIImageSize(provider, model) | ||
| ); |
There was a problem hiding this comment.
根据项目代码审查规范第 106 条,布尔值变量和函数应以 is/has/should 开头。建议将 usesNativeImageSize 重命名为 isUsingNativeImageSize。
| export const usesNativeImageSize = (provider: string, model?: string): boolean => ( | |
| provider === 'openai-image' && !usesDynamicOpenAIImageSize(provider, model) | |
| ); | |
| export const isUsingNativeImageSize = (provider: string, model?: string): boolean => ( | |
| provider === 'openai-image' && !isUsingDynamicOpenAIImageSize(provider, model) | |
| ); |
References
- React/TypeScript 命名规范:布尔值以 is/has/should 开头 (link)
| export const usesNativeImageSize = (provider: string, model?: string): boolean => ( | ||
| provider === 'openai-image' && !usesDynamicOpenAIImageSize(provider, model) | ||
| ); | ||
| export const supportsQualityControl = (provider: string): boolean => provider === 'openai-image'; |
There was a problem hiding this comment.
根据项目代码审查规范第 106 条,布尔值变量和函数应以 is/has/should 开头。建议将 supportsQualityControl 重命名为 isQualityControlSupported。
| export const supportsQualityControl = (provider: string): boolean => provider === 'openai-image'; | |
| export const isQualityControlSupported = (provider: string): boolean => provider === 'openai-image'; |
References
- React/TypeScript 命名规范:布尔值以 is/has/should 开头 (link)
…olution fix: support OpenAI image dynamic resolution
User description
Summary
Validation
CodeAnt-AI Description
Support dynamic OpenAI image sizing and keep OpenAI image settings separate
What Changed
gpt-image-2model with aspect ratio and 1K/2K/4K size controlsImpact
✅ Fewer OpenAI image generation timeouts✅ More OpenAI image model options✅ Clearer OpenAI image sizing controls🔄 Retrigger CodeAnt AI Review
Details
💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.