Skip to content

fix: gemini image correct generationConfig - #2309

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
feitianbubu:pr/fix-gemini-ImageConfig
Nov 26, 2025
Merged

Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
feitianbubu:pr/fix-gemini-ImageConfig

Conversation

@feitianbubu

@feitianbubu feitianbubu commented Nov 26, 2025 •

Copy link
Copy Markdown
Member

修复gemini-3-pro-image-preview分辨率设置无效问题
增加透传ImageConfig参数

Summary by CodeRabbit

  • Improvements
    • Enhanced image preview support for Gemini 2.5 Flash and Gemini 3 Pro models with additional resolution and aspect-ratio options.
    • Improved configuration handling for Gemini requests to ensure proper schema alignment.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Nov 26, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

These changes expand Gemini model support by adding new image size mappings for Gemini 2.5 Flash and Gemini 3 Pro, updating JSON request field names to align with a new schema, and implementing support for loading generationConfig from extra_body.google.

Changes

Cohort / File(s) Summary
Image Size Mappings and Request Schema
relay/channel/gemini/adaptor.go
Added comprehensive size mappings for Gemini 2.5 Flash and Gemini 3 Pro image previews covering multiple aspect ratios (1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9). Updated mappings for 2048x2048 and 4096x4096 with new AspectRatio and ImageSize values. Renamed JSON request fields in Gemini-3-Pro path: response_modalities → responseModalities, image_config → imageConfig, generation_config → generationConfig, and updated nested google keys.
Generation Configuration Loading
relay/channel/gemini/relay-gemini.go
Added support for loading and applying generationConfig from extra_body.google with JSON marshal/unmarshal operations into geminiRequest.GenerationConfig, including error handling for serialization failures.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Focus on verifying the completeness and correctness of the new size/aspect-ratio mappings for accuracy
  • Review marshal/unmarshal error handling logic in relay-gemini.go for proper error propagation
  • Ensure JSON field name changes align with actual Gemini API schema requirements

Possibly related PRs

Suggested reviewers

  • seefs001
  • creamlike1024

Poem

🐰 A rabbit hops through schema fields with glee,
Mappings bloom in ratios: 1:1 through 21:9!
ResponseModalities dances to camelCase now,
GenerationConfig finds its nested way,
Gemini models sing in perfect harmony! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: gemini image correct generationConfig' is directly related to the main changes in the changeset, which involve correcting the generationConfig field names and adding generationConfig support in the Gemini image handling code.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
relay/channel/gemini/adaptor.go (1)

154-163: Handle extraBody marshal errors when constructing Gemini‑3‑Pro image chat request

The google.generationConfig structure and camelCase keys look correct and are aligned with the extra_body.google.generationConfig consumer in CovertOpenAI2Gemini. The only minor issue is silently discarding potential marshal errors:

chatRequest.ExtraBody, _ = json.Marshal(extraBody)

Even though this map is under your control and failures are unlikely, it’s safer to surface the error so misconfigurations can’t silently degrade behavior.

A small, clearer variant:

-        chatRequest.ExtraBody, _ = json.Marshal(extraBody)
+        bodyBytes, err := json.Marshal(extraBody)
+        if err != nil {
+            return nil, fmt.Errorf("failed to marshal extra body for gemini-3-pro image request: %w", err)
+        }
+        chatRequest.ExtraBody = bodyBytes
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5ac1d02 and ab3cda3.

📒 Files selected for processing (2)
  • relay/channel/gemini/adaptor.go (2 hunks)
  • relay/channel/gemini/relay-gemini.go (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: antecanis8
Repo: QuantumNous/new-api PR: 1500
File: relay/channel/gemini/adaptor.go:0-0
Timestamp: 2025-08-04T14:36:34.528Z
Learning: All currently serviced Gemini embedding models support the outputDimensionality parameter, not just specific models like text-embedding-004.
Learnt from: antecanis8
Repo: QuantumNous/new-api PR: 1500
File: relay/channel/gemini/adaptor.go:0-0
Timestamp: 2025-08-04T14:36:34.528Z
Learning: In the Gemini API batchEmbedContents endpoint, each request item in the "requests" array should include its own "model" field, as shown in the official documentation at https://ai.google.dev/api/embeddings?hl=zh-cn#method:-models.batchembedcontents. The model field is not a top-level parameter.
📚 Learning: 2025-08-08T17:12:43.157Z
Learnt from: RedwindA
Repo: QuantumNous/new-api PR: 1537
File: relay/gemini_handler.go:330-342
Timestamp: 2025-08-08T17:12:43.157Z
Learning: In the new-api repository, the `GeminiEmbeddingHandler` function in `relay/gemini_handler.go` is designed specifically for native Gemini embedding requests and therefore does not require the `ConvertGeminiRequest` step that is used in the chat handler. The embedding requests are already in the native Gemini format and don't need conversion.

Applied to files:

  • relay/channel/gemini/relay-gemini.go
  • relay/channel/gemini/adaptor.go
🔇 Additional comments (2)
relay/channel/gemini/relay-gemini.go (1)

243-251: GenerationConfig passthrough from extra_body.google is consistent and safe

The marshal→unmarshal overlay into geminiRequest.GenerationConfig looks correct: it preserves existing defaults while allowing callers (including the Gemini-3-Pro image path) to inject generationConfig in a typed way. Error handling is explicit and the logic cleanly reuses the existing extra_body.google gate so ThinkingAdaptor behavior is unchanged.

relay/channel/gemini/adaptor.go (1)

89-107: Image size/aspect-ratio mappings look coherent for Flash and 3‑Pro preview

The expanded getSizeMappings table for Gemini 2.5 Flash (1K defaults) and Gemini 3 Pro preview resolutions is internally consistent with processSizeParameters: size drives aspect ratio, with 2K/4K 1:1 entries also providing an ImageSize that can be overridden by quality if present. No correctness issues stand out here.

@Calcium-Ion
Calcium-Ion merged commit 95a7749 into QuantumNous:main Nov 26, 2025
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
…ageConfig

fix: gemini image correct generationConfig
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
…ageConfig

fix: gemini image correct generationConfig
junjundesk pushed a commit to junjundesk/new-api that referenced this pull request Oct 3, 2026
…ageConfig

fix: gemini image correct generationConfig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants