env var updates
This commit is contained in:
@@ -210,6 +210,19 @@ func listModels(cfg *Cfg) (string, error) {
|
||||
|
||||
func getCfg(path string) Cfg {
|
||||
cfg := defCfg
|
||||
// Environment variable fallbacks. These are applied BEFORE the config file is
|
||||
// read so that any value explicitly set in the config file overrides them.
|
||||
if v := strings.TrimSpace(os.Getenv("BANTAM_ENDPOINT")); v != "" {
|
||||
cfg.Endpoint = v
|
||||
}
|
||||
if v := strings.TrimSpace(os.Getenv("BANTAM_MODEL")); v != "" {
|
||||
cfg.Model = v
|
||||
}
|
||||
if v := strings.TrimSpace(os.Getenv("BANTAM_TEMP")); v != "" {
|
||||
if f, e := strconv.ParseFloat(v, 64); e == nil {
|
||||
cfg.Temperature = f
|
||||
}
|
||||
}
|
||||
cfg.Raw = map[string]string{
|
||||
"endpoint": cfg.Endpoint, "model": cfg.Model, "temperature": fmt.Sprintf("%v", cfg.Temperature),
|
||||
"api_key": cfg.APIKey, "stream": strconv.FormatBool(cfg.Stream), "color": cfg.Color,
|
||||
@@ -239,8 +252,10 @@ func getCfg(path string) Cfg {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cfg.APIKey == "" || cfg.APIKey == "-") && os.Getenv("OPENAI_API_KEY") != "" {
|
||||
cfg.APIKey = os.Getenv("OPENAI_API_KEY")
|
||||
// The api_key "-" / empty sentinel means "fall back to BANTAM_API_KEY"; this
|
||||
// is evaluated after the file is read so an explicit key still wins.
|
||||
if (cfg.APIKey == "" || cfg.APIKey == "-") && os.Getenv("BANTAM_API_KEY") != "" {
|
||||
cfg.APIKey = os.Getenv("BANTAM_API_KEY")
|
||||
cfg.Raw["api_key"] = cfg.APIKey
|
||||
}
|
||||
return cfg
|
||||
@@ -298,22 +313,24 @@ When generating code:
|
||||
- Respect AGENTS.md contents in the project.`
|
||||
|
||||
func toolsDir(cfg *Cfg) string {
|
||||
if v := strings.TrimSpace(os.Getenv("BANTAM_TOOLS_DIR")); v != "" {
|
||||
// The config key takes priority over the environment variable: a local
|
||||
// .bantam.cfg always overrides BANTAM_TOOLS_DIR.
|
||||
if v := strings.TrimSpace(cfg.Raw["bantam_tools_dir"]); v != "" {
|
||||
return v
|
||||
}
|
||||
if v := strings.TrimSpace(cfg.Raw["bantam_tools_dir"]); v != "" {
|
||||
if v := strings.TrimSpace(os.Getenv("BANTAM_TOOLS_DIR")); v != "" {
|
||||
return v
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// skillsDir returns the directory Bantam should scan for skills, preferring the
|
||||
// BANTAM_SKILLS_DIR environment variable, then the bantam_skills_dir config key.
|
||||
// bantam_skills_dir config key, then the BANTAM_SKILLS_DIR environment variable.
|
||||
func skillsDir(cfg *Cfg) string {
|
||||
if v := strings.TrimSpace(os.Getenv("BANTAM_SKILLS_DIR")); v != "" {
|
||||
if v := strings.TrimSpace(cfg.Raw["bantam_skills_dir"]); v != "" {
|
||||
return v
|
||||
}
|
||||
if v := strings.TrimSpace(cfg.Raw["bantam_skills_dir"]); v != "" {
|
||||
if v := strings.TrimSpace(os.Getenv("BANTAM_SKILLS_DIR")); v != "" {
|
||||
return v
|
||||
}
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user