-
Notifications
You must be signed in to change notification settings - Fork 516
feat: add GoogleSearch support for Gemini provider #889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughAdds explicit enableSearch: false to several Gemini model entries; introduces a Gemini internet-search toggle and thinkingBudget validation in the ModelConfig dialog; and refactors the Gemini provider to use GenerateContentConfig, streaming generateContentStream, tool integration, and mapped safety settings. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant UI as ModelConfigDialog
participant Presenter as ConfigPresenter
participant Provider as GeminiProvider
participant GenAI as Google GenAI API
rect rgba(230,240,255,0.5)
User->>UI: Open model settings
UI->>Presenter: Load model config
UI-->>User: Show enableSearch (Gemini only)
User->>UI: Toggle enableSearch / set thinkingBudget
UI->>Presenter: Save updated config (enableSearch, thinkingBudget)
end
rect rgba(240,255,240,0.5)
User->>Provider: Send messages
Provider->>Provider: getGenerateContentConfig(messages, modelConfig)
alt enableSearch = true
Provider->>Provider: Add GoogleSearch tool
else enableSearch = false
Provider->>Provider: Convert MCP tools -> Gemini tools
end
Provider->>Provider: Map safety settings -> HarmBlockThreshold/Category
Provider->>GenAI: generateContentStream(model, contents, config)
loop Stream
GenAI-->>Provider: text/reasoning/toolCall/image/usage chunks
Provider-->>User: Emit chunk events
end
GenAI-->>Provider: done
Provider-->>User: stop
end
sequenceDiagram
autonumber
actor User
participant Provider as GeminiProvider
participant GenAI as Google GenAI API
Note over User,Provider: Image generation path
User->>Provider: Prompt with image generation intent
Provider->>Provider: Validate user content for image gen
Provider->>GenAI: generateContentStream(..., config)
loop Stream
GenAI-->>Provider: text chunk / image data
Provider-->>User: Emit text/imageData events
end
Provider-->>User: stop
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
Pre-merge checks (2 passed, 1 warning)❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Poem
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal). Please share your feedback with us on this Discord post. 📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing touches🧪 Generate unit tests
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/presenter/llmProviderPresenter/providers/geminiProvider.ts (1)
376-383
: Bug: comparing enum to string in safety settings filterthreshold is a HarmBlockThreshold enum, but compared to string literals; the condition is never as intended. Compare against enum members and don’t rely on truthiness.
- // Only add if threshold is defined, category is defined, and threshold is not BLOCK_NONE - if ( - threshold && - category && - threshold !== 'BLOCK_NONE' && - threshold !== 'HARM_BLOCK_THRESHOLD_UNSPECIFIED' - ) { - safetySettings.push({ category, threshold }) - } + // Only add if category is defined and threshold is not NONE/UNSPECIFIED + if ( + category !== undefined && + threshold !== undefined && + threshold !== null && + threshold !== HarmBlockThreshold.BLOCK_NONE && + threshold !== HarmBlockThreshold.HARM_BLOCK_THRESHOLD_UNSPECIFIED + ) { + safetySettings.push({ category, threshold }) + }
🧹 Nitpick comments (6)
src/renderer/src/components/settings/ModelConfigDialog.vue (2)
275-286
: Add capability gating for Gemini search toggleAvoid showing the toggle on unsupported/image models. Gate by model type and functionCall.
- <div v-if="showGeminiSearch" class="space-y-4"> + <div v-if="showGeminiSearch" class="space-y-4">And update the computed below (see next comment).
456-489
: Use English for new/changed commentsNew comments in this PR are in Chinese. Repo guideline: logs/comments in English. Please convert newly added comments to English (existing legacy comments can be cleaned up separately).
Also applies to: 508-523
src/main/presenter/llmProviderPresenter/providers/geminiProvider.ts (4)
298-306
: Use a known-available model in provider check()models/gemini-1.5-flash-8b may not exist in all accounts/regions. Use a static known ID or the first recommended model to reduce false negatives.
- const result = await this.genAI.models.generateContent({ - model: 'models/gemini-1.5-flash-8b', + const result = await this.genAI.models.generateContent({ + model: GeminiProvider.GEMINI_MODELS[0].id, contents: [{ role: 'user', parts: [{ text: 'Hello' }] }] })
943-943
: Downgrade verbose logs or guard behind DEBUGDumping entire request/response candidates is noisy and may leak context. Wrap with a debug guard.
- console.log('requestParams', requestParams) + if (process.env.LOG_LEVEL === 'DEBUG') console.debug('requestParams', requestParams)- console.log('chunk.candidates', JSON.stringify(chunk.candidates, null, 2)) + if (process.env.LOG_LEVEL === 'DEBUG') { + console.debug('chunk.candidates', JSON.stringify(chunk.candidates, null, 2)) + }Also applies to: 962-962
512-535
: Tool response mapping likely incorrect for GeminiWhen handling tool messages (function_response), you’re pushing a text part. Gemini expects a functionResponse part with name + structured response. This can hurt follow-up turns.
Example adjustment inside the tool branch:
- build parts.push({ functionResponse: { name, response: {...} } })
- keep user role for functionResponse as you already do elsewhere.
I can propose a concrete patch if you share the exact tool message shape emitted upstream.
964-981
: Tool call event ID generationUsing Date.now() risks collisions and makes correlating multiple calls harder. Prefer a monotonic counter or include function name + index.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/main/presenter/configPresenter/providerModelSettings.ts
(8 hunks)src/main/presenter/llmProviderPresenter/providers/geminiProvider.ts
(9 hunks)src/renderer/src/components/settings/ModelConfigDialog.vue
(2 hunks)
🧰 Additional context used
📓 Path-based instructions (17)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development-setup.mdc)
**/*.{js,jsx,ts,tsx}
: 使用 OxLint 进行代码检查
Log和注释使用英文书写
Files:
src/main/presenter/configPresenter/providerModelSettings.ts
src/main/presenter/llmProviderPresenter/providers/geminiProvider.ts
src/{main,renderer}/**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/electron-best-practices.mdc)
src/{main,renderer}/**/*.ts
: Use context isolation for improved security
Implement proper inter-process communication (IPC) patterns
Optimize application startup time with lazy loading
Implement proper error handling and logging for debugging
Files:
src/main/presenter/configPresenter/providerModelSettings.ts
src/main/presenter/llmProviderPresenter/providers/geminiProvider.ts
src/main/**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/electron-best-practices.mdc)
Use Electron's built-in APIs for file system and native dialogs
Files:
src/main/presenter/configPresenter/providerModelSettings.ts
src/main/presenter/llmProviderPresenter/providers/geminiProvider.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/error-logging.mdc)
**/*.{ts,tsx}
: 始终使用 try-catch 处理可能的错误
提供有意义的错误信息
记录详细的错误日志
优雅降级处理
日志应包含时间戳、日志级别、错误代码、错误描述、堆栈跟踪(如适用)、相关上下文信息
日志级别应包括 ERROR、WARN、INFO、DEBUG
不要吞掉错误
提供用户友好的错误信息
实现错误重试机制
避免记录敏感信息
使用结构化日志
设置适当的日志级别
Files:
src/main/presenter/configPresenter/providerModelSettings.ts
src/main/presenter/llmProviderPresenter/providers/geminiProvider.ts
src/main/**/*.{ts,js,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)
主进程代码放在
src/main
Files:
src/main/presenter/configPresenter/providerModelSettings.ts
src/main/presenter/llmProviderPresenter/providers/geminiProvider.ts
**/*.{ts,tsx,js,vue}
📄 CodeRabbit inference engine (CLAUDE.md)
Use English for all logs and comments
Files:
src/main/presenter/configPresenter/providerModelSettings.ts
src/renderer/src/components/settings/ModelConfigDialog.vue
src/main/presenter/llmProviderPresenter/providers/geminiProvider.ts
**/*.{ts,tsx,vue}
📄 CodeRabbit inference engine (CLAUDE.md)
Enable and adhere to strict TypeScript typing (avoid implicit any, prefer precise types)
Files:
src/main/presenter/configPresenter/providerModelSettings.ts
src/renderer/src/components/settings/ModelConfigDialog.vue
src/main/presenter/llmProviderPresenter/providers/geminiProvider.ts
src/renderer/src/**/*
📄 CodeRabbit inference engine (.cursor/rules/i18n.mdc)
src/renderer/src/**/*
: All user-facing strings must use i18n keys (avoid hardcoded user-visible text in code)
Use the 'vue-i18n' framework for all internationalization in the renderer
Ensure all user-visible text in the renderer uses the translation system
Files:
src/renderer/src/components/settings/ModelConfigDialog.vue
src/renderer/**/*.{vue,ts,js,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)
渲染进程代码放在
src/renderer
Files:
src/renderer/src/components/settings/ModelConfigDialog.vue
src/renderer/src/**/*.{vue,ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/vue-best-practices.mdc)
src/renderer/src/**/*.{vue,ts,tsx,js,jsx}
: Use the Composition API for better code organization and reusability
Implement proper state management with Pinia
Utilize Vue Router for navigation and route management
Leverage Vue's built-in reactivity system for efficient data handling
Files:
src/renderer/src/components/settings/ModelConfigDialog.vue
src/renderer/src/**/*.vue
📄 CodeRabbit inference engine (.cursor/rules/vue-best-practices.mdc)
Use scoped styles to prevent CSS conflicts between components
Files:
src/renderer/src/components/settings/ModelConfigDialog.vue
src/renderer/**/*.{ts,tsx,vue}
📄 CodeRabbit inference engine (.cursor/rules/vue-shadcn.mdc)
src/renderer/**/*.{ts,tsx,vue}
: Use descriptive variable names with auxiliary verbs (e.g., isLoading, hasError).
Use TypeScript for all code; prefer types over interfaces.
Avoid enums; use const objects instead.
Use arrow functions for methods and computed properties.
Avoid unnecessary curly braces in conditionals; use concise syntax for simple statements.
Files:
src/renderer/src/components/settings/ModelConfigDialog.vue
src/renderer/**/*.{vue,ts}
📄 CodeRabbit inference engine (.cursor/rules/vue-shadcn.mdc)
Implement lazy loading for routes and components.
Files:
src/renderer/src/components/settings/ModelConfigDialog.vue
src/renderer/**/*.{ts,vue}
📄 CodeRabbit inference engine (.cursor/rules/vue-shadcn.mdc)
src/renderer/**/*.{ts,vue}
: Use useFetch and useAsyncData for data fetching.
Implement SEO best practices using Nuxt's useHead and useSeoMeta.Use Pinia for frontend state management (do not introduce alternative state libraries)
Files:
src/renderer/src/components/settings/ModelConfigDialog.vue
src/renderer/{src,shell,floating}/**/*.vue
📄 CodeRabbit inference engine (CLAUDE.md)
src/renderer/{src,shell,floating}/**/*.vue
: Use Vue 3 Composition API for all components
All user-facing strings must use i18n keys via vue-i18n (no hard-coded UI strings)
Use Tailwind CSS utilities and ensure styles are scoped in Vue components
Files:
src/renderer/src/components/settings/ModelConfigDialog.vue
src/renderer/src/components/**/*
📄 CodeRabbit inference engine (CLAUDE.md)
Organize UI components by feature within src/renderer/src/
Files:
src/renderer/src/components/settings/ModelConfigDialog.vue
src/main/presenter/llmProviderPresenter/providers/*.ts
📄 CodeRabbit inference engine (.cursor/rules/llm-agent-loop.mdc)
src/main/presenter/llmProviderPresenter/providers/*.ts
: Each file insrc/main/presenter/llmProviderPresenter/providers/*.ts
should handle interaction with a specific LLM API, including request/response formatting, tool definition conversion, native/non-native tool call management, and standardizing output streams to a common event format.
Provider implementations must use acoreStream
method that yields standardized stream events to decouple the main loop from provider-specific details.
ThecoreStream
method in each Provider must perform a single streaming API request per conversation round and must not contain multi-round tool call loop logic.
Provider files should implement helper methods such asformatMessages
,convertToProviderTools
,parseFunctionCalls
, andprepareFunctionCallPrompt
as needed for provider-specific logic.
All provider implementations must parse provider-specific data chunks and yield standardized events for text, reasoning, tool calls, usage, errors, stop reasons, and image data.
When a provider does not support native function calling, it must prepare messages using prompt wrapping (e.g.,prepareFunctionCallPrompt
) before making the API call.
When a provider supports native function calling, MCP tools must be converted to the provider's format (e.g., usingconvertToProviderTools
) and included in the API request.
Provider implementations should aggregate and yield usage events as part of the standardized stream.
Provider implementations should yield image data events in the standardized format when applicable.
Provider implementations should yield reasoning events in the standardized format when applicable.
Provider implementations should yield tool call events (tool_call_start
,tool_call_chunk
,tool_call_end
) in the standardized format.
Provider implementations should yield stop events with appropriatestop_reason
in the standardized format.
Provider implementations should yield error events in the standardized format...
Files:
src/main/presenter/llmProviderPresenter/providers/geminiProvider.ts
🧠 Learnings (2)
📓 Common learnings
Learnt from: neoragex2002
PR: ThinkInAIXYZ/deepchat#550
File: src/main/presenter/mcpPresenter/inMemoryServers/meetingServer.ts:258-324
Timestamp: 2025-06-21T15:53:34.641Z
Learning: User neoragex2002 prefers concise, brief responses rather than chatty or verbose communication. Avoid lengthy explanations, excessive enthusiasm, or ASCII art in responses.
📚 Learning: 2025-09-06T03:07:23.817Z
Learnt from: CR
PR: ThinkInAIXYZ/deepchat#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-06T03:07:23.817Z
Learning: Applies to src/main/presenter/configPresenter/providers.ts : Add provider configuration entries in src/main/presenter/configPresenter/providers.ts
Applied to files:
src/main/presenter/configPresenter/providerModelSettings.ts
🧬 Code graph analysis (1)
src/main/presenter/llmProviderPresenter/providers/geminiProvider.ts (2)
src/shared/types/presenters/legacy.presenters.d.ts (1)
Tool
(108-119)src/main/presenter/index.ts (1)
presenter
(223-223)
🔇 Additional comments (2)
src/main/presenter/configPresenter/providerModelSettings.ts (1)
310-312
: Explicit Gemini enableSearch defaults added — LGTMSetting enableSearch: false explicitly is consistent with getProviderSpecificModelConfig and prevents accidental tool attachment. No issues spotted across these blocks.
Also applies to: 334-336, 346-348, 358-360, 385-387, 397-399, 409-411, 421-423
src/main/presenter/llmProviderPresenter/providers/geminiProvider.ts (1)
895-905
: Google Search tool shape is correct — use camelCase{ googleSearch: {} }
Confirmed the @google/genai Node SDK expects
{ googleSearch: {} }
; the current code already uses that shape ({ googleSearch: {} as GoogleSearch }
), so no change required.
// 是否显示Gemini搜索配置 | ||
const showGeminiSearch = computed(() => { | ||
const isGemini = props.providerId === 'gemini' | ||
const modelId = props.modelId.toLowerCase() | ||
const supportedSearchModels = [ | ||
'gemini-2.5-pro', | ||
'gemini-2.5-flash', | ||
'gemini-2.5-flash-lite', | ||
'gemini-2.5-flash-lite-preview-06-17', | ||
'gemini-2.0-flash', | ||
'gemini-2.0-flash-lite', | ||
'gemini-1.5-pro', | ||
'gemini-1.5-flash' | ||
] | ||
const isSupported = | ||
supportedSearchModels.some((supportedModel) => modelId.includes(supportedModel)) || | ||
modelId.includes('gemini') | ||
return isGemini && isSupported | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Tighten showGeminiSearch conditions (remove broad .includes('gemini'))
Limit to known chat models and require functionCall to reduce UX confusion.
-// 是否显示Gemini搜索配置
-const showGeminiSearch = computed(() => {
- const isGemini = props.providerId === 'gemini'
- const modelId = props.modelId.toLowerCase()
- const supportedSearchModels = [
+// Show Gemini search config only for supported chat models
+const showGeminiSearch = computed(() => {
+ if (props.providerId !== 'gemini') return false
+ const modelId = props.modelId.toLowerCase()
+ const supportedSearchModels = [
'gemini-2.5-pro',
'gemini-2.5-flash',
'gemini-2.5-flash-lite',
'gemini-2.5-flash-lite-preview-06-17',
- 'gemini-2.0-flash',
- 'gemini-2.0-flash-lite',
- 'gemini-1.5-pro',
+ 'gemini-2.0-flash',
+ 'gemini-2.0-flash-lite',
+ 'gemini-1.5-pro',
'gemini-1.5-flash'
]
- const isSupported =
- supportedSearchModels.some((supportedModel) => modelId.includes(supportedModel)) ||
- modelId.includes('gemini')
- return isGemini && isSupported
+ const isSupported = supportedSearchModels.some((m) => modelId.includes(m))
+ // Only for chat models that can call tools
+ return (
+ isSupported &&
+ config.value.type === ModelType.Chat &&
+ config.value.functionCall === true
+ )
})
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
// 是否显示Gemini搜索配置 | |
const showGeminiSearch = computed(() => { | |
const isGemini = props.providerId === 'gemini' | |
const modelId = props.modelId.toLowerCase() | |
const supportedSearchModels = [ | |
'gemini-2.5-pro', | |
'gemini-2.5-flash', | |
'gemini-2.5-flash-lite', | |
'gemini-2.5-flash-lite-preview-06-17', | |
'gemini-2.0-flash', | |
'gemini-2.0-flash-lite', | |
'gemini-1.5-pro', | |
'gemini-1.5-flash' | |
] | |
const isSupported = | |
supportedSearchModels.some((supportedModel) => modelId.includes(supportedModel)) || | |
modelId.includes('gemini') | |
return isGemini && isSupported | |
}) | |
// Show Gemini search config only for supported chat models | |
const showGeminiSearch = computed(() => { | |
if (props.providerId !== 'gemini') return false | |
const modelId = props.modelId.toLowerCase() | |
const supportedSearchModels = [ | |
'gemini-2.5-pro', | |
'gemini-2.5-flash', | |
'gemini-2.5-flash-lite', | |
'gemini-2.5-flash-lite-preview-06-17', | |
'gemini-2.0-flash', | |
'gemini-2.0-flash-lite', | |
'gemini-1.5-pro', | |
'gemini-1.5-flash' | |
] | |
const isSupported = supportedSearchModels.some((m) => modelId.includes(m)) | |
// Only for chat models that can call tools | |
return ( | |
isSupported && | |
config.value.type === ModelType.Chat && | |
config.value.functionCall === true | |
) | |
}) |
feat: add GoogleSearch support for Gemini provider
Summary by CodeRabbit
New Features
Refactor