From d1b033c1685b9af28386780e61c2a2427dfddfcb Mon Sep 17 00:00:00 2001 From: Blake Mizerany Date: Wed, 13 Nov 2024 23:00:44 -0800 Subject: [PATCH] server: update checkNameExists to use case-insensitive name comparison This allows pulls, pushes, and other model operations to be performed with mixed-case names, which the Ollama registry supports. --- server/routes.go | 2 +- types/model/name.go | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/server/routes.go b/server/routes.go index c5fd3293..f6ebc5bc 100644 --- a/server/routes.go +++ b/server/routes.go @@ -628,7 +628,7 @@ func checkNameExists(name model.Name) error { } for n := range names { - if strings.EqualFold(n.Filepath(), name.Filepath()) && n != name { + if strings.EqualFold(n.Filepath(), name.Filepath()) && n.EqualFold(name) { return errors.New("a model with that name already exists") } } diff --git a/types/model/name.go b/types/model/name.go index 75b35ef7..9d819f10 100644 --- a/types/model/name.go +++ b/types/model/name.go @@ -298,6 +298,13 @@ func (n Name) LogValue() slog.Value { return slog.StringValue(n.String()) } +func (n Name) EqualFold(o Name) bool { + return strings.EqualFold(n.Host, o.Host) && + strings.EqualFold(n.Namespace, o.Namespace) && + strings.EqualFold(n.Model, o.Model) && + strings.EqualFold(n.Tag, o.Tag) +} + func isValidLen(kind partKind, s string) bool { switch kind { case kindHost: