Repository navigation
fix: gemini image correct generationConfig - #2309
Conversation
WalkthroughThese 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
relay/channel/gemini/adaptor.go (1)
154-163: HandleextraBodymarshal errors when constructing Gemini‑3‑Pro image chat requestThe
google.generationConfigstructure and camelCase keys look correct and are aligned with theextra_body.google.generationConfigconsumer inCovertOpenAI2Gemini. 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
📒 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.gorelay/channel/gemini/adaptor.go
🔇 Additional comments (2)
relay/channel/gemini/relay-gemini.go (1)
243-251: GenerationConfig passthrough fromextra_body.googleis consistent and safeThe marshal→unmarshal overlay into
geminiRequest.GenerationConfiglooks correct: it preserves existing defaults while allowing callers (including the Gemini-3-Pro image path) to injectgenerationConfigin a typed way. Error handling is explicit and the logic cleanly reuses the existingextra_body.googlegate soThinkingAdaptorbehavior is unchanged.relay/channel/gemini/adaptor.go (1)
89-107: Image size/aspect-ratio mappings look coherent for Flash and 3‑Pro previewThe expanded
getSizeMappingstable for Gemini 2.5 Flash (1K defaults) and Gemini 3 Pro preview resolutions is internally consistent withprocessSizeParameters:sizedrives aspect ratio, with 2K/4K 1:1 entries also providing anImageSizethat can be overridden byqualityif present. No correctness issues stand out here.
…ageConfig fix: gemini image correct generationConfig
…ageConfig fix: gemini image correct generationConfig
…ageConfig fix: gemini image correct generationConfig
修复gemini-3-pro-image-preview分辨率设置无效问题
增加透传ImageConfig参数
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.