-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathpull.go
More file actions
43 lines (33 loc) · 1.28 KB
/
pull.go
File metadata and controls
43 lines (33 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package commands
import (
"fmt"
"github.com/docker/model-runner/cmd/cli/commands/completion"
"github.com/docker/model-runner/cmd/cli/desktop"
"github.com/spf13/cobra"
)
func newPullCmd() *cobra.Command {
var ignoreRuntimeMemoryCheck bool
c := &cobra.Command{
Use: "pull MODEL",
Short: "Pull a model from Docker Hub or HuggingFace to your local environment",
Args: requireExactArgs(1, "pull", "MODEL"),
RunE: func(cmd *cobra.Command, args []string) error {
if _, err := ensureStandaloneRunnerAvailable(cmd.Context(), asPrinter(cmd), false); err != nil {
return fmt.Errorf("unable to initialize standalone model runner: %w", err)
}
return pullModel(cmd, desktopClient, args[0], ignoreRuntimeMemoryCheck)
},
ValidArgsFunction: completion.NoComplete,
}
c.Flags().BoolVar(&ignoreRuntimeMemoryCheck, "ignore-runtime-memory-check", false, "Do not block pull if estimated runtime memory for model exceeds system resources.")
return c
}
func pullModel(cmd *cobra.Command, desktopClient *desktop.Client, model string, ignoreRuntimeMemoryCheck bool) error {
printer := asPrinter(cmd)
response, _, err := desktopClient.Pull(model, ignoreRuntimeMemoryCheck, printer)
if err != nil {
return handleClientError(err, "Failed to pull model")
}
cmd.Println(response)
return nil
}