move model struct

This commit is contained in:
Patrick Devine 2023-07-16 17:00:09 -07:00
parent 2e1394e405
commit e6d0062c13
2 changed files with 15 additions and 32 deletions

View File

@ -23,7 +23,12 @@ import (
var DefaultRegistry string = "https://registry.ollama.ai"
//var DefaultRegistry string = "http://localhost:6000"
type Model struct {
Name string `json:"name"`
ModelPath string
Prompt string
Options api.Options
}
type ManifestV2 struct {
SchemaVersion int `json:"schemaVersion"`
@ -61,7 +66,7 @@ func GetManifest(name string) (*ManifestV2, error) {
return nil, err
}
fp := path.Join(home, ".ollama/models/manifests", name)
fp := filepath.Join(home, ".ollama/models/manifests", name)
_, err = os.Stat(fp)
if os.IsNotExist(err) {
return nil, fmt.Errorf("couldn't find model '%s'", name)
@ -99,7 +104,7 @@ func GetModel(name string) (*Model, error) {
}
for _, layer := range manifest.Layers {
filename := path.Join(home, ".ollama/models/blobs", layer.Digest)
filename := filepath.Join(home, ".ollama/models/blobs", layer.Digest)
switch layer.MediaType {
case "application/vnd.ollama.image.model":
model.ModelPath = filename
@ -284,7 +289,7 @@ func SaveLayers(layers []*LayerWithBuffer, fn func(status string), force bool) e
return err
}
dir := path.Join(home, ".ollama/models/blobs")
dir := filepath.Join(home, ".ollama/models/blobs")
err = os.MkdirAll(dir, 0o700)
if err != nil {
@ -293,7 +298,7 @@ func SaveLayers(layers []*LayerWithBuffer, fn func(status string), force bool) e
// Write each of the layers to disk
for _, layer := range layers {
fp := path.Join(dir, layer.Digest)
fp := filepath.Join(dir, layer.Digest)
_, err = os.Stat(fp)
if os.IsNotExist(err) || force {
@ -340,7 +345,7 @@ func CreateManifest(name string, cfg *LayerWithBuffer, layers []*Layer) error {
return err
}
fp := path.Join(home, ".ollama/models/manifests", name)
fp := filepath.Join(home, ".ollama/models/manifests", name)
err = os.WriteFile(fp, manifestJSON, 0644)
if err != nil {
log.Printf("couldn't write to %s", fp)
@ -355,7 +360,7 @@ func GetLayerWithBufferFromLayer(layer *Layer) (*LayerWithBuffer, error) {
return nil, err
}
fp := path.Join(home, ".ollama/models/blobs", layer.Digest)
fp := filepath.Join(home, ".ollama/models/blobs", layer.Digest)
file, err := os.Open(fp)
if err != nil {
return nil, fmt.Errorf("could not open blob: %w", err)
@ -559,7 +564,7 @@ func PullModel(name, username, password string, fn func(status, digest string, T
return err
}
fp := path.Join(home, ".ollama/models/manifests", name)
fp := filepath.Join(home, ".ollama/models/manifests", name)
err = os.MkdirAll(path.Dir(fp), 0o700)
if err != nil {
@ -699,7 +704,7 @@ func uploadBlob(location string, layer *Layer, username string, password string)
// TODO allow canceling uploads via DELETE
// TODO allow cross repo blob mount
fp := path.Join(home, ".ollama/models/blobs", layer.Digest)
fp := filepath.Join(home, ".ollama/models/blobs", layer.Digest)
f, err := os.Open(fp)
if err != nil {
return err
@ -727,7 +732,7 @@ func downloadBlob(registryURL, repoName, digest string, username, password strin
return err
}
fp := path.Join(home, ".ollama/models/blobs", digest)
fp := filepath.Join(home, ".ollama/models/blobs", digest)
_, err = os.Stat(fp)
if !os.IsNotExist(err) {

View File

@ -1,22 +0,0 @@
package server
import (
"github.com/jmorganca/ollama/api"
)
type Model struct {
Name string `json:"name"`
ModelPath string
Prompt string
Options api.Options
DisplayName string `json:"display_name"`
Parameters string `json:"parameters"`
URL string `json:"url"`
ShortDescription string `json:"short_description"`
Description string `json:"description"`
PublishedBy string `json:"published_by"`
OriginalAuthor string `json:"original_author"`
OriginalURL string `json:"original_url"`
License string `json:"license"`
}