backend: require OLLIE_BACKEND/OLLIE_MODEL; no silent ollama default
- NewWithName and newFromEnv now error when OLLIE_BACKEND is unset instead of falling back to ollama silently - createSession reads OLLIE_MODEL as fallback when model= is not given - Update test to assert error on missing OLLIE_BACKEND Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
b54c5c08f9
commit
c7ad2ca68a
|
|
@ -59,13 +59,13 @@ func New() (Backend, error) {
|
|||
|
||||
// NewWithName constructs a Backend for the given backend name, loading
|
||||
// env-file defaults for API keys/URLs but ignoring OLLIE_BACKEND.
|
||||
// If name is empty, falls back to OLLIE_BACKEND / "ollama".
|
||||
// If name is empty, falls back to OLLIE_BACKEND; errors if neither is set.
|
||||
func NewWithName(name string) (Backend, error) {
|
||||
loadEnvFile(paths.CfgDir() + "/env")
|
||||
if name == "" {
|
||||
name = os.Getenv("OLLIE_BACKEND")
|
||||
if name == "" {
|
||||
name = "ollama"
|
||||
return nil, fmt.Errorf("no backend specified: set OLLIE_BACKEND or pass backend= to the session")
|
||||
}
|
||||
}
|
||||
return newBackend(name)
|
||||
|
|
@ -76,7 +76,7 @@ func newFromEnv(envFile string) (Backend, error) {
|
|||
|
||||
which := os.Getenv("OLLIE_BACKEND")
|
||||
if which == "" {
|
||||
which = "ollama"
|
||||
return nil, fmt.Errorf("OLLIE_BACKEND is not set")
|
||||
}
|
||||
|
||||
return newBackend(which)
|
||||
|
|
|
|||
|
|
@ -31,14 +31,11 @@ func clearEnv(t *testing.T, keys ...string) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestNewFromEnv_DefaultOllama(t *testing.T) {
|
||||
func TestNewFromEnv_NoBackendErrors(t *testing.T) {
|
||||
clearEnv(t, "OLLIE_BACKEND", "OLLIE_OLLAMA_URL")
|
||||
b, err := newFromEnv("/nonexistent")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if b.Name() != "ollama" {
|
||||
t.Errorf("name = %q; want ollama", b.Name())
|
||||
_, err := newFromEnv("/nonexistent")
|
||||
if err == nil {
|
||||
t.Fatal("expected error when OLLIE_BACKEND is unset, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -357,6 +357,9 @@ func (s *SessionStore) createSession(args []string) error {
|
|||
return fmt.Errorf("backend: %w", err)
|
||||
}
|
||||
|
||||
if modelOverride == "" {
|
||||
modelOverride = os.Getenv("OLLIE_MODEL")
|
||||
}
|
||||
if modelOverride != "" {
|
||||
be.SetModel(modelOverride)
|
||||
}
|
||||
|
|
|
|||
Reference in New Issue