ollama/cmd/cmd.go

827 lines
18 KiB
Go
Raw Normal View History

package cmd
import (
2023-07-06 20:49:31 +00:00
"bufio"
"context"
"crypto/ed25519"
"crypto/rand"
"encoding/pem"
2023-07-06 22:43:04 +00:00
"errors"
2023-07-06 16:24:49 +00:00
"fmt"
2023-07-18 21:01:19 +00:00
"io"
"log"
"net"
2023-07-11 20:05:51 +00:00
"net/http"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
2023-07-07 17:12:58 +00:00
"strings"
2023-07-06 22:43:04 +00:00
"time"
2023-07-18 21:01:19 +00:00
"github.com/chzyer/readline"
2023-07-18 16:09:45 +00:00
"github.com/dustin/go-humanize"
"github.com/olekukonko/tablewriter"
2023-07-06 20:49:31 +00:00
"github.com/spf13/cobra"
"golang.org/x/crypto/ssh"
2023-07-06 20:49:31 +00:00
2023-07-03 20:32:48 +00:00
"github.com/jmorganca/ollama/api"
2023-07-18 16:09:45 +00:00
"github.com/jmorganca/ollama/format"
"github.com/jmorganca/ollama/progressbar"
2023-07-03 20:32:48 +00:00
"github.com/jmorganca/ollama/server"
2023-08-22 01:24:42 +00:00
"github.com/jmorganca/ollama/version"
)
2023-07-20 23:09:23 +00:00
func CreateHandler(cmd *cobra.Command, args []string) error {
filename, _ := cmd.Flags().GetString("file")
filename, err := filepath.Abs(filename)
if err != nil {
return err
}
client, err := api.FromEnv()
if err != nil {
return err
}
2023-07-17 21:14:41 +00:00
var spinner *Spinner
var currentDigest string
var bar *progressbar.ProgressBar
2023-07-17 21:14:41 +00:00
request := api.CreateRequest{Name: args[0], Path: filename}
fn := func(resp api.ProgressResponse) error {
if resp.Digest != currentDigest && resp.Digest != "" {
if spinner != nil {
spinner.Stop()
}
currentDigest = resp.Digest
2023-08-04 22:56:40 +00:00
switch {
case strings.Contains(resp.Status, "embeddings"):
bar = progressbar.Default(int64(resp.Total), resp.Status)
bar.Set(resp.Completed)
default:
// pulling
bar = progressbar.DefaultBytes(
int64(resp.Total),
resp.Status,
)
bar.Set(resp.Completed)
}
} else if resp.Digest == currentDigest && resp.Digest != "" {
bar.Set(resp.Completed)
} else {
currentDigest = ""
if spinner != nil {
spinner.Stop()
}
spinner = NewSpinner(resp.Status)
go spinner.Spin(100 * time.Millisecond)
}
2023-08-14 18:15:53 +00:00
return nil
}
if err := client.Create(context.Background(), &request, fn); err != nil {
return err
}
2023-07-17 21:14:41 +00:00
if spinner != nil {
spinner.Stop()
2023-08-14 18:15:53 +00:00
if spinner.description != "success" {
return errors.New("unexpected end to create model")
}
2023-07-17 21:14:41 +00:00
}
return nil
}
func RunHandler(cmd *cobra.Command, args []string) error {
2023-08-22 04:56:56 +00:00
insecure, err := cmd.Flags().GetBool("insecure")
if err != nil {
return err
}
mp := server.ParseModelPath(args[0])
2023-08-22 04:56:56 +00:00
if err != nil {
return err
}
if mp.ProtocolScheme == "http" && !insecure {
return fmt.Errorf("insecure protocol http")
}
2023-07-18 05:44:21 +00:00
fp, err := mp.GetManifestPath(false)
if err != nil {
return err
}
_, err = os.Stat(fp)
2023-07-06 22:43:04 +00:00
switch {
case errors.Is(err, os.ErrNotExist):
2023-08-22 04:56:56 +00:00
if err := pull(args[0], insecure); err != nil {
2023-07-11 20:05:51 +00:00
var apiStatusError api.StatusError
if !errors.As(err, &apiStatusError) {
return err
}
if apiStatusError.StatusCode != http.StatusBadGateway {
return err
}
2023-07-06 22:43:04 +00:00
}
case err != nil:
2023-07-06 21:05:55 +00:00
return err
}
return RunGenerate(cmd, args)
2023-07-06 18:18:40 +00:00
}
2023-07-20 23:09:23 +00:00
func PushHandler(cmd *cobra.Command, args []string) error {
client, err := api.FromEnv()
if err != nil {
return err
}
insecure, err := cmd.Flags().GetBool("insecure")
if err != nil {
return err
}
var currentDigest string
var bar *progressbar.ProgressBar
request := api.PushRequest{Name: args[0], Insecure: insecure}
2023-07-19 01:51:30 +00:00
fn := func(resp api.ProgressResponse) error {
if resp.Digest != currentDigest && resp.Digest != "" {
currentDigest = resp.Digest
bar = progressbar.DefaultBytes(
int64(resp.Total),
fmt.Sprintf("pushing %s...", resp.Digest[7:19]),
)
bar.Set(resp.Completed)
} else if resp.Digest == currentDigest && resp.Digest != "" {
bar.Set(resp.Completed)
} else {
currentDigest = ""
fmt.Println(resp.Status)
}
return nil
}
if err := client.Push(context.Background(), &request, fn); err != nil {
return err
}
2023-08-14 18:15:53 +00:00
if bar != nil && !bar.IsFinished() {
return errors.New("unexpected end to push model")
}
return nil
}
2023-07-20 23:09:23 +00:00
func ListHandler(cmd *cobra.Command, args []string) error {
client, err := api.FromEnv()
if err != nil {
return err
}
2023-07-18 16:09:45 +00:00
models, err := client.List(context.Background())
if err != nil {
return err
}
var data [][]string
for _, m := range models.Models {
2023-07-18 21:01:19 +00:00
if len(args) == 0 || strings.HasPrefix(m.Name, args[0]) {
2023-08-29 03:50:24 +00:00
data = append(data, []string{m.Name, m.Digest[:12], humanize.Bytes(uint64(m.Size)), format.HumanTime(m.ModifiedAt, "Never")})
2023-07-18 21:01:19 +00:00
}
2023-07-18 16:09:45 +00:00
}
table := tablewriter.NewWriter(os.Stdout)
2023-08-29 03:50:24 +00:00
table.SetHeader([]string{"NAME", "ID", "SIZE", "MODIFIED"})
2023-07-18 16:09:45 +00:00
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetHeaderLine(false)
table.SetBorder(false)
table.SetNoWhiteSpace(true)
table.SetTablePadding("\t")
table.AppendBulk(data)
table.Render()
return nil
}
2023-07-20 23:09:23 +00:00
func DeleteHandler(cmd *cobra.Command, args []string) error {
client, err := api.FromEnv()
if err != nil {
return err
}
2023-07-20 23:09:23 +00:00
for _, name := range args {
req := api.DeleteRequest{Name: name}
if err := client.Delete(context.Background(), &req); err != nil {
return err
}
fmt.Printf("deleted '%s'\n", name)
2023-07-20 23:09:23 +00:00
}
return nil
}
2023-07-24 15:27:28 +00:00
func CopyHandler(cmd *cobra.Command, args []string) error {
client, err := api.FromEnv()
if err != nil {
return err
}
2023-07-24 15:27:28 +00:00
req := api.CopyRequest{Source: args[0], Destination: args[1]}
if err := client.Copy(context.Background(), &req); err != nil {
return err
}
fmt.Printf("copied '%s' to '%s'\n", args[0], args[1])
return nil
}
2023-07-20 23:09:23 +00:00
func PullHandler(cmd *cobra.Command, args []string) error {
insecure, err := cmd.Flags().GetBool("insecure")
if err != nil {
return err
}
return pull(args[0], insecure)
}
func pull(model string, insecure bool) error {
client, err := api.FromEnv()
if err != nil {
return err
}
2023-07-19 01:51:30 +00:00
var currentDigest string
2023-07-07 18:26:58 +00:00
var bar *progressbar.ProgressBar
2023-07-11 20:05:51 +00:00
request := api.PullRequest{Name: model, Insecure: insecure}
2023-07-19 01:51:30 +00:00
fn := func(resp api.ProgressResponse) error {
if resp.Digest != currentDigest && resp.Digest != "" {
currentDigest = resp.Digest
bar = progressbar.DefaultBytes(
int64(resp.Total),
2023-07-19 01:51:30 +00:00
fmt.Sprintf("pulling %s...", resp.Digest[7:19]),
)
2023-07-19 01:51:30 +00:00
bar.Set(resp.Completed)
} else if resp.Digest == currentDigest && resp.Digest != "" {
bar.Set(resp.Completed)
} else {
2023-07-19 01:51:30 +00:00
currentDigest = ""
fmt.Println(resp.Status)
}
2023-08-14 18:15:53 +00:00
return nil
}
2023-07-07 14:22:37 +00:00
if err := client.Pull(context.Background(), &request, fn); err != nil {
return err
}
2023-08-14 18:15:53 +00:00
if bar != nil && !bar.IsFinished() {
return errors.New("unexpected end to pull model")
}
return nil
2023-07-06 20:49:31 +00:00
}
2023-07-13 01:18:06 +00:00
func RunGenerate(cmd *cobra.Command, args []string) error {
2023-07-06 20:49:31 +00:00
if len(args) > 1 {
2023-07-12 16:55:07 +00:00
// join all args into a single prompt
2023-07-13 01:18:06 +00:00
return generate(cmd, args[0], strings.Join(args[1:], " "))
2023-07-06 20:49:31 +00:00
}
2023-07-18 21:01:19 +00:00
if readline.IsTerminal(int(os.Stdin.Fd())) {
2023-07-13 01:18:06 +00:00
return generateInteractive(cmd, args[0])
2023-07-06 20:49:31 +00:00
}
2023-07-13 01:18:06 +00:00
return generateBatch(cmd, args[0])
2023-07-06 20:49:31 +00:00
}
2023-07-18 18:59:42 +00:00
type generateContextKey string
2023-07-13 01:18:06 +00:00
func generate(cmd *cobra.Command, model, prompt string) error {
2023-07-07 17:12:58 +00:00
if len(strings.TrimSpace(prompt)) > 0 {
client, err := api.FromEnv()
if err != nil {
return err
}
2023-07-07 17:12:58 +00:00
2023-07-17 21:14:41 +00:00
spinner := NewSpinner("")
go spinner.Spin(60 * time.Millisecond)
2023-07-06 22:43:04 +00:00
2023-07-13 01:18:06 +00:00
var latest api.GenerateResponse
2023-07-18 18:59:42 +00:00
generateContext, ok := cmd.Context().Value(generateContextKey("context")).([]int)
if !ok {
generateContext = []int{}
}
2023-08-01 01:35:18 +00:00
request := api.GenerateRequest{Model: model, Prompt: prompt, Context: generateContext}
2023-07-18 18:59:42 +00:00
fn := func(response api.GenerateResponse) error {
2023-07-07 17:12:58 +00:00
if !spinner.IsFinished() {
spinner.Finish()
}
2023-07-06 22:43:04 +00:00
2023-07-18 18:59:42 +00:00
latest = response
2023-07-13 01:18:06 +00:00
2023-07-18 18:59:42 +00:00
fmt.Print(response.Response)
2023-07-07 17:12:58 +00:00
return nil
2023-07-07 21:04:43 +00:00
}
if err := client.Generate(context.Background(), &request, fn); err != nil {
if strings.Contains(err.Error(), "failed to load model") {
// tell the user to check the server log, if it exists locally
home, nestedErr := os.UserHomeDir()
if nestedErr != nil {
// return the original error
return err
}
logPath := filepath.Join(home, ".ollama", "logs", "server.log")
if _, nestedErr := os.Stat(logPath); nestedErr == nil {
err = fmt.Errorf("%w\nFor more details, check the error logs at %s", err, logPath)
}
}
2023-07-07 21:04:43 +00:00
return err
}
2023-07-06 22:43:04 +00:00
2023-07-07 17:12:58 +00:00
fmt.Println()
fmt.Println()
2023-07-13 01:18:06 +00:00
2023-08-14 18:15:53 +00:00
if !latest.Done {
return errors.New("unexpected end of response")
}
2023-07-13 01:18:06 +00:00
verbose, err := cmd.Flags().GetBool("verbose")
if err != nil {
return err
}
if verbose {
latest.Summary()
}
2023-07-18 18:59:42 +00:00
ctx := cmd.Context()
ctx = context.WithValue(ctx, generateContextKey("context"), latest.Context)
cmd.SetContext(ctx)
2023-07-07 17:12:58 +00:00
}
2023-07-06 20:49:31 +00:00
return nil
}
func showLayer(l *server.Layer) {
filename, err := server.GetBlobsPath(l.Digest)
if err != nil {
fmt.Println("Couldn't get layer's path")
return
}
bts, err := os.ReadFile(filename)
if err != nil {
fmt.Println("Couldn't read layer")
return
}
fmt.Println(string(bts))
}
2023-07-13 01:18:06 +00:00
func generateInteractive(cmd *cobra.Command, model string) error {
2023-07-18 21:01:19 +00:00
home, err := os.UserHomeDir()
if err != nil {
return err
}
completer := readline.NewPrefixCompleter(
readline.PcItem("/help"),
readline.PcItem("/list"),
readline.PcItem("/set",
readline.PcItem("history"),
readline.PcItem("nohistory"),
2023-07-19 16:25:23 +00:00
readline.PcItem("verbose"),
readline.PcItem("quiet"),
2023-07-18 21:01:19 +00:00
readline.PcItem("mode",
readline.PcItem("vim"),
readline.PcItem("emacs"),
readline.PcItem("default"),
),
),
readline.PcItem("/show",
readline.PcItem("license"),
readline.PcItem("system"),
readline.PcItem("template"),
),
2023-07-18 21:01:19 +00:00
readline.PcItem("/exit"),
readline.PcItem("/bye"),
)
usage := func() {
fmt.Fprintln(os.Stderr, "commands:")
fmt.Fprintln(os.Stderr, completer.Tree(" "))
}
config := readline.Config{
Prompt: ">>> ",
HistoryFile: filepath.Join(home, ".ollama", "history"),
AutoComplete: completer,
}
scanner, err := readline.NewEx(&config)
if err != nil {
return err
}
defer scanner.Close()
var multiLineBuffer string
var isMultiLine bool
2023-07-18 21:01:19 +00:00
for {
line, err := scanner.Readline()
switch {
case errors.Is(err, io.EOF):
return nil
case errors.Is(err, readline.ErrInterrupt):
2023-07-20 07:53:08 +00:00
if line == "" {
return nil
}
2023-07-18 21:01:19 +00:00
continue
case err != nil:
2023-07-06 20:49:31 +00:00
return err
}
2023-07-18 21:01:19 +00:00
line = strings.TrimSpace(line)
2023-07-06 20:49:31 +00:00
2023-07-18 21:01:19 +00:00
switch {
case isMultiLine:
if strings.HasSuffix(line, `"""`) {
isMultiLine = false
multiLineBuffer += strings.TrimSuffix(line, `"""`)
line = multiLineBuffer
multiLineBuffer = ""
scanner.SetPrompt(">>> ")
} else {
multiLineBuffer += line + " "
continue
}
case strings.HasPrefix(line, `"""`):
isMultiLine = true
multiLineBuffer = strings.TrimPrefix(line, `"""`) + " "
scanner.SetPrompt("... ")
continue
2023-07-18 21:01:19 +00:00
case strings.HasPrefix(line, "/list"):
args := strings.Fields(line)
2023-07-20 23:09:23 +00:00
if err := ListHandler(cmd, args[1:]); err != nil {
2023-07-18 21:01:19 +00:00
return err
}
continue
case strings.HasPrefix(line, "/set"):
args := strings.Fields(line)
if len(args) > 1 {
switch args[1] {
case "history":
scanner.HistoryEnable()
continue
case "nohistory":
scanner.HistoryDisable()
continue
2023-07-19 16:25:23 +00:00
case "verbose":
cmd.Flags().Set("verbose", "true")
continue
case "quiet":
cmd.Flags().Set("verbose", "false")
continue
2023-07-18 21:01:19 +00:00
case "mode":
if len(args) > 2 {
switch args[2] {
case "vim":
scanner.SetVimMode(true)
continue
case "emacs", "default":
scanner.SetVimMode(false)
continue
default:
usage()
continue
}
} else {
usage()
continue
}
}
} else {
usage()
continue
}
case strings.HasPrefix(line, "/show"):
args := strings.Fields(line)
if len(args) > 1 {
mp := server.ParseModelPath(model)
2023-08-22 04:56:56 +00:00
if err != nil {
return err
}
2023-08-29 03:50:24 +00:00
manifest, _, err := server.GetManifest(mp)
if err != nil {
fmt.Println("error: couldn't get a manifest for this model")
continue
}
switch args[1] {
case "license":
for _, l := range manifest.Layers {
if l.MediaType == "application/vnd.ollama.image.license" {
showLayer(l)
}
}
continue
case "system":
for _, l := range manifest.Layers {
if l.MediaType == "application/vnd.ollama.image.system" {
showLayer(l)
}
}
continue
case "template":
for _, l := range manifest.Layers {
if l.MediaType == "application/vnd.ollama.image.template" {
showLayer(l)
2023-07-18 21:01:19 +00:00
}
}
continue
default:
usage()
continue
2023-07-18 21:01:19 +00:00
}
} else {
usage()
continue
2023-07-18 21:01:19 +00:00
}
case line == "/help", line == "/?":
usage()
continue
case line == "/exit", line == "/bye":
return nil
}
if err := generate(cmd, model, line); err != nil {
return err
}
}
2023-07-06 16:24:49 +00:00
}
2023-07-13 01:18:06 +00:00
func generateBatch(cmd *cobra.Command, model string) error {
2023-07-06 20:49:31 +00:00
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
prompt := scanner.Text()
fmt.Printf(">>> %s\n", prompt)
2023-07-13 01:18:06 +00:00
if err := generate(cmd, model, prompt); err != nil {
2023-07-06 20:49:31 +00:00
return err
}
}
return nil
}
func RunServer(cmd *cobra.Command, _ []string) error {
2023-08-22 04:56:56 +00:00
host, port := "127.0.0.1", "11434"
parts := strings.Split(os.Getenv("OLLAMA_HOST"), ":")
if ip := net.ParseIP(parts[0]); ip != nil {
host = ip.String()
}
if len(parts) > 1 {
port = parts[1]
}
// deprecated: include port in OLLAMA_HOST
if p := os.Getenv("OLLAMA_PORT"); p != "" {
port = p
2023-07-04 04:47:00 +00:00
}
err := initializeKeypair()
if err != nil {
return err
}
ln, err := net.Listen("tcp", fmt.Sprintf("%s:%s", host, port))
if err != nil {
return err
}
2023-07-04 04:47:00 +00:00
var origins []string
if o := os.Getenv("OLLAMA_ORIGINS"); o != "" {
origins = strings.Split(o, ",")
}
2023-08-10 16:27:03 +00:00
return server.Serve(ln, origins)
2023-07-04 04:47:00 +00:00
}
func initializeKeypair() error {
home, err := os.UserHomeDir()
if err != nil {
return err
}
privKeyPath := filepath.Join(home, ".ollama", "id_ed25519")
pubKeyPath := filepath.Join(home, ".ollama", "id_ed25519.pub")
_, err = os.Stat(privKeyPath)
if os.IsNotExist(err) {
fmt.Printf("Couldn't find '%s'. Generating new private key.\n", privKeyPath)
_, privKey, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
return err
}
privKeyBytes, err := format.OpenSSHPrivateKey(privKey, "")
if err != nil {
return err
}
err = os.MkdirAll(path.Dir(privKeyPath), 0o700)
if err != nil {
return fmt.Errorf("could not create directory %w", err)
}
2023-08-22 04:56:56 +00:00
err = os.WriteFile(privKeyPath, pem.EncodeToMemory(privKeyBytes), 0o600)
if err != nil {
return err
}
sshPrivateKey, err := ssh.NewSignerFromKey(privKey)
if err != nil {
return err
}
pubKeyData := ssh.MarshalAuthorizedKey(sshPrivateKey.PublicKey())
2023-08-22 04:56:56 +00:00
err = os.WriteFile(pubKeyPath, pubKeyData, 0o644)
if err != nil {
return err
}
fmt.Printf("Your new public key is: \n\n%s\n", string(pubKeyData))
}
return nil
}
2023-07-31 21:38:10 +00:00
func startMacApp(client *api.Client) error {
2023-08-01 20:01:55 +00:00
exe, err := os.Executable()
if err != nil {
return err
}
link, err := os.Readlink(exe)
2023-07-31 21:38:10 +00:00
if err != nil {
return err
}
2023-08-01 17:48:48 +00:00
if !strings.Contains(link, "Ollama.app") {
return fmt.Errorf("could not find ollama app")
}
2023-07-31 21:38:10 +00:00
path := strings.Split(link, "Ollama.app")
if err := exec.Command("/usr/bin/open", "-a", path[0]+"Ollama.app").Run(); err != nil {
return err
}
// wait for the server to start
timeout := time.After(5 * time.Second)
tick := time.Tick(500 * time.Millisecond)
for {
select {
case <-timeout:
return errors.New("timed out waiting for server to start")
case <-tick:
if err := client.Heartbeat(context.Background()); err == nil {
return nil // server has started
}
}
}
}
func checkServerHeartbeat(_ *cobra.Command, _ []string) error {
client, err := api.FromEnv()
if err != nil {
return err
}
if err := client.Heartbeat(context.Background()); err != nil {
2023-07-31 21:38:10 +00:00
if !strings.Contains(err.Error(), "connection refused") {
return err
}
if runtime.GOOS == "darwin" {
if err := startMacApp(client); err != nil {
2023-08-01 17:48:48 +00:00
return fmt.Errorf("could not connect to ollama app, is it running?")
}
2023-07-31 21:38:10 +00:00
} else {
return fmt.Errorf("could not connect to ollama server, run 'ollama serve' to start it")
}
}
return nil
}
func NewCLI() *cobra.Command {
log.SetFlags(log.LstdFlags | log.Lshortfile)
rootCmd := &cobra.Command{
2023-08-14 18:15:53 +00:00
Use: "ollama",
Short: "Large language model runner",
SilenceUsage: true,
SilenceErrors: true,
CompletionOptions: cobra.CompletionOptions{
DisableDefaultCmd: true,
},
2023-08-22 01:24:42 +00:00
Version: version.Version,
}
cobra.EnableCommandSorting = false
createCmd := &cobra.Command{
Use: "create MODEL",
Short: "Create a model from a Modelfile",
Args: cobra.MinimumNArgs(1),
PreRunE: checkServerHeartbeat,
RunE: CreateHandler,
}
createCmd.Flags().StringP("file", "f", "Modelfile", "Name of the Modelfile (default \"Modelfile\")")
runCmd := &cobra.Command{
Use: "run MODEL [PROMPT]",
Short: "Run a model",
Args: cobra.MinimumNArgs(1),
PreRunE: checkServerHeartbeat,
RunE: RunHandler,
}
2023-07-13 01:18:06 +00:00
runCmd.Flags().Bool("verbose", false, "Show timings for response")
2023-08-22 04:56:56 +00:00
runCmd.Flags().Bool("insecure", false, "Use an insecure registry")
2023-07-13 01:18:06 +00:00
serveCmd := &cobra.Command{
Use: "serve",
Aliases: []string{"start"},
Short: "Start ollama",
2023-07-06 20:49:31 +00:00
RunE: RunServer,
}
pullCmd := &cobra.Command{
Use: "pull MODEL",
Short: "Pull a model from a registry",
Args: cobra.MinimumNArgs(1),
PreRunE: checkServerHeartbeat,
RunE: PullHandler,
}
pullCmd.Flags().Bool("insecure", false, "Use an insecure registry")
pushCmd := &cobra.Command{
Use: "push MODEL",
Short: "Push a model to a registry",
Args: cobra.MinimumNArgs(1),
PreRunE: checkServerHeartbeat,
RunE: PushHandler,
}
pushCmd.Flags().Bool("insecure", false, "Use an insecure registry")
2023-07-18 16:09:45 +00:00
listCmd := &cobra.Command{
Use: "list",
2023-07-20 22:28:27 +00:00
Aliases: []string{"ls"},
Short: "List models",
PreRunE: checkServerHeartbeat,
RunE: ListHandler,
2023-07-20 23:09:23 +00:00
}
2023-07-24 15:27:28 +00:00
copyCmd := &cobra.Command{
Use: "cp",
Short: "Copy a model",
Args: cobra.MinimumNArgs(2),
PreRunE: checkServerHeartbeat,
RunE: CopyHandler,
2023-07-24 15:27:28 +00:00
}
2023-07-20 23:09:23 +00:00
deleteCmd := &cobra.Command{
Use: "rm",
Short: "Remove a model",
Args: cobra.MinimumNArgs(1),
PreRunE: checkServerHeartbeat,
RunE: DeleteHandler,
2023-07-18 16:09:45 +00:00
}
rootCmd.AddCommand(
serveCmd,
createCmd,
runCmd,
pullCmd,
pushCmd,
2023-07-18 16:09:45 +00:00
listCmd,
2023-07-24 15:27:28 +00:00
copyCmd,
2023-07-20 23:09:23 +00:00
deleteCmd,
)
return rootCmd
}