Split OLLIE_API_URL into backend-specific vars

OLLIE_API_URL was shared across backends, causing the ollama backend
to use the OpenRouter URL when OLLIE_BACKEND was overridden on the
command line while the env file still set OLLIE_API_URL.

Replace with OLLIE_OLLAMA_URL and OLLIE_OPENAI_URL so each backend
only reads its own URL setting.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Levi Neely 2026-03-31 23:50:05 +02:00
parent 73b13451a0
commit ebb726e384
1 changed files with 8 additions and 10 deletions

View File

@ -40,9 +40,10 @@ func loadEnvFile(path string) {
// so the file acts as a default; variables already set in the environment take // so the file acts as a default; variables already set in the environment take
// precedence. // precedence.
// //
// OLLIE_BACKEND ollama | openai | openrouter (default: ollama) // OLLIE_BACKEND ollama | openai | openrouter (default: ollama)
// OLLIE_API_URL override base URL for the selected backend // OLLIE_OLLAMA_URL base URL for ollama (default: http://localhost:11434)
// OLLIE_API_KEY API key (required for openai / openrouter) // OLLIE_OPENAI_URL base URL for openai-compatible backends
// OLLIE_API_KEY API key (required for openai / openrouter)
func New() (Backend, error) { func New() (Backend, error) {
home, _ := os.UserHomeDir() home, _ := os.UserHomeDir()
loadEnvFile(home + "/.config/ollie/env") loadEnvFile(home + "/.config/ollie/env")
@ -52,20 +53,17 @@ func New() (Backend, error) {
which = "ollama" which = "ollama"
} }
apiURL := os.Getenv("OLLIE_API_URL")
apiKey := os.Getenv("OLLIE_API_KEY")
switch which { switch which {
case "ollama": case "ollama":
return NewOllama(apiURL), nil return NewOllama(os.Getenv("OLLIE_OLLAMA_URL")), nil
case "openai": case "openai":
return NewOpenAI(apiURL, apiKey), nil return NewOpenAI(os.Getenv("OLLIE_OPENAI_URL"), os.Getenv("OLLIE_API_KEY")), nil
case "openrouter": case "openrouter":
url := apiURL url := os.Getenv("OLLIE_OPENAI_URL")
if url == "" { if url == "" {
url = "https://openrouter.ai/api" url = "https://openrouter.ai/api"
} }
return NewOpenAI(url, apiKey), nil return NewOpenAI(url, os.Getenv("OLLIE_API_KEY")), nil
default: default:
return nil, fmt.Errorf("unknown OLLIE_BACKEND %q (supported: ollama, openai, openrouter)", which) return nil, fmt.Errorf("unknown OLLIE_BACKEND %q (supported: ollama, openai, openrouter)", which)
} }