-
Notifications
You must be signed in to change notification settings - Fork 3
Add Support for Google Gemini API #46
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
- Install @google/genai v1.28.0 package - Add gemini option to aiServiceProvider enum - Add geminiApiKey configuration setting with link to Google AI Studio - Add geminiModel configuration setting with default gemini-2.0-flash-exp - Include documentation for popular Gemini models
- Create GeminiService class implementing AIService interface - Add getCommitMessageFromDiff() method for generating commit messages - Add getExplainedChanges() method for explaining code changes - Implement caching support for API responses - Add comprehensive error handling with user-friendly messages - Follow same pattern as OpenAiService for consistency
- Add getGeminiKey() method to retrieve and validate Gemini API key - Add getGeminiModel() method to retrieve selected Gemini model - Include error messages for missing API key with link to Google AI Studio
- Import and add GeminiService instance management - Add getGeminiService() method - Update getAIService() to support gemini provider - Update all methods to handle Gemini API: * explainAndPreview() * explainDiffToClipboard() * generateCommitMessageToClipboard() * generateCommitMessageToSCM() - Add Gemini API key validation - Add cleanup for Gemini service in dispose() method
Hi7cl4w
left a 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.
Summary
This PR adds support for Google Gemini API as an alternative AI provider to the existing OpenAI integration. The implementation follows the same pattern as the OpenAiService and integrates seamlessly with the existing extension architecture.
Changes
🔧 Dependencies
- Added
@google/genaiv1.28.0 package for Google Gemini API integration
⚙️ Configuration
- Added
geminioption toaiServiceProviderenum in package.json - Added
geminiApiKeysetting with link to Google AI Studio for API key setup - Added
geminiModelsetting with support for multiple Gemini models:gemini-2.0-flash-exp(default)gemini-1.5-progemini-1.5-flash
🏗️ Implementation
-
GeminiService.ts: New service class implementing the AIService interface
- Singleton pattern for service management
- Full integration with caching layer (CacheService)
- Error handling and logging
- Support for all extension features: commit message generation, diff explanation, etc.
-
WorkspaceService.ts: Extended with Gemini-specific configuration methods
getGeminiKey(): Retrieves and validates Gemini API keygetGeminiModel(): Gets selected Gemini model from settings
-
Diffy.ts: Updated main extension class
- Added
getGeminiService()method for lazy initialization - Updated
getAIService()to route to Gemini when provider is set to "gemini" - All four main methods now support Gemini:
explainAndPreview()explainDiffToClipboard()generateCommitMessageToClipboard()generateCommitMessageToSCM()
- Added proper cleanup in
dispose()method
- Added
Usage
Users can now select Google Gemini as their AI provider by setting:
{
"diffy.aiServiceProvider": "gemini",
"diffy.geminiApiKey": "your-gemini-api-key-here",
"diffy.geminiModel": "gemini-2.0-flash-exp"
}Testing
- ✅ Code compiles successfully with webpack
- ✅ All TypeScript types are properly defined
- ✅ Follows existing code patterns and architecture
- ✅ Error handling matches existing services
- ✅ Caching integration works correctly
Commits
The changes were committed separately for better review:
feat: add Google Gemini API dependency- Package updatesfeat: implement GeminiService for Google Gemini API integration- New servicefeat: add Gemini configuration methods to WorkspaceService- Config methodsfeat: integrate GeminiService into Diffy extension- Main integration
No description provided.