Skip to content

Commit e14de7a

Browse files
authored
fix: tweak the logic in config to ensure that env vs file configurations merge properly (#115)
1 parent 004cfe7 commit e14de7a

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

internal/config/config.go

+13-9
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ func Load(workingDir string, debug bool) (*Config, error) {
129129

130130
configureViper()
131131
setDefaults(debug)
132-
setProviderDefaults()
133132

134133
// Read global config
135134
if err := readConfig(viper.ReadInConfig()); err != nil {
@@ -139,6 +138,8 @@ func Load(workingDir string, debug bool) (*Config, error) {
139138
// Load and merge local config
140139
mergeLocalConfig(workingDir)
141140

141+
setProviderDefaults()
142+
142143
// Apply configuration to the struct
143144
if err := viper.Unmarshal(cfg); err != nil {
144145
return cfg, fmt.Errorf("failed to unmarshal config: %w", err)
@@ -222,7 +223,8 @@ func setDefaults(debug bool) {
222223
}
223224
}
224225

225-
// setProviderDefaults configures LLM provider defaults based on environment variables.
226+
// setProviderDefaults configures LLM provider defaults based on provider provided by
227+
// environment variables and configuration file.
226228
func setProviderDefaults() {
227229
// Set all API keys we can find in the environment
228230
if apiKey := os.Getenv("ANTHROPIC_API_KEY"); apiKey != "" {
@@ -246,42 +248,44 @@ func setProviderDefaults() {
246248
// 2. OpenAI
247249
// 3. Google Gemini
248250
// 4. Groq
249-
// 5. AWS Bedrock
251+
// 5. OpenRouter
252+
// 6. AWS Bedrock
253+
// 7. Azure
254+
250255
// Anthropic configuration
251-
if apiKey := os.Getenv("ANTHROPIC_API_KEY"); apiKey != "" {
256+
if viper.Get("providers.anthropic.apiKey") != "" {
252257
viper.SetDefault("agents.coder.model", models.Claude37Sonnet)
253258
viper.SetDefault("agents.task.model", models.Claude37Sonnet)
254259
viper.SetDefault("agents.title.model", models.Claude37Sonnet)
255260
return
256261
}
257262

258263
// OpenAI configuration
259-
if apiKey := os.Getenv("OPENAI_API_KEY"); apiKey != "" {
264+
if viper.Get("providers.openai.apiKey") != "" {
260265
viper.SetDefault("agents.coder.model", models.GPT41)
261266
viper.SetDefault("agents.task.model", models.GPT41Mini)
262267
viper.SetDefault("agents.title.model", models.GPT41Mini)
263268
return
264269
}
265270

266271
// Google Gemini configuration
267-
if apiKey := os.Getenv("GEMINI_API_KEY"); apiKey != "" {
272+
if viper.Get("providers.google.gemini.apiKey") != "" {
268273
viper.SetDefault("agents.coder.model", models.Gemini25)
269274
viper.SetDefault("agents.task.model", models.Gemini25Flash)
270275
viper.SetDefault("agents.title.model", models.Gemini25Flash)
271276
return
272277
}
273278

274279
// Groq configuration
275-
if apiKey := os.Getenv("GROQ_API_KEY"); apiKey != "" {
280+
if viper.Get("providers.groq.apiKey") != "" {
276281
viper.SetDefault("agents.coder.model", models.QWENQwq)
277282
viper.SetDefault("agents.task.model", models.QWENQwq)
278283
viper.SetDefault("agents.title.model", models.QWENQwq)
279284
return
280285
}
281286

282287
// OpenRouter configuration
283-
if apiKey := os.Getenv("OPENROUTER_API_KEY"); apiKey != "" {
284-
viper.SetDefault("providers.openrouter.apiKey", apiKey)
288+
if viper.Get("providers.openrouter.apiKey") != "" {
285289
viper.SetDefault("agents.coder.model", models.OpenRouterClaude37Sonnet)
286290
viper.SetDefault("agents.task.model", models.OpenRouterClaude37Sonnet)
287291
viper.SetDefault("agents.title.model", models.OpenRouterClaude35Haiku)

internal/llm/models/models.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ const (
3535

3636
// Providers in order of popularity
3737
var ProviderPopularity = map[ModelProvider]int{
38-
ProviderAnthropic: 1,
39-
ProviderOpenAI: 2,
40-
ProviderGemini: 3,
41-
ProviderGROQ: 4,
42-
ProviderBedrock: 5,
38+
ProviderAnthropic: 1,
39+
ProviderOpenAI: 2,
40+
ProviderGemini: 3,
41+
ProviderGROQ: 4,
42+
ProviderOpenRouter: 5,
43+
ProviderBedrock: 6,
44+
ProviderAzure: 7,
4345
}
4446

4547
var SupportedModels = map[ModelID]Model{

0 commit comments

Comments
 (0)