From a5fdfad6ff6b91bb4dcb8134638f6e0f4208289b Mon Sep 17 00:00:00 2001 From: andreasjansson Date: Tue, 27 Feb 2024 14:42:15 -0800 Subject: [PATCH] Support repositories with more than three slash-delimited parts Some registries use URL schemes that have more than three slash-delimited parts. For example Google Artifact Registry has a format like `us-central1-docker.pkg.dev/PROJECT/NAMESPACE/REPOSITORY`. From Docker's and Ollama's point of view, `NAMESPACE/REPOSITORY` should all be treated as repository. --- server/modelpath.go | 2 +- server/modelpath_test.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/server/modelpath.go b/server/modelpath.go index af3f36ab..ed1cf2dc 100644 --- a/server/modelpath.go +++ b/server/modelpath.go @@ -47,7 +47,7 @@ func ParseModelPath(name string) ModelPath { } name = strings.ReplaceAll(name, string(os.PathSeparator), "/") - parts := strings.Split(name, "/") + parts := strings.SplitN(name, "/", 3) switch len(parts) { case 3: mp.Registry = parts[0] diff --git a/server/modelpath_test.go b/server/modelpath_test.go index 8b26d52c..45f63c5c 100644 --- a/server/modelpath_test.go +++ b/server/modelpath_test.go @@ -74,6 +74,17 @@ func TestParseModelPath(t *testing.T) { Tag: DefaultTag, }, }, + { + "path with more than three parts", + "https://example.com/ns/another-part/repo:tag", + ModelPath{ + ProtocolScheme: "https", + Registry: "example.com", + Namespace: "ns", + Repository: "another-part/repo", + Tag: "tag", + }, + }, } for _, tc := range tests {