Skip to content

[Feature] Add Gemini 3.0 image generation with configurable sizes#638

Merged
dingyi222666 merged 6 commits into
v1-devfrom
feat/gemini-3-image
Nov 30, 2025
Merged

[Feature] Add Gemini 3.0 image generation with configurable sizes#638
dingyi222666 merged 6 commits into
v1-devfrom
feat/gemini-3-image

Conversation

@dingyi222666
Copy link
Copy Markdown
Member

This PR adds support for Gemini 3.0 image generation capabilities with configurable image sizes.

New Features

  • Add Gemini 3.0 Pro Image model support with size variants (1K, 2K, 4K)
  • Support configurable imageSize parameter via model name suffix (e.g., gemini-3.0-pro-image-2K)
  • Add imageConfig to generation configuration for controlling output image size
  • Add overrideRequestParams to ModelRequestParams for custom request parameters
  • Export deepAssign utility for deep object merging

Implementation Details

  • Model variants: gemini-3.0-pro-image, gemini-3.0-pro-image-2K, gemini-3.0-pro-image-4K
  • Image sizes follow Gemini API specification: 1K (default), 2K, 4K
  • Size extraction happens automatically from model name suffix

- Update image generation feature detection to support all image-capable models
- Broaden model compatibility check from specific model names to generic 'image' keyword
- Update documentation to reflect Gemini 3.0 Pro Image Preview support
- Bump package version to 1.3.8

This change makes the image generation feature more flexible and future-proof
by detecting any model with 'image' in its name, rather than maintaining a
hardcoded list of specific model versions.
…ration

This commit adds support for configurable image sizes (2K, 4K) in Gemini 3.0 image generation models.

Changes:
- adapter-gemini: Add model variants with -2K and -4K suffixes for gemini-3.0-pro-image
- adapter-gemini: Extract imageSize from model name in prepareModelConfig
- adapter-gemini: Add imageConfig to generationConfig when imageSize is specified
- core: Add overrideRequestParams to ModelRequestParams for custom request parameters
- core: Export deepAssign utility function for deep object merging
- shared-adapter: Apply overrideRequestParams in buildChatCompletionParams

The imageSize parameter follows Gemini API's ImageConfig specification, supporting 1K (default), 2K, and 4K image sizes.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Nov 30, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

为 Gemini 适配器添加对图像分辨率后缀(-2K / -4K)的模型变体生成与传递支持;在模型配置中解析并传递 imageSize;新增并导出递归合并工具 deepAssign;在模型请求参数接口中加入 overrideRequestParams,并在构建请求时深度合并覆盖参数。

Changes

Cohort / File(s) 变更摘要
Gemini 模型变体生成
packages/adapter-gemini/src/client.ts
GeminiClient.refreshModels 中新增 imageResolutionModel 分支;当模型名匹配图像类模型时,除了原始 info 外再生成带 -2K-4K 后缀的变体以表示高分辨率选项。
模型配置与生成配置
packages/adapter-gemini/src/utils.ts
prepareModelConfig 解析模型名后缀并新增 imageSize 字段(匹配 -2K/-4K,并从模型名中移除后缀);createGenerationConfig 引入 base 对象、在存在 imageSize 时加入 imageConfig,并改为使用深度合并(deepAssign)来合并覆盖参数。
请求参数合并点
packages/shared-adapter/src/requester.ts
buildChatCompletionParams 不再直接返回 base,而是通过 deepAssign({}, base, params.overrideRequestParams ?? {})overrideRequestParams 深度合并进最终请求参数。
公共工具与接口
packages/core/src/utils/object.ts, packages/core/src/llm-core/platform/api.ts
新增并导出 deepAssign 递归合并函数(支持多源重载与变参实现);在 ModelRequestParams 接口中新增可选字段 overrideRequestParams?: Record<string, any>(带文档注释)。
类构造器可见性调整
packages/adapter-gemini/src/requester.ts
GeminiRequester 构造函数的 _plugin 参数声明为 public 成员(暴露为类属性)。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

  • 重点审查 deepAssign 的递归实现与数组/非平凡对象边界(数组作为原始替换 vs 期望的合并行为)。
  • 校验 prepareModelConfig 中解析 -2K/-4K 的正则与在含其它后缀或复合模型名时的行为。
  • 验证 overrideRequestParamsdeepAssign 的合并顺序与优先级(覆盖规则、undefined/null 的处理)。
  • 检查 GeminiClient.refreshModels 中新增分支与现有 thinking-level 分支的顺序和互斥性,防止重复或遗漏变体生成。

