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
37d95157
Unverified
Commit
37d95157
authored
Nov 21, 2023
by
Bruce MacDonald
Committed by
GitHub
Nov 21, 2023
Browse files
fix relative path on create (#1222)
parent
2eaa95b4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
13 deletions
+18
-13
server/images.go
server/images.go
+14
-9
server/routes.go
server/routes.go
+4
-4
No files found.
server/images.go
View file @
37d95157
...
@@ -228,10 +228,10 @@ func GetModel(name string) (*Model, error) {
...
@@ -228,10 +228,10 @@ func GetModel(name string) (*Model, error) {
return
model
,
nil
return
model
,
nil
}
}
func
realpath
(
p
string
)
string
{
func
realpath
(
mfDir
,
from
string
)
string
{
abspath
,
err
:=
filepath
.
Abs
(
p
)
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 {
...
@@ -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
,
"~/"
)
{
}
else
if
strings
.
HasPrefix
(
from
,
"~/"
)
{
return
filepath
.
Join
(
home
,
p
[
2
:
])
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
...
@@ -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
...
@@ -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
}
}
...
...
server/routes.go
View file @
37d95157
...
@@ -423,14 +423,14 @@ func CreateModelHandler(c *gin.Context) {
...
@@ -423,14 +423,14 @@ func CreateModelHandler(c *gin.Context) {
var
modelfile
io
.
Reader
=
strings
.
NewReader
(
req
.
Modelfile
)
var
modelfile
io
.
Reader
=
strings
.
NewReader
(
req
.
Modelfile
)
if
req
.
Path
!=
""
&&
req
.
Modelfile
==
""
{
if
req
.
Path
!=
""
&&
req
.
Modelfile
==
""
{
bin
,
err
:=
os
.
Open
(
req
.
Path
)
mf
,
err
:=
os
.
Open
(
req
.
Path
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
AbortWithStatusJSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
fmt
.
Sprintf
(
"error reading modelfile: %s"
,
err
)})
c
.
AbortWithStatusJSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
fmt
.
Sprintf
(
"error reading modelfile: %s"
,
err
)})
return
return
}
}
defer
bin
.
Close
()
defer
mf
.
Close
()
modelfile
=
bin
modelfile
=
mf
}
}
commands
,
err
:=
parser
.
Parse
(
modelfile
)
commands
,
err
:=
parser
.
Parse
(
modelfile
)
...
@@ -449,7 +449,7 @@ func CreateModelHandler(c *gin.Context) {
...
@@ -449,7 +449,7 @@ func CreateModelHandler(c *gin.Context) {
ctx
,
cancel
:=
context
.
WithCancel
(
c
.
Request
.
Context
())
ctx
,
cancel
:=
context
.
WithCancel
(
c
.
Request
.
Context
())
defer
cancel
()
defer
cancel
()
if
err
:=
CreateModel
(
ctx
,
req
.
Name
,
commands
,
fn
);
err
!=
nil
{
if
err
:=
CreateModel
(
ctx
,
req
.
Name
,
filepath
.
Dir
(
req
.
Path
),
commands
,
fn
);
err
!=
nil
{
ch
<-
gin
.
H
{
"error"
:
err
.
Error
()}
ch
<-
gin
.
H
{
"error"
:
err
.
Error
()}
}
}
}()
}()
...
...
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