Respect ollama model baseUrl before default
Some checks are pending
ci / test (macos-latest) (push) Waiting to run
ci / test (ubuntu-latest) (push) Waiting to run
ci / test (windows-latest) (push) Waiting to run

This commit is contained in:
patriceckhart 2026-06-08 07:41:05 +02:00
parent 7da9114a05
commit a7ef8c22a1
2 changed files with 44 additions and 4 deletions

View file

@ -305,9 +305,6 @@ func Resolve(args Args, requireCred bool) (Resolved, error) {
credErr error
)
if provName == "ollama" {
if args.BaseURL == "" {
args.BaseURL = "http://localhost:11434"
}
cred = firstNonEmpty(args.APIKey, "ollama")
method = "apikey"
} else {
@ -398,10 +395,15 @@ func Resolve(args Args, requireCred bool) (Resolved, error) {
}
// If the model defines a base URL (e.g. local ollama) and the
// user didn't pass --base-url, use the model's URL.
// user didn't pass --base-url, use the model's URL. For ollama,
// keep http://localhost:11434 as a fallback only after the model
// metadata has had a chance to provide a custom baseUrl.
if args.BaseURL == "" && resolvedModel.BaseURL != "" {
args.BaseURL = resolvedModel.BaseURL
}
if args.BaseURL == "" && provName == "ollama" {
args.BaseURL = "http://localhost:11434"
}
// If the model has a base URL, credentials are optional (local
// models like ollama don't need real API keys).

View file

@ -5,6 +5,8 @@ import (
"path/filepath"
"strings"
"testing"
"github.com/patriceckhart/zot/packages/provider"
)
func TestReadAgentsContextLoadsGlobalAndAncestors(t *testing.T) {
@ -109,6 +111,42 @@ func TestResolveExplicitFlagStaleDoesNotRepairConfig(t *testing.T) {
}
}
func TestResolveOllamaUsesModelBaseURLBeforeDefault(t *testing.T) {
t.Setenv("ZOT_HOME", t.TempDir())
provider.SetLiveModels(nil)
defer provider.SetLiveModels(nil)
provider.SetUserModels([]provider.Model{{
Provider: "ollama",
ID: "qwen-local",
DisplayName: "Qwen Local",
ContextWindow: 32768,
MaxOutput: 8192,
BaseURL: "http://localhost:8000/v1",
}})
r, err := Resolve(Args{Provider: "ollama", Model: "qwen-local"}, false)
if err != nil {
t.Fatalf("Resolve failed: %v", err)
}
if r.BaseURL != "http://localhost:8000/v1" {
t.Fatalf("BaseURL = %q, want models.json baseUrl", r.BaseURL)
}
}
func TestResolveOllamaFallsBackToDefaultBaseURL(t *testing.T) {
t.Setenv("ZOT_HOME", t.TempDir())
provider.SetLiveModels(nil)
defer provider.SetLiveModels(nil)
r, err := Resolve(Args{Provider: "ollama", Model: "any-local-model"}, false)
if err != nil {
t.Fatalf("Resolve failed: %v", err)
}
if r.BaseURL != "http://localhost:11434" {
t.Fatalf("BaseURL = %q, want ollama default", r.BaseURL)
}
}
func TestCanonicalProviderResolvesAliases(t *testing.T) {
cases := map[string]string{
"bedrock": "amazon-bedrock",