Possibly related PRs

Poem

🐇 我在草丛里数名字的尾巴,
加上 -2K 与 -4K 更有斑斓,
deepAssign 把参数缝成被,
覆盖悄悄滑进请求里,
我咯咯跳,图像更清晰啦 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.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
Title check ✅ Passed PR标题准确反映了主要变更内容,即为Gemini 3.0添加支持可配置大小的图像生成功能。
Description check ✅ Passed PR描述详细说明了新增功能、实现细节及模型变体,与代码变更内容高度相关。
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/gemini-3-image

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.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @dingyi222666, 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 significantly enhances the Gemini adapter by integrating the latest Gemini 3.0 Pro Image model, providing users with advanced image generation features. It introduces a flexible mechanism to specify image resolutions directly through model names and allows for granular control over API request parameters, improving the adapter's versatility and alignment with the Gemini API's capabilities.

Highlights

  • Gemini 3.0 Image Generation: Adds support for the Gemini 3.0 Pro Image model, enabling image generation capabilities within the adapter.
  • Configurable Image Sizes: Introduces configurable image sizes (1K, 2K, 4K) for Gemini 3.0 image generation, which can be specified via model name suffixes (e.g., 'gemini-3.0-pro-image-2K').
  • Generation Configuration: Integrates 'imageConfig' into the generation configuration to control the output image size based on the selected model variant.
  • Request Parameter Overrides: Adds an 'overrideRequestParams' property to 'ModelRequestParams', allowing for custom request parameters to be applied dynamically.
  • Deep Assign Utility: Exports a new 'deepAssign' utility function for performing deep merges of objects, used internally for configuration and request parameter handling.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for Gemini 3.0 image generation with configurable sizes, which is a great addition. The implementation is well-structured, introducing model name suffixes for size configuration and adding overrideRequestParams for more flexible API calls. The new deepAssign utility is a good reusable component. I've found a potential issue in the deepAssign implementation regarding property iteration and a minor inconsistency in the updated documentation for image generation models. My detailed comments are below.

Comment thread packages/core/src/utils/object.ts
Comment thread packages/adapter-gemini/src/locales/en-US.schema.yml Outdated
Comment thread packages/adapter-gemini/src/locales/zh-CN.schema.yml Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/adapter-gemini/src/utils.ts (1)

380-380: 移除不必要的 undefined 初始化

TypeScript 中显式初始化为 undefined 是冗余的,因为未初始化的变量默认值就是 undefined

应用此修改:

-    let imageSize: string | undefined = undefined
+    let imageSize: string | undefined
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1e22f46 and 4f60e57.

⛔ Files ignored due to path filters (4)
  • packages/adapter-gemini/package.json is excluded by !**/*.json
  • packages/adapter-gemini/src/locales/en-US.schema.yml is excluded by !**/*.yml
  • packages/adapter-gemini/src/locales/zh-CN.schema.yml is excluded by !**/*.yml
  • packages/core/package.json is excluded by !**/*.json
📒 Files selected for processing (5)
  • packages/adapter-gemini/src/client.ts (2 hunks)
  • packages/adapter-gemini/src/utils.ts (6 hunks)
  • packages/core/src/llm-core/platform/api.ts (1 hunks)
  • packages/core/src/utils/object.ts (1 hunks)
  • packages/shared-adapter/src/requester.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
packages/adapter-gemini/src/client.ts (1)
packages/adapter-gemini/src/index.ts (1)
  • name (102-102)
packages/shared-adapter/src/requester.ts (1)
packages/core/src/utils/object.ts (1)
  • deepAssign (15-39)
packages/adapter-gemini/src/utils.ts (1)
packages/core/src/utils/object.ts (1)
  • deepAssign (15-39)
🪛 GitHub Check: CodeFactor
packages/adapter-gemini/src/utils.ts

