mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: clean up env var usage in aibridge (#24783)
> AI tools where used when creating this PR This PR removes environment variable parsing from `/aibridge` directory. Added env variables/flags for dump dir as coder options. Only added to new indexed provider options (`CODER_AIBRIDGE_PROVIDER_<N>_*`) not to deprecated legacy env variables (`CODER_AIBRIDGE_ANTHROPIC_*` and `CODER_AIBRIDGE_OPENAI_KEY_*`). Reverted adding `MaxRetries` option as it will be removed soon due to key failover work: https://github.com/coder/coder/pull/24783#discussion_r3155544808
This commit is contained in:
@@ -116,6 +116,7 @@ func buildProviders(cfg codersdk.AIBridgeConfig) ([]aibridge.Provider, error) {
|
||||
Name: name,
|
||||
BaseURL: p.BaseURL,
|
||||
Key: p.Key,
|
||||
APIDumpDir: p.DumpDir,
|
||||
CircuitBreaker: cbConfig,
|
||||
SendActorHeaders: cfg.SendActorHeaders.Value(),
|
||||
}))
|
||||
@@ -124,6 +125,7 @@ func buildProviders(cfg codersdk.AIBridgeConfig) ([]aibridge.Provider, error) {
|
||||
Name: name,
|
||||
BaseURL: p.BaseURL,
|
||||
Key: p.Key,
|
||||
APIDumpDir: p.DumpDir,
|
||||
CircuitBreaker: cbConfig,
|
||||
SendActorHeaders: cfg.SendActorHeaders.Value(),
|
||||
}, bedrockConfigFromProvider(p)))
|
||||
@@ -131,6 +133,7 @@ func buildProviders(cfg codersdk.AIBridgeConfig) ([]aibridge.Provider, error) {
|
||||
providers = append(providers, aibridge.NewCopilotProvider(aibridge.CopilotConfig{
|
||||
Name: name,
|
||||
BaseURL: p.BaseURL,
|
||||
APIDumpDir: p.DumpDir,
|
||||
CircuitBreaker: cbConfig,
|
||||
}))
|
||||
default:
|
||||
|
||||
@@ -43,8 +43,19 @@ func TestBuildProviders(t *testing.T) {
|
||||
t.Parallel()
|
||||
cfg := codersdk.AIBridgeConfig{
|
||||
Providers: []codersdk.AIBridgeProviderConfig{
|
||||
{Type: aibridge.ProviderAnthropic, Name: "anthropic-zdr", Key: "sk-zdr"},
|
||||
{Type: aibridge.ProviderOpenAI, Name: "openai-azure", Key: "sk-azure", BaseURL: "https://azure.openai.com"},
|
||||
{
|
||||
Type: aibridge.ProviderAnthropic,
|
||||
Name: "anthropic-zdr",
|
||||
Key: "sk-zdr",
|
||||
DumpDir: "/tmp/anthropic-dump",
|
||||
},
|
||||
{
|
||||
Type: aibridge.ProviderOpenAI,
|
||||
Name: "openai-azure",
|
||||
Key: "sk-azure",
|
||||
BaseURL: "https://azure.openai.com",
|
||||
DumpDir: "/tmp/openai-dump",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -53,6 +64,8 @@ func TestBuildProviders(t *testing.T) {
|
||||
|
||||
names := providerNames(providers)
|
||||
assert.Equal(t, []string{"anthropic-zdr", "openai-azure"}, names)
|
||||
assert.Equal(t, "/tmp/anthropic-dump", providers[0].APIDumpDir())
|
||||
assert.Equal(t, "/tmp/openai-dump", providers[1].APIDumpDir())
|
||||
})
|
||||
|
||||
t.Run("LegacyOpenAIConflictsWithIndexed", func(t *testing.T) {
|
||||
@@ -154,7 +167,7 @@ func TestBuildProviders(t *testing.T) {
|
||||
// Copilot API hosts via an explicit BASE_URL.
|
||||
cfg := codersdk.AIBridgeConfig{
|
||||
Providers: []codersdk.AIBridgeProviderConfig{
|
||||
{Type: aibridge.ProviderCopilot, Name: aibridge.ProviderCopilot},
|
||||
{Type: aibridge.ProviderCopilot, Name: aibridge.ProviderCopilot, DumpDir: "/tmp/copilot-dump"},
|
||||
{Type: aibridge.ProviderCopilot, Name: agplaibridge.ProviderCopilotBusiness, BaseURL: "https://" + agplaibridge.HostCopilotBusiness},
|
||||
{Type: aibridge.ProviderCopilot, Name: agplaibridge.ProviderCopilotEnterprise, BaseURL: "https://" + agplaibridge.HostCopilotEnterprise},
|
||||
},
|
||||
@@ -165,6 +178,7 @@ func TestBuildProviders(t *testing.T) {
|
||||
require.Len(t, providers, 3)
|
||||
|
||||
assert.Equal(t, aibridge.ProviderCopilot, providers[0].Name())
|
||||
assert.Equal(t, "/tmp/copilot-dump", providers[0].APIDumpDir())
|
||||
assert.Equal(t, agplaibridge.ProviderCopilotBusiness, providers[1].Name())
|
||||
assert.Equal(t, "https://"+agplaibridge.HostCopilotBusiness, providers[1].BaseURL())
|
||||
assert.Equal(t, agplaibridge.ProviderCopilotEnterprise, providers[2].Name())
|
||||
|
||||
Reference in New Issue
Block a user