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
5eb77bf9
Unverified
Commit
5eb77bf9
authored
Aug 28, 2024
by
Michael Yang
Committed by
GitHub
Aug 28, 2024
Browse files
Merge pull request #6539 from ollama/mxyng/validate-modelpath
fix: validate modelpath
parents
7416ced7
8e6da3cb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
20 deletions
+26
-20
.golangci.yaml
.golangci.yaml
+4
-0
api/types.go
api/types.go
+9
-7
server/modelpath.go
server/modelpath.go
+5
-13
server/modelpath_test.go
server/modelpath_test.go
+8
-0
No files found.
.golangci.yaml
View file @
5eb77bf9
...
...
@@ -32,6 +32,10 @@ linters:
linters-settings
:
gci
:
sections
:
[
standard
,
default
,
localmodule
]
staticcheck
:
checks
:
-
all
-
-SA1019
# omit Deprecated check
severity
:
default-severity
:
error
rules
:
...
...
api/types.go
View file @
5eb77bf9
...
...
@@ -296,15 +296,17 @@ type EmbeddingResponse struct {
// CreateRequest is the request passed to [Client.Create].
type
CreateRequest
struct
{
Model
string
`json:"model"`
Path
string
`json:"path"`
Modelfile
string
`json:"modelfile"`
Stream
*
bool
`json:"stream,omitempty"`
Quantize
string
`json:"quantize,omitempty"`
//
Name is d
eprecated
,
se
e Model
//
D
eprecated
:
se
t the model name with Model instead
Name
string
`json:"name"`
// Quantization is deprecated, see Quantize
// Deprecated: set the file content with Modelfile instead
Path
string
`json:"path"`
// Deprecated: use Quantize instead
Quantization
string
`json:"quantization,omitempty"`
}
...
...
@@ -312,7 +314,7 @@ type CreateRequest struct {
type
DeleteRequest
struct
{
Model
string
`json:"model"`
//
Name is d
eprecated
,
se
e Model
//
D
eprecated
:
se
t the model name with Model instead
Name
string
`json:"name"`
}
...
...
@@ -327,7 +329,7 @@ type ShowRequest struct {
Options
map
[
string
]
interface
{}
`json:"options"`
//
Name is d
eprecated
,
se
e Model
//
D
eprecated
:
se
t the model name with Model instead
Name
string
`json:"name"`
}
...
...
@@ -359,7 +361,7 @@ type PullRequest struct {
Password
string
`json:"password"`
Stream
*
bool
`json:"stream,omitempty"`
//
Name is d
eprecated
,
se
e Model
//
D
eprecated
:
se
t the model name with Model instead
Name
string
`json:"name"`
}
...
...
@@ -380,7 +382,7 @@ type PushRequest struct {
Password
string
`json:"password"`
Stream
*
bool
`json:"stream,omitempty"`
//
Name is d
eprecated
,
se
e Model
//
D
eprecated
:
se
t the model name with Model instead
Name
string
`json:"name"`
}
...
...
server/modelpath.go
View file @
5eb77bf9
...
...
@@ -73,18 +73,6 @@ func ParseModelPath(name string) ModelPath {
var
errModelPathInvalid
=
errors
.
New
(
"invalid model path"
)
func
(
mp
ModelPath
)
Validate
()
error
{
if
mp
.
Repository
==
""
{
return
fmt
.
Errorf
(
"%w: model repository name is required"
,
errModelPathInvalid
)
}
if
strings
.
Contains
(
mp
.
Tag
,
":"
)
{
return
fmt
.
Errorf
(
"%w: ':' (colon) is not allowed in tag names"
,
errModelPathInvalid
)
}
return
nil
}
func
(
mp
ModelPath
)
GetNamespaceRepository
()
string
{
return
fmt
.
Sprintf
(
"%s/%s"
,
mp
.
Namespace
,
mp
.
Repository
)
}
...
...
@@ -105,7 +93,11 @@ func (mp ModelPath) GetShortTagname() string {
// GetManifestPath returns the path to the manifest file for the given model path, it is up to the caller to create the directory if it does not exist.
func
(
mp
ModelPath
)
GetManifestPath
()
(
string
,
error
)
{
return
filepath
.
Join
(
envconfig
.
Models
(),
"manifests"
,
mp
.
Registry
,
mp
.
Namespace
,
mp
.
Repository
,
mp
.
Tag
),
nil
if
p
:=
filepath
.
Join
(
mp
.
Registry
,
mp
.
Namespace
,
mp
.
Repository
,
mp
.
Tag
);
filepath
.
IsLocal
(
p
)
{
return
filepath
.
Join
(
envconfig
.
Models
(),
"manifests"
,
p
),
nil
}
return
""
,
errModelPathInvalid
}
func
(
mp
ModelPath
)
BaseURL
()
*
url
.
URL
{
...
...
server/modelpath_test.go
View file @
5eb77bf9
package
server
import
(
"errors"
"os"
"path/filepath"
"testing"
...
...
@@ -154,3 +155,10 @@ func TestParseModelPath(t *testing.T) {
})
}
}
func
TestInsecureModelpath
(
t
*
testing
.
T
)
{
mp
:=
ParseModelPath
(
"../../..:something"
)
if
_
,
err
:=
mp
.
GetManifestPath
();
!
errors
.
Is
(
err
,
errModelPathInvalid
)
{
t
.
Errorf
(
"expected error: %v"
,
err
)
}
}
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