[warning] 380-380: packages/adapter-gemini/src/utils.ts#L380
It's not necessary to initialize 'imageSize: string | undefined' to undefined. (no-undef-init)

🔇 Additional comments (7)
packages/core/src/llm-core/platform/api.ts (1)

72-77: 很好的扩展!

新增的 overrideRequestParams 字段为请求参数提供了灵活的覆盖机制,与下游的深度合并逻辑(如 packages/shared-adapter/src/requester.ts 中的使用)配合良好。

packages/adapter-gemini/src/client.ts (1)

79-117: 图像分辨率模型变体实现正确!

为包含 gemini-3.0-pro-image 的模型自动生成 -2K-4K 分辨率变体的逻辑清晰,与 utils.ts 中的 imageSize 提取逻辑(正则表达式 /-(2K|4K)$/)保持一致。原始模型作为 1K 默认分辨率。

packages/shared-adapter/src/requester.ts (2)

31-31: 导入正确!

引入 deepAssign 工具函数用于深度合并请求参数。


96-96: 深度合并实现正确!

使用 deepAssign({}, base, params.overrideRequestParams ?? {}) 创建新对象并合并覆盖参数,避免了对 base 对象的直接修改。合并顺序正确,允许 overrideRequestParams 深度覆盖基础配置。

packages/adapter-gemini/src/utils.ts (3)

33-33: 导入正确!

引入 deepAssign 工具函数用于深度合并生成配置参数。


411-416: 图像尺寸提取逻辑实现正确!

从模型名称后缀提取 imageSize(-2K-4K)的正则表达式逻辑清晰,与 client.ts 中生成的模型变体保持一致。


468-496: 生成配置构建逻辑正确!

使用 base 对象统一管理生成配置字段,当 imageSize 存在时正确添加 imageConfig 字段。Line 496 使用 deepAssign 深度合并 overrideRequestParams,模式与 requester.ts 一致。

Comment thread packages/core/src/utils/object.ts
Add hasOwnProperty check to deepAssign function to only process own enumerable properties and skip inherited properties from the prototype chain. This prevents potential security issues from prototype pollution and ensures the function behaves correctly when merging objects with custom prototypes.
Remove redundant '= undefined' initialization for imageSize variable as TypeScript variables are undefined by default when declared without initialization.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
packages/core/src/utils/object.ts (1)

14-41: deepAssign 实现整体正确,可考虑对 sources 做轻量健壮性增强

目前实现已经通过 hasOwnProperty 避免了原型链属性被误合并,递归合并普通对象的逻辑也符合预期。不过作为通用工具函数,如果未来某处误传入 null / undefined 作为 source,for (const key in src) 会直接抛异常。

