Skip to content

Conversation

@m7medVision
Copy link
Owner

This pull request introduces support for custom API endpoints per provider, allowing users to configure and use alternative or local AI inference servers for commit message generation. It removes OpenRouter as a built-in provider and updates the configuration, CLI, and documentation to reflect these changes. The main themes are provider configuration flexibility, codebase simplification, and improved validation.

Provider configuration and flexibility:

  • Added support for custom API endpoints for providers (openai, copilot) via the new endpoint_url field in configuration, including CLI and interactive config support, and validation for endpoint URLs. [1] [2] [3] [4] [5]
  • Updated provider constructors and internal logic to use the configured endpoint, defaulting to the official endpoint if none is set. [1] [2] [3]

Documentation and model selection:

  • Updated README.md to document custom endpoint configuration, removed OpenRouter as a built-in provider, and added examples for local and alternative endpoints. [1] [2] [3]
  • Simplified interactive provider/model selection in the CLI, removing OpenRouter and updating model lists accordingly. [1] [2] [3] [4]

Testing and validation:

  • Added comprehensive tests for endpoint configuration, including default endpoints, custom endpoints, unknown providers, and endpoint URL validation.

Minor fixes:

  • Updated tests to remove references to OpenRouter and use openai for provider-related tests. [1] [2] [3]

These changes collectively make the tool more flexible for enterprise, local, or alternative AI model usage, while simplifying the provider configuration experience.

@m7medVision m7medVision self-assigned this Oct 24, 2025
@m7medVision m7medVision added the enhancement New feature or request label Oct 24, 2025
@gemini-code-assist
Copy link

Summary of Changes

Hello @m7medVision, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the flexibility of the AI commit message generator by allowing users to specify custom API endpoints for their chosen AI providers. This change facilitates integration with local AI models like Ollama, enterprise proxy servers, or other OpenAI-compatible services, moving away from hardcoded endpoints. Concurrently, the OpenRouter provider has been deprecated and removed, streamlining the codebase and configuration options. The updates ensure a more adaptable and simplified user experience for diverse AI inference setups.

Highlights

  • Custom Endpoint Support: Introduced the ability to configure custom API endpoints for openai and copilot providers, enabling use with local AI inference servers or alternative services.
  • OpenRouter Removal: The OpenRouter provider has been removed from the application, simplifying the provider list and configuration.
  • Configuration Updates: The configuration structure, CLI interactive setup, and README.md documentation have been updated to support and explain the new custom endpoint feature and reflect the removal of OpenRouter.
  • Endpoint Validation: New validation logic ensures that custom endpoint URLs are correctly formatted and use http or https protocols.
  • Provider Logic Refinement: Provider constructors and internal logic now dynamically use the configured endpoint_url, falling back to default official endpoints if none is specified.
  • Enhanced Testing: Comprehensive unit tests have been added for endpoint configuration, covering default, custom, and invalid endpoint scenarios.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@m7medVision m7medVision changed the title Feature/custom endpoint support Custom Endpoints Oct 24, 2025
@m7medVision m7medVision mentioned this pull request Oct 24, 2025
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces custom API endpoint support for providers, removes OpenRouter, and updates configurations. The code changes include modifications to the README, command-line tools, internal configurations, and provider implementations. I have focused on identifying potential issues related to correctness and error handling, and have provided suggestions for improvement.

Comment on lines +177 to +196
func validateEndpointURL(endpoint string) error {
if endpoint == "" {
return nil // Empty endpoint is valid (will use default)
}

parsedURL, err := url.Parse(endpoint)
if err != nil {
return fmt.Errorf("invalid URL format: %w", err)
}

if parsedURL.Scheme != "http" && parsedURL.Scheme != "https" {
return fmt.Errorf("endpoint must use http or https protocol")
}

if parsedURL.Host == "" {
return fmt.Errorf("endpoint must have a valid host")
}

return nil
}

Choose a reason for hiding this comment

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

high

