Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
cb1e0726
Unverified
Commit
cb1e0726
authored
May 01, 2024
by
Michael Yang
Committed by
GitHub
May 01, 2024
Browse files
Merge pull request #4087 from ollama/mxyng/fix-host-port
types/model: fix name for hostport
parents
68755f1f
997a4550
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
2 deletions
+55
-2
types/model/name.go
types/model/name.go
+12
-2
types/model/name_test.go
types/model/name_test.go
+43
-0
No files found.
types/model/name.go
View file @
cb1e0726
...
...
@@ -143,18 +143,28 @@ func ParseNameBare(s string) Name {
n
.
RawDigest
=
MissingPart
}
s
,
n
.
Tag
,
_
=
cutPromised
(
s
,
":"
)
// "/" is an illegal tag character, so we can use it to split the host
if
strings
.
LastIndex
(
s
,
":"
)
>
strings
.
LastIndex
(
s
,
"/"
)
{
s
,
n
.
Tag
,
_
=
cutPromised
(
s
,
":"
)
}
s
,
n
.
Model
,
promised
=
cutPromised
(
s
,
"/"
)
if
!
promised
{
n
.
Model
=
s
return
n
}
s
,
n
.
Namespace
,
promised
=
cutPromised
(
s
,
"/"
)
if
!
promised
{
n
.
Namespace
=
s
return
n
}
n
.
Host
=
s
scheme
,
host
,
ok
:=
strings
.
Cut
(
s
,
"://"
)
if
!
ok
{
host
=
scheme
}
n
.
Host
=
host
return
n
}
...
...
types/model/name_test.go
View file @
cb1e0726
package
model
import
(
"path/filepath"
"reflect"
"runtime"
"testing"
...
...
@@ -15,8 +16,19 @@ func TestParseNameParts(t *testing.T) {
cases
:=
[]
struct
{
in
string
want
Name
wantFilepath
string
wantValidDigest
bool
}{
{
in
:
"scheme://host:port/namespace/model:tag"
,
want
:
Name
{
Host
:
"host:port"
,
Namespace
:
"namespace"
,
Model
:
"model"
,
Tag
:
"tag"
,
},
wantFilepath
:
filepath
.
Join
(
"host:port"
,
"namespace"
,
"model"
,
"tag"
),
},
{
in
:
"host/namespace/model:tag"
,
want
:
Name
{
...
...
@@ -25,6 +37,17 @@ func TestParseNameParts(t *testing.T) {
Model
:
"model"
,
Tag
:
"tag"
,
},
wantFilepath
:
filepath
.
Join
(
"host"
,
"namespace"
,
"model"
,
"tag"
),
},
{
in
:
"host:port/namespace/model:tag"
,
want
:
Name
{
Host
:
"host:port"
,
Namespace
:
"namespace"
,
Model
:
"model"
,
Tag
:
"tag"
,
},
wantFilepath
:
filepath
.
Join
(
"host:port"
,
"namespace"
,
"model"
,
"tag"
),
},
{
in
:
"host/namespace/model"
,
...
...
@@ -33,6 +56,16 @@ func TestParseNameParts(t *testing.T) {
Namespace
:
"namespace"
,
Model
:
"model"
,
},
wantFilepath
:
filepath
.
Join
(
"host"
,
"namespace"
,
"model"
,
"latest"
),
},
{
in
:
"host:port/namespace/model"
,
want
:
Name
{
Host
:
"host:port"
,
Namespace
:
"namespace"
,
Model
:
"model"
,
},
wantFilepath
:
filepath
.
Join
(
"host:port"
,
"namespace"
,
"model"
,
"latest"
),
},
{
in
:
"namespace/model"
,
...
...
@@ -40,12 +73,14 @@ func TestParseNameParts(t *testing.T) {
Namespace
:
"namespace"
,
Model
:
"model"
,
},
wantFilepath
:
filepath
.
Join
(
"registry.ollama.ai"
,
"namespace"
,
"model"
,
"latest"
),
},
{
in
:
"model"
,
want
:
Name
{
Model
:
"model"
,
},
wantFilepath
:
filepath
.
Join
(
"registry.ollama.ai"
,
"library"
,
"model"
,
"latest"
),
},
{
in
:
"h/nn/mm:t"
,
...
...
@@ -55,6 +90,7 @@ func TestParseNameParts(t *testing.T) {
Model
:
"mm"
,
Tag
:
"t"
,
},
wantFilepath
:
filepath
.
Join
(
"h"
,
"nn"
,
"mm"
,
"t"
),
},
{
in
:
part80
+
"/"
+
part80
+
"/"
+
part80
+
":"
+
part80
,
...
...
@@ -64,6 +100,7 @@ func TestParseNameParts(t *testing.T) {
Model
:
part80
,
Tag
:
part80
,
},
wantFilepath
:
filepath
.
Join
(
part80
,
part80
,
part80
,
part80
),
},
{
in
:
part350
+
"/"
+
part80
+
"/"
+
part80
+
":"
+
part80
,
...
...
@@ -73,6 +110,7 @@ func TestParseNameParts(t *testing.T) {
Model
:
part80
,
Tag
:
part80
,
},
wantFilepath
:
filepath
.
Join
(
part350
,
part80
,
part80
,
part80
),
},
{
in
:
"@digest"
,
...
...
@@ -97,6 +135,11 @@ func TestParseNameParts(t *testing.T) {
if
!
reflect
.
DeepEqual
(
got
,
tt
.
want
)
{
t
.
Errorf
(
"parseName(%q) = %v; want %v"
,
tt
.
in
,
got
,
tt
.
want
)
}
got
=
ParseName
(
tt
.
in
)
if
tt
.
wantFilepath
!=
""
&&
got
.
Filepath
()
!=
tt
.
wantFilepath
{
t
.
Errorf
(
"parseName(%q).Filepath() = %q; want %q"
,
tt
.
in
,
got
.
Filepath
(),
tt
.
wantFilepath
)
}
})
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment