This commit is contained in:
Josh Yan 2024-07-29 14:37:21 -07:00
parent 18203bf8d8
commit 86a874fceb
4 changed files with 19 additions and 19 deletions

View File

@ -139,7 +139,7 @@ func ParseFile(r io.Reader) (*File, error) {
} }
continue continue
} else if isSpace(r){ } else if isSpace(r) {
return nil, errInvalidVersion return nil, errInvalidVersion
} else if _, err := semver.NewVersion(s); err != nil { } else if _, err := semver.NewVersion(s); err != nil {
return nil, errInvalidVersion return nil, errInvalidVersion

View File

@ -550,7 +550,7 @@ func CreateModel(ctx context.Context, name model.Name, modelFileDir, quantizatio
} }
} }
} }
} }
var err2 error var err2 error
layers = slices.DeleteFunc(layers, func(layer *Layer) bool { layers = slices.DeleteFunc(layers, func(layer *Layer) bool {

View File

@ -18,7 +18,7 @@ type Manifest struct {
MediaType string `json:"mediaType"` MediaType string `json:"mediaType"`
Config *Layer `json:"config"` Config *Layer `json:"config"`
Layers []*Layer `json:"layers"` Layers []*Layer `json:"layers"`
Ollama string `json:"ollama"` Ollama string `json:"ollama"`
filepath string filepath string
fi os.FileInfo fi os.FileInfo
@ -116,7 +116,7 @@ func WriteManifest(name model.Name, config *Layer, layers []*Layer, ollama strin
MediaType: "application/vnd.docker.distribution.manifest.v2+json", MediaType: "application/vnd.docker.distribution.manifest.v2+json",
Config: config, Config: config,
Layers: layers, Layers: layers,
Ollama: ollama, Ollama: ollama,
} }
return json.NewEncoder(f).Encode(m) return json.NewEncoder(f).Encode(m)

View File

@ -498,7 +498,7 @@ func TestCreateTemplateSystem(t *testing.T) {
Modelfile: fmt.Sprintf("FROM %s\nTEMPLATE {{ .Prompt", createBinFile(t, nil, nil)), Modelfile: fmt.Sprintf("FROM %s\nTEMPLATE {{ .Prompt", createBinFile(t, nil, nil)),
Stream: &stream, Stream: &stream,
}) })
if w.Code != http.StatusBadRequest { if w.Code != http.StatusBadRequest {
t.Fatalf("expected status code 400, actual %d", w.Code) t.Fatalf("expected status code 400, actual %d", w.Code)
} }
@ -510,7 +510,7 @@ func TestCreateTemplateSystem(t *testing.T) {
Modelfile: fmt.Sprintf("FROM %s\nTEMPLATE {{ if .Prompt }}", createBinFile(t, nil, nil)), Modelfile: fmt.Sprintf("FROM %s\nTEMPLATE {{ if .Prompt }}", createBinFile(t, nil, nil)),
Stream: &stream, Stream: &stream,
}) })
if w.Code != http.StatusBadRequest { if w.Code != http.StatusBadRequest {
t.Fatalf("expected status code 400, actual %d", w.Code) t.Fatalf("expected status code 400, actual %d", w.Code)
} }
@ -522,7 +522,7 @@ func TestCreateTemplateSystem(t *testing.T) {
Modelfile: fmt.Sprintf("FROM %s\nTEMPLATE {{ Prompt }}", createBinFile(t, nil, nil)), Modelfile: fmt.Sprintf("FROM %s\nTEMPLATE {{ Prompt }}", createBinFile(t, nil, nil)),
Stream: &stream, Stream: &stream,
}) })
if w.Code != http.StatusBadRequest { if w.Code != http.StatusBadRequest {
t.Fatalf("expected status code 400, actual %d", w.Code) t.Fatalf("expected status code 400, actual %d", w.Code)
} }
@ -624,7 +624,7 @@ func TestCreateDetectTemplate(t *testing.T) {
}) })
} }
func TestCreateVersion(t *testing.T){ func TestCreateVersion(t *testing.T) {
gin.SetMode(gin.TestMode) gin.SetMode(gin.TestMode)
p := t.TempDir() p := t.TempDir()
@ -640,12 +640,12 @@ func TestCreateVersion(t *testing.T){
if w.Code != http.StatusOK { if w.Code != http.StatusOK {
t.Fatalf("expected status code 200, actual %d", w.Code) t.Fatalf("expected status code 200, actual %d", w.Code)
} }
checkFileExists(t, filepath.Join(p, "manifests", "*", "*", "*", "*"), []string{ checkFileExists(t, filepath.Join(p, "manifests", "*", "*", "*", "*"), []string{
filepath.Join(p, "manifests", "registry.ollama.ai", "library", "test", "latest"), filepath.Join(p, "manifests", "registry.ollama.ai", "library", "test", "latest"),
}) })
f, err := os.Open(filepath.Join(p, "manifests", "registry.ollama.ai", "library", "test", "latest")) f, err := os.Open(filepath.Join(p, "manifests", "registry.ollama.ai", "library", "test", "latest"))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -667,11 +667,11 @@ func TestCreateVersion(t *testing.T){
Modelfile: fmt.Sprintf("FROM %s\nLICENSE MIT\nLICENSE Apache-2.0", createBinFile(t, nil, nil)), Modelfile: fmt.Sprintf("FROM %s\nLICENSE MIT\nLICENSE Apache-2.0", createBinFile(t, nil, nil)),
Stream: &stream, Stream: &stream,
}) })
if w.Code != http.StatusOK { if w.Code != http.StatusOK {
t.Fatalf("expected status code 200, actual %d", w.Code) t.Fatalf("expected status code 200, actual %d", w.Code)
} }
checkFileExists(t, filepath.Join(p, "manifests", "*", "*", "noversion", "*"), []string{ checkFileExists(t, filepath.Join(p, "manifests", "*", "*", "noversion", "*"), []string{
filepath.Join(p, "manifests", "registry.ollama.ai", "library", "noversion", "latest"), filepath.Join(p, "manifests", "registry.ollama.ai", "library", "noversion", "latest"),
}) })
@ -686,7 +686,7 @@ func TestCreateVersion(t *testing.T){
if err := bts.Decode(&m); err != nil { if err := bts.Decode(&m); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if m.Ollama != "" { if m.Ollama != "" {
t.Errorf("got %s != want \"\"", m.Ollama) t.Errorf("got %s != want \"\"", m.Ollama)
} }
@ -713,25 +713,25 @@ func TestCreateVersion(t *testing.T){
if w.Code != http.StatusOK { if w.Code != http.StatusOK {
t.Fatalf("expected status code 200, actual %d", w.Code) t.Fatalf("expected status code 200, actual %d", w.Code)
} }
checkFileExists(t, filepath.Join(p, "manifests", "*", "*", "fromvalid", "*"), []string{ checkFileExists(t, filepath.Join(p, "manifests", "*", "*", "fromvalid", "*"), []string{
filepath.Join(p, "manifests", "registry.ollama.ai", "library", "fromvalid", "latest"), filepath.Join(p, "manifests", "registry.ollama.ai", "library", "fromvalid", "latest"),
}) })
f, err := os.Open(filepath.Join(p, "manifests", "registry.ollama.ai", "library", "fromvalid", "latest")) f, err := os.Open(filepath.Join(p, "manifests", "registry.ollama.ai", "library", "fromvalid", "latest"))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
bts := json.NewDecoder(f) bts := json.NewDecoder(f)
var m Manifest var m Manifest
if err := bts.Decode(&m); err != nil { if err := bts.Decode(&m); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if m.Ollama != "0.2.3" { if m.Ollama != "0.2.3" {
t.Errorf("got %s != want 0.2.3", m.Ollama) t.Errorf("got %s != want 0.2.3", m.Ollama)
} }
}) })
} }