可以在遍历前做一次空值过滤,提升健壮性且不改变现有调用行为,例如:

 export function deepAssign(target: any, ...sources: any[]): any {
-    for (const src of sources) {
+    for (const src of sources) {
+        if (src == null) continue
         for (const key in src) {
             if (!Object.prototype.hasOwnProperty.call(src, key)) {
                 continue
             }
             // ...
         }
     }
     return target
 }
packages/adapter-gemini/src/utils.ts (1)

396-432: imageSize 解析与 overrideRequestParams 深度合并逻辑合理,类型上有小幅优化空间

  • 从模型后缀 -2K / -4K 中提取 imageSize,并将模型名规整为无尺寸后缀再下发给后端,这条链路是连贯的;createGenerationConfig 中通过 imageConfig: modelConfig.imageSize ? { imageSize: ... } : undefined 也能按需生成配置。
  • deepAssign({}, base, params.overrideRequestParams ?? {})overrideRequestParams 只覆盖需要改写的字段,同时避免修改 base / 原始 override 对象,本身设计不错。

有两点可以酌情优化:

  1. 类型收紧 imageSize
    目前声明为 let imageSize: string | undefined,但实际只可能是 '2K' | '4K'。如果希望在调用端获得更强的类型检查,可以改为:

  • let imageSize: string | undefined
  • let imageSize: '2K' | '4K' | undefined

2. **`imageConfig` 与 `imageGeneration` 的关系**(可选)  
当前只要解析到 `imageSize` 就会下发 `imageConfig`,即使 `modelConfig.imageGeneration` 为 `false`。如果你希望“仅当开启 imageGeneration 时才发送 imageConfig”,可以考虑将这两个条件结合起来,例如:

```diff
-        imageConfig: modelConfig.imageSize
+        imageConfig:
+            modelConfig.imageGeneration && modelConfig.imageSize
          ? { imageSize: modelConfig.imageSize }
          : undefined,

上述两点都不影响现有功能,仅作为类型与配置语义上的可选改进。

Also applies to: 447-449, 484-513

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 85998bb and a34ddde.

📒 Files selected for processing (2)
  • packages/adapter-gemini/src/utils.ts (7 hunks)
  • packages/core/src/utils/object.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/adapter-gemini/src/utils.ts (1)
packages/core/src/utils/object.ts (1)
  • deepAssign (15-43)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: lint
  • GitHub Check: build

Comment thread packages/adapter-gemini/src/utils.ts Outdated
Changes:
- Make _plugin property public in GeminiRequester for better accessibility
- Remove unused filterKeys import from utils.ts to reduce dependencies
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

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 (2)
packages/adapter-gemini/src/requester.ts (1)

54-61: _plugin 改为 public 的选择看起来合理,但可考虑设为只读

_plugin 声明为 public 只改变了类型可见性,运行时行为不变,也便于外部访问 GeminiRequester 所持有的插件实例,这里整体是 OK 的。为了避免后续在外部或本类中误改引用,可以考虑进一步改为只读属性:

-        public _plugin: ChatLunaPlugin<ClientConfig, Config>
+        public readonly _plugin: ChatLunaPlugin<ClientConfig, Config>
packages/adapter-gemini/src/utils.ts (1)

388-448: 模型名后缀解析 imageSize 的实现基本符合需求,可收紧类型

  • 使用 /-(2K|4K)$/ 从模型名末尾提取尺寸后缀并同步从 model 中移除,能很好地支持 gemini-3.0-pro-image-2K/4K 这类本地变体,同时对外实际请求的 model 仍为基础模型名。
  • 未匹配到后缀时不设置 imageSize,由“1K 为默认尺寸”的行为接管,也符合本 PR 描述。

可以考虑将 imageSize 的类型从 string | undefined 收紧为字面量联合,例如:

type ImageSize = '2K' | '4K'
let imageSize: ImageSize | undefined

这样后续使用时有更强的类型约束,并避免误传入无效字符串。

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a34ddde and 2c46e7a.

📒 Files selected for processing (2)
  • packages/adapter-gemini/src/requester.ts (1 hunks)
  • packages/adapter-gemini/src/utils.ts (7 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
packages/adapter-gemini/src/requester.ts (1)
packages/core/src/services/chat.ts (1)
  • ChatLunaPlugin (594-800)
packages/adapter-gemini/src/utils.ts (1)
packages/core/src/utils/object.ts (1)
  • deepAssign (15-43)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: lint
  • GitHub Check: build
🔇 Additional comments (2)
packages/adapter-gemini/src/utils.ts (2)

34-34: deepAssign 引入与使用合理

deepAssign 仅在 createGenerationConfig 中使用,通过 deepAssign({}, base, params.overrideRequestParams ?? {}) 深度合并默认配置与覆盖参数且不污染入参引用,实现方式符合预期。


478-512: generationConfig 组装与 overrideRequestParams 合并逻辑清晰

  • 在局部 base 中集中构造 stopSequencestemperaturemaxOutputTokensresponseModalities 等默认配置,并在 modelConfig.imageSize 存在时才生成 imageConfig,避免对默认 1K 尺寸发送多余字段。
  • 最终通过 deepAssign({}, base, params.overrideRequestParams ?? {}) 深度合并,保证调用方在 overrideRequestParams 中配置的字段(包括嵌套的 imageConfig / thinkingConfig)能覆盖默认值,同时不修改原始参数对象,整体设计符合“可覆盖默认请求参数”的目标。

@dingyi222666 dingyi222666 merged commit ad2c19f into v1-dev Nov 30, 2025
3 of 5 checks passed
@dingyi222666 dingyi222666 deleted the feat/gemini-3-image branch November 30, 2025 22:07
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.

1 participant