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
8ebbd12f
"docs/vscode:/vscode.git/clone" did not exist on "e51862bbed41dba7ea5a9702d2f1a472df614ae7"
Commit
8ebbd12f
authored
Jul 24, 2023
by
Bruce MacDonald
Browse files
pull model on make if not present locally
parent
07971759
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
3 deletions
+29
-3
cmd/cmd.go
cmd/cmd.go
+29
-3
No files found.
cmd/cmd.go
View file @
8ebbd12f
...
...
@@ -21,6 +21,7 @@ import (
"github.com/jmorganca/ollama/api"
"github.com/jmorganca/ollama/format"
"github.com/jmorganca/ollama/parser"
"github.com/jmorganca/ollama/progressbar"
"github.com/jmorganca/ollama/server"
)
...
...
@@ -36,6 +37,24 @@ func CreateHandler(cmd *cobra.Command, args []string) error {
var
spinner
*
Spinner
// pull the model file if needed
mf
,
err
:=
os
.
Open
(
filename
)
defer
mf
.
Close
()
cmds
,
err
:=
parser
.
Parse
(
mf
)
if
err
!=
nil
{
return
err
}
mf
.
Close
()
for
_
,
c
:=
range
cmds
{
if
c
.
Name
==
"model"
{
// check if the model file needs to be pulled
checkPull
(
c
.
Args
)
}
}
if
err
!=
nil
{
return
err
}
request
:=
api
.
CreateRequest
{
Name
:
args
[
0
],
Path
:
filename
}
fn
:=
func
(
resp
api
.
CreateProgress
)
error
{
if
spinner
!=
nil
{
...
...
@@ -59,8 +78,8 @@ func CreateHandler(cmd *cobra.Command, args []string) error {
return
nil
}
func
RunHandler
(
cmd
*
cobra
.
Command
,
args
[]
string
)
error
{
mp
:=
server
.
ParseModelPath
(
args
[
0
]
)
func
checkPull
(
model
string
)
error
{
mp
:=
server
.
ParseModelPath
(
model
)
fp
,
err
:=
mp
.
GetManifestPath
(
false
)
if
err
!=
nil
{
return
err
...
...
@@ -69,7 +88,7 @@ func RunHandler(cmd *cobra.Command, args []string) error {
_
,
err
=
os
.
Stat
(
fp
)
switch
{
case
errors
.
Is
(
err
,
os
.
ErrNotExist
)
:
if
err
:=
pull
(
args
[
0
]
,
false
);
err
!=
nil
{
if
err
:=
pull
(
model
,
false
);
err
!=
nil
{
var
apiStatusError
api
.
StatusError
if
!
errors
.
As
(
err
,
&
apiStatusError
)
{
return
err
...
...
@@ -83,6 +102,13 @@ func RunHandler(cmd *cobra.Command, args []string) error {
return
err
}
return
nil
}
func
RunHandler
(
cmd
*
cobra
.
Command
,
args
[]
string
)
error
{
if
err
:=
checkPull
(
args
[
0
]);
err
!=
nil
{
return
err
}
return
RunGenerate
(
cmd
,
args
)
}
...
...
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