|
@@ -228,10 +228,10 @@ func GetModel(name string) (*Model, error) {
|
|
return model, nil
|
|
return model, nil
|
|
}
|
|
}
|
|
|
|
|
|
-func realpath(p string) string {
|
|
|
|
- abspath, err := filepath.Abs(p)
|
|
|
|
|
|
+func realpath(mfDir, from string) string {
|
|
|
|
+ abspath, err := filepath.Abs(from)
|
|
if err != nil {
|
|
if err != nil {
|
|
- return p
|
|
|
|
|
|
+ return from
|
|
}
|
|
}
|
|
|
|
|
|
home, err := os.UserHomeDir()
|
|
home, err := os.UserHomeDir()
|
|
@@ -239,16 +239,21 @@ func realpath(p string) string {
|
|
return abspath
|
|
return abspath
|
|
}
|
|
}
|
|
|
|
|
|
- if p == "~" {
|
|
|
|
|
|
+ if from == "~" {
|
|
return home
|
|
return home
|
|
- } else if strings.HasPrefix(p, "~/") {
|
|
|
|
- return filepath.Join(home, p[2:])
|
|
|
|
|
|
+ } else if strings.HasPrefix(from, "~/") {
|
|
|
|
+ return filepath.Join(home, from[2:])
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if _, err := os.Stat(filepath.Join(mfDir, from)); err == nil {
|
|
|
|
+ // this is a file relative to the Modelfile
|
|
|
|
+ return filepath.Join(mfDir, from)
|
|
}
|
|
}
|
|
|
|
|
|
return abspath
|
|
return abspath
|
|
}
|
|
}
|
|
|
|
|
|
-func CreateModel(ctx context.Context, name string, commands []parser.Command, fn func(resp api.ProgressResponse)) error {
|
|
|
|
|
|
+func CreateModel(ctx context.Context, name, modelFileDir string, commands []parser.Command, fn func(resp api.ProgressResponse)) error {
|
|
config := ConfigV2{
|
|
config := ConfigV2{
|
|
OS: "linux",
|
|
OS: "linux",
|
|
Architecture: "amd64",
|
|
Architecture: "amd64",
|
|
@@ -276,7 +281,7 @@ func CreateModel(ctx context.Context, name string, commands []parser.Command, fn
|
|
c.Args = blobPath
|
|
c.Args = blobPath
|
|
}
|
|
}
|
|
|
|
|
|
- bin, err := os.Open(realpath(c.Args))
|
|
|
|
|
|
+ bin, err := os.Open(realpath(modelFileDir, c.Args))
|
|
if err != nil {
|
|
if err != nil {
|
|
// not a file on disk so must be a model reference
|
|
// not a file on disk so must be a model reference
|
|
modelpath := ParseModelPath(c.Args)
|
|
modelpath := ParseModelPath(c.Args)
|
|
@@ -372,7 +377,7 @@ func CreateModel(ctx context.Context, name string, commands []parser.Command, fn
|
|
layers = append(layers, layer)
|
|
layers = append(layers, layer)
|
|
case "adapter":
|
|
case "adapter":
|
|
fn(api.ProgressResponse{Status: "creating adapter layer"})
|
|
fn(api.ProgressResponse{Status: "creating adapter layer"})
|
|
- bin, err := os.Open(realpath(c.Args))
|
|
|
|
|
|
+ bin, err := os.Open(realpath(modelFileDir, c.Args))
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|