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
592dae31
Commit
592dae31
authored
Apr 16, 2024
by
Michael Yang
Browse files
update copy to use model.Name
parent
2010cbc5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
32 deletions
+30
-32
server/images.go
server/images.go
+12
-15
server/routes.go
server/routes.go
+18
-17
No files found.
server/images.go
View file @
592dae31
...
@@ -29,6 +29,7 @@ import (
...
@@ -29,6 +29,7 @@ import (
"github.com/ollama/ollama/format"
"github.com/ollama/ollama/format"
"github.com/ollama/ollama/llm"
"github.com/ollama/ollama/llm"
"github.com/ollama/ollama/parser"
"github.com/ollama/ollama/parser"
"github.com/ollama/ollama/types/model"
"github.com/ollama/ollama/version"
"github.com/ollama/ollama/version"
)
)
...
@@ -701,36 +702,32 @@ func convertModel(name, path string, fn func(resp api.ProgressResponse)) (string
...
@@ -701,36 +702,32 @@ func convertModel(name, path string, fn func(resp api.ProgressResponse)) (string
return
path
,
nil
return
path
,
nil
}
}
func
CopyModel
(
src
,
dest
string
)
error
{
func
CopyModel
(
src
,
dst
model
.
Name
)
error
{
srcModelPath
:=
ParseModelPath
(
src
)
manifests
,
err
:=
GetManifestPath
()
srcPath
,
err
:=
srcModelPath
.
GetManifestPath
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
destModelPath
:=
ParseModelPath
(
dest
)
dstpath
:=
filepath
.
Join
(
manifests
,
dst
.
FilepathNoBuild
())
destPath
,
err
:=
destModelPath
.
GetManifestPath
()
if
err
:=
os
.
MkdirAll
(
filepath
.
Dir
(
dstpath
),
0
o755
);
err
!=
nil
{
if
err
!=
nil
{
return
err
}
if
err
:=
os
.
MkdirAll
(
filepath
.
Dir
(
destPath
),
0
o755
);
err
!=
nil
{
return
err
return
err
}
}
// copy the file
srcpath
:=
filepath
.
Join
(
manifests
,
src
.
FilepathNoBuild
())
input
,
err
:=
os
.
ReadFile
(
src
P
ath
)
srcfile
,
err
:=
os
.
Open
(
src
p
ath
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
"Error reading file:"
,
err
)
return
err
return
err
}
}
defer
srcfile
.
Close
()
err
=
os
.
WriteFil
e
(
d
e
st
P
ath
,
input
,
0
o644
)
dstfile
,
err
:
=
os
.
Creat
e
(
dst
p
ath
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
"Error reading file:"
,
err
)
return
err
return
err
}
}
defer
dstfile
.
Close
()
return
nil
_
,
err
=
io
.
Copy
(
dstfile
,
srcfile
)
return
err
}
}
func
deleteUnusedLayers
(
skipModelPath
*
ModelPath
,
deleteMap
map
[
string
]
struct
{},
dryRun
bool
)
error
{
func
deleteUnusedLayers
(
skipModelPath
*
ModelPath
,
deleteMap
map
[
string
]
struct
{},
dryRun
bool
)
error
{
...
...
server/routes.go
View file @
592dae31
...
@@ -29,6 +29,7 @@ import (
...
@@ -29,6 +29,7 @@ import (
"github.com/ollama/ollama/llm"
"github.com/ollama/ollama/llm"
"github.com/ollama/ollama/openai"
"github.com/ollama/ollama/openai"
"github.com/ollama/ollama/parser"
"github.com/ollama/ollama/parser"
"github.com/ollama/ollama/types/model"
"github.com/ollama/ollama/version"
"github.com/ollama/ollama/version"
)
)
...
@@ -788,35 +789,35 @@ func (s *Server) ListModelsHandler(c *gin.Context) {
...
@@ -788,35 +789,35 @@ func (s *Server) ListModelsHandler(c *gin.Context) {
}
}
func
(
s
*
Server
)
CopyModelHandler
(
c
*
gin
.
Context
)
{
func
(
s
*
Server
)
CopyModelHandler
(
c
*
gin
.
Context
)
{
var
req
api
.
CopyRequest
var
r
api
.
CopyRequest
err
:=
c
.
ShouldBindJSON
(
&
req
)
if
err
:=
c
.
ShouldBindJSON
(
&
r
);
errors
.
Is
(
err
,
io
.
EOF
)
{
switch
{
case
errors
.
Is
(
err
,
io
.
EOF
)
:
c
.
AbortWithStatusJSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
"missing request body"
})
c
.
AbortWithStatusJSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
"missing request body"
})
return
return
case
err
!=
nil
:
}
else
if
err
!=
nil
{
c
.
AbortWithStatusJSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()})
c
.
AbortWithStatusJSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
return
}
}
if
req
.
Source
==
""
||
req
.
Destination
==
""
{
src
:=
model
.
ParseName
(
r
.
Source
)
c
.
AbortWithStatusJSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
"source add destination are required"
})
if
!
src
.
IsValid
()
{
return
_
=
c
.
Error
(
fmt
.
Errorf
(
"source %q is invalid"
,
r
.
Source
))
}
}
if
err
:=
ParseModelPath
(
req
.
Destination
)
.
Validate
();
err
!=
nil
{
dst
:=
model
.
ParseName
(
r
.
Destination
)
c
.
AbortWithStatusJSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()})
if
!
dst
.
IsValid
()
{
return
_
=
c
.
Error
(
fmt
.
Errorf
(
"destination %q is invalid"
,
r
.
Destination
))
}
}
if
err
:=
CopyModel
(
req
.
Source
,
req
.
Destination
);
err
!=
nil
{
if
len
(
c
.
Errors
)
>
0
{
if
os
.
IsNotExist
(
err
)
{
c
.
AbortWithStatusJSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
c
.
Errors
.
Errors
()})
c
.
JSON
(
http
.
StatusNotFound
,
gin
.
H
{
"error"
:
fmt
.
Sprintf
(
"model '%s' not found"
,
req
.
Source
)})
}
else
{
c
.
JSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
err
.
Error
()})
}
return
return
}
}
if
err
:=
CopyModel
(
src
,
dst
);
errors
.
Is
(
err
,
os
.
ErrNotExist
)
{
c
.
JSON
(
http
.
StatusNotFound
,
gin
.
H
{
"error"
:
fmt
.
Sprintf
(
"model %q not found"
,
r
.
Source
)})
}
else
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
err
.
Error
()})
}
}
}
func
(
s
*
Server
)
HeadBlobHandler
(
c
*
gin
.
Context
)
{
func
(
s
*
Server
)
HeadBlobHandler
(
c
*
gin
.
Context
)
{
...
...
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