Refactor: Extract model variant expansion and optimize tool handling in adapter-gemini#744
Conversation
…e tool handling - Extract model variant expansion logic into reusable utility functions (expandModelVariants, pushImageVariants, etc.) for better code organization and maintainability - Add support for image generation models with resolution and search suffix variants (-2k, -4k, -0.5k, -search) - Implement imageModelSearch config option to enable search functionality for image generation models, generating -search variant suffixes - Extract tool configuration logic from formatToolsToGeminiAITools into appendBuiltinTools helper function for cleaner separation of concerns - Add model support lists (CUSTOM_TOOLS_UNSUPPORTED_MODELS, IMAGE_GENERATION_MODELS, IMAGE_SEARCH_SUPPORTED_MODELS) as module-level constants for better maintainability - Enhance model config parsing to handle -search suffix for forcing Google search on image generation models - Fix regex pattern for thinking level detection to support gemini-3.1-pro family models - Fix image size extraction regex to support additional resolution formats (0.5k) with case-insensitive matching - Add forceGoogleSearch flag to model config to enable search on image models when -search suffix is present - Update safety settings to use modelConfig.model instead of params.model for consistency - Add comprehensive JSDoc comments documenting model variant expansion rules - Add code regions (#region / #endregion) for better code navigation in GeminiClient - Update English and Chinese locales with imageModelSearch configuration description
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
Walkthrough此PR为Gemini适配器引入了集中化的模型变体扩展机制,通过新增 Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
Summary of ChangesHello @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 enhances the Gemini adapter by improving its internal architecture and expanding its capabilities. The primary goal was to centralize and streamline the complex logic involved in generating various model configurations and managing tool integrations. This refactoring leads to a more modular, maintainable, and extensible codebase, particularly for handling diverse Gemini model variants and their associated features like image search. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
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. 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
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9ce4308da5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Code Review
This pull request introduces a significant refactoring of the Gemini adapter, primarily by extracting the logic for model variant expansion and tool handling into utility functions. This greatly improves code organization, readability, and maintainability. The changes also include enhancements like support for new model variants (e.g., gemini-3.1-pro, gemini-3.1-flash-image) and a new -search suffix to force Google Search. The overall changes are well-executed and represent a solid improvement to the codebase. I have a couple of suggestions for minor improvements to further enhance code clarity and reduce duplication.
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
packages/adapter-gemini/src/utils.ts (1)
394-399: 禁用分支日志与实际行为不一致该分支同时关闭了
googleSearch、codeExecution、urlContext,但日志只提示了 google search,建议同步文案,避免误导排障。🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/adapter-gemini/src/utils.ts` around lines 394 - 399, The warning message in logger.warn is misleading because the branch disables googleSearch, codeExecution, and urlContext but only mentions google search; update the logger.warn call (referencing logger.warn and the model variable) to clearly list all disabled features (googleSearch, codeExecution, urlContext) or alternatively change the assignments to only disable googleSearch if that was intended; ensure the log text and the boolean assignments (googleSearch, codeExecution, urlContext) remain consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/adapter-gemini/src/client.ts`:
- Around line 100-103: refreshModels calls expandModelVariants(models, baseInfo)
but doesn't pass the imageModelSearch flag, so "-search" variants are always
generated; update the call in refreshModels to pass the config (e.g.,
expandModelVariants(models, baseInfo, imageModelSearch)) and adjust
expandModelVariants' signature/implementation to accept and honor that third
boolean parameter (imageModelSearch) so variant generation respects the flag;
ensure all other call sites of expandModelVariants are updated accordingly or
given a default to preserve backward compatibility.
In `@packages/adapter-gemini/src/utils.ts`:
- Around line 369-371: The early return checks only "tools.length < 1 &&
!config.googleSearch" which wrongly skips built-in tools when other flags like
codeExecution or urlContext are enabled; update the condition around the "return
undefined" to only return when tools is empty AND none of the built-in feature
flags are enabled (e.g. config.googleSearch, config.codeExecution,
config.urlContext — include any other built-in flags present), so that if any
built-in (codeExecution, urlContext, googleSearch, etc.) is enabled the code
continues to register and emit built-in tools.
---
Nitpick comments:
In `@packages/adapter-gemini/src/utils.ts`:
- Around line 394-399: The warning message in logger.warn is misleading because
the branch disables googleSearch, codeExecution, and urlContext but only
mentions google search; update the logger.warn call (referencing logger.warn and
the model variable) to clearly list all disabled features (googleSearch,
codeExecution, urlContext) or alternatively change the assignments to only
disable googleSearch if that was intended; ensure the log text and the boolean
assignments (googleSearch, codeExecution, urlContext) remain consistent.
ℹ️ Review info
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (3)
packages/adapter-gemini/package.jsonis excluded by!**/*.jsonpackages/adapter-gemini/src/locales/en-US.schema.ymlis excluded by!**/*.ymlpackages/adapter-gemini/src/locales/zh-CN.schema.ymlis excluded by!**/*.yml
📒 Files selected for processing (3)
packages/adapter-gemini/src/client.tspackages/adapter-gemini/src/index.tspackages/adapter-gemini/src/utils.ts
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…nt expansion - Pass imageModelSearch config to expandModelVariants for image model handling - Update pushImageVariants to conditionally generate -search suffixes based on imageModelSearch flag - Enhance formatToolsToGeminiAITools validation to check codeExecution and urlContext configs - Improve documentation comments for image variant generation and model expansion logic
Summary
This PR refactors the Gemini adapter to improve code organization and maintainability by extracting model variant expansion logic and optimizing tool handling mechanisms.
New Features
Bug fixes
None
Other Changes
packages/adapter-gemini/src/client.tswith improved structurepackages/adapter-gemini/src/utils.tswith new helper utilities