Skip to content

Conversation

@Hi7cl4w
Copy link
Owner

@Hi7cl4w Hi7cl4w commented Nov 3, 2025

No description provided.

- 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 Hi7cl4w linked an issue Nov 3, 2025 that may be closed by this pull request
Copy link
Owner Author

@Hi7cl4w Hi7cl4w left a 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/genai v1.28.0 package for Google Gemini API integration

⚙️ Configuration

  • Added gemini option to aiServiceProvider enum in package.json
  • Added geminiApiKey setting with link to Google AI Studio for API key setup
  • Added geminiModel setting with support for multiple Gemini models:
    • gemini-2.0-flash-exp (default)
    • gemini-1.5-pro
    • gemini-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 key
    • getGeminiModel(): 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

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:

  1. feat: add Google Gemini API dependency - Package updates
  2. feat: implement GeminiService for Google Gemini API integration - New service
  3. feat: add Gemini configuration methods to WorkspaceService - Config methods
  4. feat: integrate GeminiService into Diffy extension - Main integration

@Hi7cl4w Hi7cl4w merged commit 80d85ae into main Nov 3, 2025
7 checks passed
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.

Feature Request: Add Support for Google Gemini API

2 participants