feat: add per-entry base-url support for OpenAI-compatible API keys#769
feat: add per-entry base-url support for OpenAI-compatible API keys#769hungthai1401 wants to merge 2 commits intorouter-for-me:devfrom
Conversation
…y providers Allow individual API key entries to specify their own base URL that overrides the parent provider's base URL. This enables using different endpoints for different API keys within the same OpenAI compatibility provider configuration. When the per-entry BaseURL field is empty, the system falls back to the parent provider's base URL, maintaining backward compatibility with existing configs.
Summary of ChangesHello @hungthai1401, 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 enhances the flexibility of OpenAI-compatible API key configurations by enabling the specification of a unique base URL for each individual API key. This allows for more granular control over where requests are directed, while maintaining a sensible fallback to the provider's default base URL if a specific one isn't provided for an entry. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request adds support for a per-entry base-url for OpenAI-compatible API keys, with a fallback to the parent base-url. The implementation looks correct across the configuration, synthesizer logic, and example file. A new test has been added to cover this feature. I've provided a couple of suggestions to improve the new test for better maintainability and reproducibility. Overall, the changes are good.
| }, | ||
| }, | ||
| }, | ||
| Now: time.Now(), |
There was a problem hiding this comment.
| // First entry has custom base URL | ||
| if auths[0].Attributes["base_url"] != "https://custom.api.com" { | ||
| t.Errorf("expected base_url https://custom.api.com, got %s", auths[0].Attributes["base_url"]) | ||
| } | ||
| if auths[0].Attributes["api_key"] != "key-with-custom-base" { | ||
| t.Errorf("expected api_key key-with-custom-base, got %s", auths[0].Attributes["api_key"]) | ||
| } | ||
|
|
||
| // Second entry falls back to parent base URL | ||
| if auths[1].Attributes["base_url"] != "https://default.api.com" { | ||
| t.Errorf("expected base_url https://default.api.com, got %s", auths[1].Attributes["base_url"]) | ||
| } | ||
| if auths[1].Attributes["api_key"] != "key-without-base" { | ||
| t.Errorf("expected api_key key-without-base, got %s", auths[1].Attributes["api_key"]) | ||
| } | ||
|
|
||
| // Third entry with empty base URL falls back to parent base URL | ||
| if auths[2].Attributes["base_url"] != "https://default.api.com" { | ||
| t.Errorf("expected base_url https://default.api.com, got %s", auths[2].Attributes["base_url"]) | ||
| } | ||
| if auths[2].Attributes["api_key"] != "key-with-empty-base" { | ||
| t.Errorf("expected api_key key-with-empty-base, got %s", auths[2].Attributes["api_key"]) | ||
| } |
There was a problem hiding this comment.
The test assertions are a bit repetitive. Refactoring this to use a table-driven structure would make the test cleaner, more readable, and easier to extend with more test cases in the future.
testCases := []struct {
name string
expectedKey string
expectedURL string
authIndex int
}{
{
name: "custom base URL",
expectedKey: "key-with-custom-base",
expectedURL: "https://custom.api.com",
authIndex: 0,
},
{
name: "fallback to parent base URL",
expectedKey: "key-without-base",
expectedURL: "https://default.api.com",
authIndex: 1,
},
{
name: "empty base URL falls back to parent",
expectedKey: "key-with-empty-base",
expectedURL: "https://default.api.com",
authIndex: 2,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
auth := auths[tc.authIndex]
if auth.Attributes["base_url"] != tc.expectedURL {
t.Errorf("expected base_url %q, got %q", tc.expectedURL, auth.Attributes["base_url"])
}
if auth.Attributes["api_key"] != tc.expectedKey {
t.Errorf("expected api_key %q, got %q", tc.expectedKey, auth.Attributes["api_key"])
}
})
}|
Thanks for the contribution. Unfortunately, we follow a "one provider, one base-url" principle, so we cannot merge this. |
Summary
Adds optional
base-urlfield to individual API key entries in OpenAI-compatible configurations. If not specified, falls back to the parentbase-url.Changes
BaseURLfield toOpenAICompatibilityAPIKeystructUsage