env tweaks
This commit is contained in:
@@ -210,6 +210,7 @@ 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 != "" {
|
||||
@@ -222,15 +223,49 @@ func getCfg(path string) Cfg {
|
||||
if f, e := strconv.ParseFloat(v, 64); e == nil {
|
||||
cfg.Temperature = f
|
||||
}
|
||||
} else if v := strings.TrimSpace(os.Getenv("BANTAM_TEMPERATURE")); v != "" {
|
||||
if f, e := strconv.ParseFloat(v, 64); e == nil {
|
||||
cfg.Temperature = f
|
||||
}
|
||||
}
|
||||
if v := strings.TrimSpace(os.Getenv("BANTAM_STREAM")); v != "" {
|
||||
cfg.Stream = v == "true" || v == "1" || v == "yes"
|
||||
}
|
||||
if v := strings.TrimSpace(os.Getenv("BANTAM_COLOR")); v != "" {
|
||||
cfg.Color = v
|
||||
}
|
||||
if v := strings.TrimSpace(os.Getenv("BANTAM_TIMEOUT")); v != "" {
|
||||
cfg.Timeout = atoiD(v, cfg.Timeout)
|
||||
}
|
||||
if v := strings.TrimSpace(os.Getenv("BANTAM_SHELL_TIMEOUT")); v != "" {
|
||||
cfg.ShellTimeout = atoiD(v, cfg.ShellTimeout)
|
||||
}
|
||||
if v := strings.TrimSpace(os.Getenv("BANTAM_MAX_AL_ITERATIONS")); v != "" {
|
||||
cfg.MaxALIterations = atoiD(v, cfg.MaxALIterations)
|
||||
}
|
||||
if v := strings.TrimSpace(os.Getenv("BANTAM_CONTEXT_WINDOW")); v != "" {
|
||||
cfg.ContextWindow = atoiD(v, cfg.ContextWindow)
|
||||
}
|
||||
re := "high"
|
||||
if v := strings.TrimSpace(os.Getenv("BANTAM_REASONING_EFFORT")); v != "" {
|
||||
re = v
|
||||
}
|
||||
|
||||
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,
|
||||
"timeout": strconv.Itoa(cfg.Timeout), "shell_timeout": strconv.Itoa(cfg.ShellTimeout),
|
||||
"max_al_iterations": strconv.Itoa(cfg.MaxALIterations),
|
||||
"context_window": strconv.Itoa(cfg.ContextWindow),
|
||||
"reasoning_effort": "high",
|
||||
"reasoning_effort": re,
|
||||
}
|
||||
if v := strings.TrimSpace(os.Getenv("BANTAM_TOOLS_DIR")); v != "" {
|
||||
cfg.Raw["bantam_tools_dir"] = v
|
||||
}
|
||||
if v := strings.TrimSpace(os.Getenv("BANTAM_SKILLS_DIR")); v != "" {
|
||||
cfg.Raw["bantam_skills_dir"] = v
|
||||
}
|
||||
|
||||
if d, err := os.ReadFile(path); err == nil {
|
||||
for _, ln := range strings.Split(string(d), "\n") {
|
||||
ln = strings.TrimSpace(ln)
|
||||
@@ -252,9 +287,10 @@ func getCfg(path string) Cfg {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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") != "" {
|
||||
if(cfg.APIKey == "" || cfg.APIKey == "-") && os.Getenv("BANTAM_API_KEY") != "" {
|
||||
cfg.APIKey = os.Getenv("BANTAM_API_KEY")
|
||||
cfg.Raw["api_key"] = cfg.APIKey
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user