on main help sign in
fix: tweak the logic in config to ensure that env vs file configurations merge properly (#115)
commite14de7a2111170e782d2c61f872b5db26667cb0d authorAiden Cline <63023139+rekram1-node@users.noreply.github.com> dateThu 1 May 2025, 06:22 (1 year ago) parent004cfe7
2 files changed+20−14
internal/config/config.go+13−9 internal/llm/models/models.go+7−5
internal/config/config.go+13−9
@@ -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.
226228func setProviderDefaults() {
227229 // Set all API keys we can find in the environment
228230 if apiKey := os.Getenv("ANTHROPIC_API_KEY"); apiKey != "" {
@@ -246,9 +248,12 @@ 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)
@@ -256,7 +261,7 @@ func setProviderDefaults() {
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)
@@ -264,7 +269,7 @@ func setProviderDefaults() {
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)
@@ -272,7 +277,7 @@ func setProviderDefaults() {
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)
@@ -280,8 +285,7 @@ func setProviderDefaults() {
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
@@ -35,11 +35,13 @@ const (
3535
3636// Providers in order of popularity
3737var 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
4547var SupportedModels = map[ModelID]Model{