Skip to content

feat: gemini imagen quality value - #1983

Merged
seefs001 merged 1 commit into
QuantumNous:mainfrom
Sh1n3zZ:feat-imagen-related
Oct 9, 2025
Merged

seefs001 merged 1 commit into
QuantumNous:mainfrom
Sh1n3zZ:feat-imagen-related

Conversation

@Sh1n3zZ

@Sh1n3zZ Sh1n3zZ commented Oct 8, 2025 •

Copy link
Copy Markdown
Contributor
  • Support the use of the imageSize parameter when requesting gemini imagen models to control the size of the generated images (for openai endpoint, this value is mapped to quality)

https://ai.google.dev/gemini-api/docs/imagen
https://platform.openai.com/docs/api-reference/images/create

Summary by CodeRabbit

  • New Features
    • Expanded Gemini image generation sizes: now supports 256x256, 512x512, 1024x1024 (1:1), 1536x1024 (3:2), and 1024x1536 (2:3).
    • Quality setting now controls output resolution when provided: “hd”/“high” (and “2K”) produce 2K images; other values (e.g., “standard”, “medium”, “low”, “auto”, “1K”) default to 1K.
    • More flexible aspect ratio handling for varied creative outputs.

@coderabbitai

coderabbitai Bot commented Oct 8, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Adds ImageSize to GeminiImageParameters and updates Gemini adaptor logic to map more image size strings to aspect ratios and derive Parameters.ImageSize from request.Quality when provided.

Changes

Cohort / File(s) Summary
DTO: Gemini parameters
dto/gemini.go
Added field ImageSize string \json:"imageSize,omitempty"`toGeminiImageParameters`.
Adaptor: Gemini image handling
relay/channel/gemini/adaptor.go
Expanded size→aspectRatio mapping: supports 256x256, 512x512 → 1:1; 1536x1024 → 3:2; 1024x1536 → 2:3. Added quality→imageSize mapping: when request.Quality present, sets Parameters.ImageSize to "2K" for "hd"/"high"/"2K", else "1K" for other values and default.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Client
  participant Adaptor as Gemini Adaptor
  participant Gemini as Gemini API

  Client->>Adaptor: Submit image generation request (size, quality)
  rect rgba(200,230,255,0.3)
    note right of Adaptor: Size → Aspect Ratio
    Adaptor->>Adaptor: Map size string\n- 256x256/512x512/1024x1024 → 1:1\n- 1536x1024 → 3:2\n- 1024x1536 → 2:3
  end
  rect rgba(200,255,220,0.3)
    note right of Adaptor: Quality → ImageSize (if provided)
    alt quality in ["hd","high","2K"]
      Adaptor->>Adaptor: Parameters.ImageSize = "2K"
    else other/non-empty quality
      Adaptor->>Adaptor: Parameters.ImageSize = "1K"
    end
  end
  Adaptor->>Gemini: Send request with Parameters{aspectRatio, imageSize?}
  Gemini-->>Adaptor: Response
  Adaptor-->>Client: Result
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • feat: imagen for vertex channel #1614 — Adjusts size→aspectRatio logic in the same adaptor; overlaps with this PR’s expanded mappings and thus likely part of the same image sizing refactor.

Poem

A nibble of pixels, a hop through the night,
I tuned the sizes to ratios right.
Quality whispers: “1K or 2?”
I twitch my ears—“2K for you.”
With tidy params and carrot-bright cheer,
Our images bloom—crisp and clear! 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title Check ❓ Inconclusive The title “feat: gemini imagen quality value” is vague and does not clearly describe the primary change of adding an imageSize parameter and its mapping from quality values, making it hard for a reviewer to understand the main feature. Consider renaming the title to explicitly mention the addition of the imageSize field and its mapping from quality values for Gemini Imagen, for example: “feat: add imageSize mapping from quality for Gemini Imagen.”
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ 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)

98-118: Consider simplifying the quality mapping logic.

The switch statement can be streamlined since multiple cases and the default all map to "1K":

Apply this diff to simplify:

-	if request.Quality != "" {
-		imageSize := "1K" // default
-		switch request.Quality {
-		case "hd", "high":
-			imageSize = "2K"
-		case "2K":
-			imageSize = "2K"
-		case "standard", "medium", "low", "auto", "1K":
-			imageSize = "1K"
-		default:
-			// unknown quality value, default to 1K
-			imageSize = "1K"
-		}
-		geminiRequest.Parameters.ImageSize = imageSize
-	}
+	if request.Quality != "" {
+		imageSize := "1K" // default for standard, medium, low, auto, 1K, and unknown values
+		if request.Quality == "hd" || request.Quality == "high" || request.Quality == "2K" {
+			imageSize = "2K"
+		}
+		geminiRequest.Parameters.ImageSize = imageSize
+	}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0c417e8 and 8f00af1.

📒 Files selected for processing (2)
  • dto/gemini.go (1 hunks)
  • relay/channel/gemini/adaptor.go (2 hunks)
🔇 Additional comments (2)
dto/gemini.go (1)

332-332: LGTM!

The ImageSize field addition is correctly structured with appropriate JSON tags and follows the existing conventions in the struct.

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

70-75: LGTM!

The additional image size mappings are correct:

  • 256x256 and 512x512 appropriately map to 1:1 aspect ratio
  • 1536x1024 correctly maps to 3:2
  • 1024x1536 correctly maps to 2:3

@seefs001
seefs001 merged commit 1a398bb into QuantumNous:main Oct 9, 2025
@Sh1n3zZ
Sh1n3zZ deleted the feat-imagen-related branch October 10, 2025 17:54
x22x22 pushed a commit to x22x22/new-api that referenced this pull request Apr 24, 2026
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
junjundesk pushed a commit to junjundesk/new-api that referenced this pull request Oct 3, 2026
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