The validateEndpointURL function is duplicated in cmd/config.go. This duplication increases the risk of inconsistencies and makes maintenance more difficult. Consider creating a single, reusable validation function in a common utility package and calling it from both places.

Comment on lines +59 to +63
endpoint, err := config.GetEndpoint()
if err != nil {
fmt.Fprintf(os.Stderr, "Error getting endpoint: %v\n", err)
os.Exit(1)
}

Choose a reason for hiding this comment

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

medium

This block retrieves the endpoint, but the error is only handled by printing to stderr and exiting. It would be better to propagate this error so that the calling function can handle it gracefully, potentially providing more context to the user or attempting a fallback mechanism.

Consider returning the error to allow the caller to handle it.

Comment on lines +49 to +73
func validateEndpointURL(val interface{}) error {
endpoint, ok := val.(string)
if !ok {
return fmt.Errorf("endpoint must be a string")
}

// Empty string is valid (uses default)
if endpoint == "" {
return nil
}

parsedURL, err := url.Parse(endpoint)
if err != nil {
return fmt.Errorf("invalid URL format: %w", err)
}

if parsedURL.Scheme != "http" && parsedURL.Scheme != "https" {
return fmt.Errorf("endpoint must use http or https protocol")
}

if parsedURL.Host == "" {
return fmt.Errorf("endpoint must have a valid host")
}

return nil

Choose a reason for hiding this comment

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

medium

The validateEndpointURL function could benefit from more robust validation. Currently, it checks for http or https schemes and a valid host. However, it doesn't check for other potential issues, such as invalid characters, malformed URLs, or excessively long URLs. Consider adding additional checks to ensure that the endpoint URL is well-formed and safe to use.

For example, you could use a regular expression to validate the URL format or check the URL length to prevent buffer overflow issues.

Comment on lines +177 to +196
func validateEndpointURL(endpoint string) error {
if endpoint == "" {
return nil // Empty endpoint is valid (will use default)
}

parsedURL, err := url.Parse(endpoint)
if err != nil {
return fmt.Errorf("invalid URL format: %w", err)
}

if parsedURL.Scheme != "http" && parsedURL.Scheme != "https" {
return fmt.Errorf("endpoint must use http or https protocol")
}

if parsedURL.Host == "" {
return fmt.Errorf("endpoint must have a valid host")
}

return nil
}

Choose a reason for hiding this comment

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

medium

The validateEndpointURL function could benefit from more robust validation. Currently, it checks for http or https schemes and a valid host. However, it doesn't check for other potential issues, such as invalid characters, malformed URLs, or excessively long URLs. Consider adding additional checks to ensure that the endpoint URL is well-formed and safe to use.

For example, you could use a regular expression to validate the URL format or check the URL length to prevent buffer overflow issues.

Comment on lines +212 to 240
func TestSetEndpoint_Validation(t *testing.T) {
// Reset configuration for clean test
cfg = nil
viper.Reset()

// Initialize config
InitConfig()

testCases := []struct {
endpoint string
valid bool
}{
{"", true}, // Empty should be valid (default)
{"https://api.openai.com/v1", true}, // Valid HTTPS URL
{"http://localhost:11434", true}, // Valid HTTP URL
{"ftp://invalid.com", false}, // Invalid protocol
{"not-a-url", false}, // Invalid format
{"https://", false}, // Missing host
}

for _, tc := range testCases {
err := SetEndpoint("test", tc.endpoint)
if tc.valid && err != nil {
t.Errorf("Expected valid endpoint %s to pass, but got error: %v", tc.endpoint, err)
} else if !tc.valid && err == nil {
t.Errorf("Expected invalid endpoint %s to fail, but it passed", tc.endpoint)
}
}
}

Choose a reason for hiding this comment

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

medium

The test case "https://" is marked as invalid due to the missing host. However, url.Parse in Go handles this case without error, resulting in an empty Host field. While the current validation logic correctly identifies this as invalid, the test description might be misleading. Consider updating the test description to accurately reflect the behavior of url.Parse and the validation logic.

@m7medVision m7medVision merged commit dbe4d09 into main Oct 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants