Skip to content

feat: add Gemini backend support #93

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

Merged
merged 5 commits into from
Apr 12, 2025
Merged

Conversation

catatsuy
Copy link
Owner

This pull request introduces significant changes to the internal/cli/cli.go file to add support for a new backend, Gemini, alongside the existing OpenAI backend. It also includes the implementation of the Gemini client and its associated tests. Below are the most important changes:

CLI Enhancements:

  • Added a new backend flag to specify the backend to use, either openai or gemini. (internal/cli/cli.go) [1] [2]
  • Updated the Run method to select the appropriate translator based on the backend flag and set the corresponding API key environment variable. (internal/cli/cli.go)

Gemini Client Implementation:

  • Introduced the GeminiTranslator struct and implemented the request method to interact with the Gemini API. (internal/cli/cli.go)
  • Added the internal/gemini package, which includes the Client, Payload, Message, and Response types, as well as methods for creating a new client and sending chat requests. (internal/gemini/client.go)

Testing:

  • Added unit tests for the Gemini client to test successful and failed chat requests. (internal/gemini/client_test.go)
  • Included test data files for the Gemini client tests. (internal/gemini/testdata/gemini_success.json)

Code Cleanup and Documentation:

  • Improved documentation and comments throughout the internal/cli/cli.go file. (internal/cli/cli.go) [1] [2] [3]
  • Removed redundant error messages and streamlined error handling. (internal/cli/cli.go) [1] [2]

These changes collectively enhance the CLI tool by adding support for the Gemini backend, improving code readability, and ensuring robust testing for the new functionality.

@catatsuy catatsuy requested a review from Copilot April 12, 2025 07:14
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.

Files not reviewed (1)
  • internal/gemini/testdata/gemini_success.json: Language not supported
Comments suppressed due to low confidence (1)

internal/cli/cli.go:360

  • Update the inline comment to match the default Gemini model ('gemini-2.0-flash-lite') defined in the constants for consistency.
Model: useModel, // e.g., "gemini-2.0-flash"

catatsuy and others added 2 commits April 12, 2025 16:15
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@catatsuy catatsuy requested a review from Copilot April 12, 2025 07:15
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 5 out of 6 changed files in this pull request and generated no comments.

Files not reviewed (1)
  • internal/gemini/testdata/gemini_success.json: Language not supported
Comments suppressed due to low confidence (2)

internal/gemini/client.go:15

  • The variable name GeminiAPIURL is potentially misleading since the URL contains 'openai'. Consider renaming it or adding a clarifying comment to indicate it is the endpoint for Gemini.
var GeminiAPIURL = "https://generativelanguage.googleapis.com/v1beta/openai/chat/completions"

internal/cli/cli.go:172

  • [nitpick] Overwriting the default OpenAI model with the Gemini default for the Gemini backend might be unexpected; consider adding a comment or log to inform users that the default model is being switched when using the gemini backend.
if useModel == DefaultOpenAIModel { useModel = DefaultGeminiModel }

@catatsuy catatsuy merged commit 1052be4 into main Apr 12, 2025
5 checks passed
@catatsuy catatsuy deleted the feature-add-gemini-backend branch April 12, 2025 07:19
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.

1 participant