- Introduce config.Load() to handle centralized configuration loading in TOML format - Add --model flag support across commands with alias resolution via GetModel - Update root command to load config in PersistentPreRun - Remove redundant config init and set defaults for model and temperature
37 lines
791 B
Go
37 lines
791 B
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
func Load() {
|
|
home, _ := os.UserHomeDir()
|
|
configPath := filepath.Join(home, ".config", "grokkit")
|
|
|
|
viper.SetConfigName("config")
|
|
viper.SetConfigType("toml")
|
|
viper.AddConfigPath(configPath)
|
|
viper.AddConfigPath(".")
|
|
viper.AutomaticEnv() // XAI_API_KEY etc.
|
|
|
|
viper.SetDefault("default_model", "grok-4")
|
|
viper.SetDefault("temperature", 0.7)
|
|
|
|
_ = viper.ReadInConfig() // ignore error if no config yet
|
|
}
|
|
|
|
// GetModel returns the model, respecting --model flag or alias
|
|
func GetModel(flagModel string) string {
|
|
if flagModel != "" {
|
|
// Check alias first
|
|
if alias := viper.GetString("aliases." + flagModel); alias != "" {
|
|
return alias
|
|
}
|
|
return flagModel
|
|
}
|
|
return viper.GetString("default_model")
|
|
}
|