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
2d305fa9
Commit
2d305fa9
authored
Jul 19, 2023
by
Jeffrey Morgan
Browse files
allow relative paths in `FROM` instruction
parent
e4d7f3e2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
28 deletions
+23
-28
server/images.go
server/images.go
+22
-18
server/routes.go
server/routes.go
+1
-10
No files found.
server/images.go
View file @
2d305fa9
...
...
@@ -137,21 +137,14 @@ func GetModel(name string) (*Model, error) {
return
model
,
nil
}
func
getAbsPath
(
fp
string
)
(
string
,
error
)
{
if
strings
.
HasPrefix
(
fp
,
"~/"
)
{
parts
:=
strings
.
Split
(
fp
,
"/"
)
home
,
err
:=
os
.
UserHomeDir
()
if
err
!=
nil
{
return
""
,
err
}
fp
=
filepath
.
Join
(
home
,
filepath
.
Join
(
parts
[
1
:
]
...
))
func
CreateModel
(
name
string
,
path
string
,
fn
func
(
status
string
))
error
{
mf
,
err
:=
os
.
Open
(
path
)
if
err
!=
nil
{
fn
(
fmt
.
Sprintf
(
"couldn't open modelfile '%s'"
,
path
))
return
fmt
.
Errorf
(
"failed to open file: %w"
,
err
)
}
defer
mf
.
Close
()
return
os
.
ExpandEnv
(
fp
),
nil
}
func
CreateModel
(
name
string
,
mf
io
.
Reader
,
fn
func
(
status
string
))
error
{
fn
(
"parsing modelfile"
)
commands
,
err
:=
parser
.
Parse
(
mf
)
if
err
!=
nil
{
...
...
@@ -169,11 +162,22 @@ func CreateModel(name string, mf io.Reader, fn func(status string)) error {
fn
(
"looking for model"
)
mf
,
err
:=
GetManifest
(
ParseModelPath
(
c
.
Arg
))
if
err
!=
nil
{
// if we couldn't read the manifest, try getting the bin file
fp
,
err
:=
getAbsPath
(
c
.
Arg
)
if
err
!=
nil
{
fn
(
"error determing path. exiting."
)
return
err
fp
:=
c
.
Arg
// If filePath starts with ~/, replace it with the user's home directory.
if
strings
.
HasPrefix
(
fp
,
"~/"
)
{
parts
:=
strings
.
Split
(
fp
,
"/"
)
home
,
err
:=
os
.
UserHomeDir
()
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to open file: %v"
,
err
)
}
fp
=
filepath
.
Join
(
home
,
filepath
.
Join
(
parts
[
1
:
]
...
))
}
// If filePath is not an absolute path, make it relative to the modelfile path
if
!
filepath
.
IsAbs
(
fp
)
{
fp
=
filepath
.
Join
(
filepath
.
Dir
(
path
),
fp
)
}
fn
(
"creating model layer"
)
...
...
server/routes.go
View file @
2d305fa9
...
...
@@ -144,15 +144,6 @@ func create(c *gin.Context) {
return
}
// NOTE consider passing the entire Modelfile in the json instead of the path to it
file
,
err
:=
os
.
Open
(
req
.
Path
)
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"message"
:
err
.
Error
()})
return
}
defer
file
.
Close
()
ch
:=
make
(
chan
any
)
go
func
()
{
defer
close
(
ch
)
...
...
@@ -162,7 +153,7 @@ func create(c *gin.Context) {
}
}
if
err
:=
CreateModel
(
req
.
Name
,
file
,
fn
);
err
!=
nil
{
if
err
:=
CreateModel
(
req
.
Name
,
req
.
Path
,
fn
);
err
!=
nil
{
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"message"
:
err
.
Error
()})
return
}
...
...
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