feat(adapter-gemini): 支持手动配置模型列表#911
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the ability to configure whether to automatically pull models via pullModels and allows defining additionalModels manually in the Gemini adapter. Feedback on these changes highlights potential runtime errors and backward compatibility issues: pullModels could be undefined in existing configurations (which would unexpectedly disable model pulling), and additionalModels could also be undefined, leading to TypeError crashes during iteration or lookup. Additionally, it is recommended to use English constants (e.g., 'embeddings') instead of hardcoded Chinese strings for modelType to improve internationalization and code robustness.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
Warning Review limit reached
More reviews will be available in 6 minutes and 51 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, 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 include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (2)
📒 Files selected for processing (3)
Walkthrough扩展 Gemini 适配器配置(新增 pullModels 与 additionalModels),prepareModelConfig 增加 additionalModels 的早退匹配,并在 GeminiClient.refreshModels 中重构模型映射、变体追加与同名去重逻辑;同时移除若干旧的变体展开/判断导出。 变更内容Gemini 模型配置与初始化
🎯 4 (Complex) | ⏱️ ~40 分钟 可能相关的 PR(最多 3 个):
建议审查人:
概述(更新)该 PR 为 Gemini 适配器扩展模型配置能力,新增可选的额外模型表与条件性远程拉取开关,统一重构模型初始化中的变体展开与去重流程。 变更内容(已更新)Gemini 模型配置与初始化
相关 PR(更新)
建议审查人(更新)
诗
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
|
我想知道为什么要在 gemini 适配器里用其他非 gemini 模型或者手动加,如果拉不到模型,直接默认内置一些模型更好而不是还需要手动填 |
|
如果无法解释这个 pr 我将关闭 |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/adapter-gemini/src/client.ts`:
- Line 206: 返回 models 时没有对空模型集做校验,当 pullModels 为 false 且 additionalModels
为空会导致返回空数组并“静默成功”;在返回前(在 packages/adapter-gemini/src/client.ts 中处理模型集合的函数,返回
models 的位置)加入校验:如果 models.length === 0 且 pullModels === false(或 additionalModels
为空/未提供),不要返回空数组,而是抛出一个明确的错误(例如抛出或返回带有标识码 MODEL_INIT_ERROR
的异常/错误对象),以便尽早暴露配置问题并阻止下游缓存空模型列表。确保使用现有错误类型/工厂或统一错误格式与项目风格一致。
In `@packages/adapter-gemini/src/utils.ts`:
- Around line 770-772: The current isGeminiModelName function is too permissive
(uses includes('gemini')) and misclassifies non-standard names; update
isGeminiModelName to validate against the standard Gemini request name pattern
(e.g. case-insensitive match for names that start with "gemini" followed by
end-of-string or a delimiter like '-' or ':' — or check against an explicit
allowlist of known Gemini model IDs) so it only returns true for real Gemini
request names; then ensure callers such as prepareModelConfig use the updated
isGeminiModelName to drive Gemini-specific branches and manual capability
priority.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 5c9d0026-5b23-46bf-9519-304e04afbdef
⛔ Files ignored due to path filters (2)
packages/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
这里的非 Gemini 模型名不是想让适配器请求其他格式的模型,而是为了支持一些 Gemini 格式上游暴露的自定义模型 ID。 比如我上游提供 手动添加也是为了避免拉上游一大坨模型列表下来 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/adapter-gemini/src/client.ts (1)
182-182: 💤 Low value去重逻辑区分大小写,可能导致意外重复。
当前使用
model.name原始大小写进行去重。如果用户在additionalModels中配置Gemini-2.5-Flash,而 API 返回gemini-2.5-flash,两者会被视为不同模型,导致列表中出现重复。建议改用小写进行去重:
♻️ 建议修改
const models: ModelInfo[] = [] -const names = new Set<string>() +const names = new Set<string>() for (const model of items) { const name = model.name.toLowerCase() const suffixes: string[] = [] // ...suffix generation... for (const suffix of suffixes) { const full = model.name + suffix - if (!names.has(full)) { - names.add(full) + if (!names.has(full.toLowerCase())) { + names.add(full.toLowerCase()) models.push({ ...model, name: full }) } } - if (names.has(model.name)) continue + if (names.has(name)) continue - names.add(model.name) + names.add(name) models.push(model) }Also applies to: 224-224, 230-230, 232-232
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/adapter-gemini/src/client.ts` at line 182, The deduplication currently uses the raw model.name (via the names Set) which is case-sensitive and can produce duplicates like "Gemini-2.5-Flash" vs "gemini-2.5-flash"; update all checks and inserts into the names Set to use a normalized form (e.g., model.name.toLowerCase()) so comparisons are case-insensitive—apply this change wherever names is read/updated (references around the names variable and uses of model.name at lines noted).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/adapter-gemini/src/utils.ts`:
- Around line 547-553: The current check uses
item.model.toLowerCase().includes('gemini') which is too broad and misclassifies
custom models; update the predicate in pluginConfig.additionalModels.some to use
a strict case-insensitive prefix match (e.g.,
item.model.toLowerCase().startsWith('gemini-')) when comparing against model
(and apply the same stricter check in client.ts refreshModels where
name.includes('gemini') is used) so only standard Gemini model names with the
"gemini-" prefix trigger Gemini-specific parsing.
---
Nitpick comments:
In `@packages/adapter-gemini/src/client.ts`:
- Line 182: The deduplication currently uses the raw model.name (via the names
Set) which is case-sensitive and can produce duplicates like "Gemini-2.5-Flash"
vs "gemini-2.5-flash"; update all checks and inserts into the names Set to use a
normalized form (e.g., model.name.toLowerCase()) so comparisons are
case-insensitive—apply this change wherever names is read/updated (references
around the names variable and uses of model.name at lines noted).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: e37ff15e-c6af-4817-aff1-5d1553f989ec
📒 Files selected for processing (2)
packages/adapter-gemini/src/client.tspackages/adapter-gemini/src/utils.ts
f514796 to
3f84e75
Compare
Summary
pullModels和additionalModels配置。