refactor cmd
This commit is contained in:
parent
4a36f374a2
commit
926ffa7f8c
1 changed files with 10 additions and 25 deletions
35
cmd/cmd.go
35
cmd/cmd.go
|
@ -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), 0o700); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := os.RemoveAll(sp); err != nil {
|
if err := os.RemoveAll(sp); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -99,16 +80,20 @@ 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"), 0o700); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
cobra.EnableCommandSorting = false
|
cobra.EnableCommandSorting = false
|
||||||
|
|
||||||
runCmd := &cobra.Command{
|
runCmd := &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
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue