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
926ffa7f
Commit
926ffa7f
authored
Jul 06, 2023
by
Bruce MacDonald
Committed by
Jeffrey Morgan
Jul 06, 2023
Browse files
refactor cmd
parent
4a36f374
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
25 deletions
+10
-25
cmd/cmd.go
cmd/cmd.go
+10
-25
No files found.
cmd/cmd.go
View file @
926ffa7f
...
@@ -14,36 +14,17 @@ import (
...
@@ -14,36 +14,17 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/cobra"
)
)
func
sockpath
()
string
{
func
cacheDir
()
string
{
home
,
err
:=
os
.
UserHomeDir
()
home
,
err
:=
os
.
UserHomeDir
()
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
panic
(
err
)
}
}
return
path
.
Join
(
home
,
".ollama"
,
"ollama.sock"
)
return
path
.
Join
(
home
,
".ollama"
)
}
func
running
()
bool
{
// Set a timeout duration
timeout
:=
time
.
Second
// Dial the unix socket
conn
,
err
:=
net
.
DialTimeout
(
"unix"
,
sockpath
(),
timeout
)
if
err
!=
nil
{
return
false
}
if
conn
!=
nil
{
defer
conn
.
Close
()
}
return
true
}
}
func
serve
()
error
{
func
serve
()
error
{
sp
:=
sockpath
()
sp
:=
path
.
Join
(
cacheDir
(),
"ollama.sock"
)
if
err
:=
os
.
MkdirAll
(
path
.
Dir
(
sp
),
0
o700
);
err
!=
nil
{
return
err
}
if
err
:=
os
.
RemoveAll
(
sp
);
err
!=
nil
{
if
err
:=
os
.
RemoveAll
(
sp
);
err
!=
nil
{
return
err
return
err
...
@@ -99,6 +80,10 @@ func NewCLI() *cobra.Command {
...
@@ -99,6 +80,10 @@ func NewCLI() *cobra.Command {
PersistentPreRun
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
PersistentPreRun
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
// Disable usage printing on errors
// Disable usage printing on errors
cmd
.
SilenceUsage
=
true
cmd
.
SilenceUsage
=
true
// create the models directory and it's parent
if
err
:=
os
.
MkdirAll
(
path
.
Join
(
cacheDir
(),
"models"
),
0
o700
);
err
!=
nil
{
panic
(
err
)
}
},
},
}
}
...
@@ -108,7 +93,7 @@ func NewCLI() *cobra.Command {
...
@@ -108,7 +93,7 @@ func NewCLI() *cobra.Command {
Use
:
"run MODEL"
,
Use
:
"run MODEL"
,
Short
:
"Run a model"
,
Short
:
"Run a model"
,
Args
:
cobra
.
ExactArgs
(
1
),
Args
:
cobra
.
ExactArgs
(
1
),
RunE
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
error
{
RunE
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
error
{
return
nil
return
nil
},
},
}
}
...
...
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