-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathshow.go
More file actions
105 lines (90 loc) · 2.67 KB
/
Copy pathshow.go
File metadata and controls
105 lines (90 loc) · 2.67 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package commands
import (
"fmt"
"strings"
"time"
"github.com/docker/model-runner/cmd/cli/commands/completion"
"github.com/docker/model-runner/cmd/cli/desktop"
"github.com/docker/model-runner/pkg/distribution/types"
dmrm "github.com/docker/model-runner/pkg/inference/models"
"github.com/spf13/cobra"
)
func newShowCmd() *cobra.Command {
var remote bool
c := &cobra.Command{
Use: "show MODEL",
Short: "Show information for a model",
Long: "Display detailed information about a model in a human-readable format.",
Args: requireExactArgs(1, "show", "MODEL"),
RunE: func(cmd *cobra.Command, args []string) error {
output, err := showModel(args[0], remote, desktopClient)
if err != nil {
return err
}
cmd.Print(output)
return nil
},
ValidArgsFunction: completion.ModelNames(getDesktopClient, 1),
}
c.Flags().BoolVarP(&remote, "remote", "r", false, "Show info for remote models")
return c
}
func showModel(modelName string, remote bool, desktopClient *desktop.Client) (string, error) {
model, err := desktopClient.Inspect(modelName, remote)
if err != nil {
return "", handleClientError(err, "Failed to get model "+modelName)
}
return formatModelInfo(model), nil
}
func formatModelInfo(model dmrm.Model) string {
var sb strings.Builder
// Model ID
fmt.Fprintf(&sb, "Model: %s\n", model.ID)
// Tags
if len(model.Tags) > 0 {
fmt.Fprintf(&sb, "Tags: %s\n", strings.Join(model.Tags, ", "))
}
// Created date
if model.Created > 0 {
created := time.Unix(model.Created, 0)
fmt.Fprintf(&sb, "Created: %s\n", created.Format(time.RFC3339))
}
// Config details
if model.Config != nil {
sb.WriteString("\n")
if cfg, ok := model.Config.(*types.Config); ok {
// Config fields using data-driven approach
fields := []struct {
label string
value string
}{
{"Format:", string(cfg.Format)},
{"Architecture:", cfg.Architecture},
{"Parameters:", cfg.Parameters},
{"Size:", cfg.Size},
{"Quantization:", cfg.Quantization},
}
for _, field := range fields {
if field.value != "" {
fmt.Fprintf(&sb, "%-14s%s\n", field.label, field.value)
}
}
if cfg.ContextSize != nil {
fmt.Fprintf(&sb, "%-14s%d\n", "Context Size:", *cfg.ContextSize)
}
// Helper function to print metadata sections
printMetadata := func(title string, data map[string]string) {
if len(data) > 0 {
fmt.Fprintf(&sb, "\n%s:\n", title)
for k, v := range data {
fmt.Fprintf(&sb, " %s: %s\n", k, v)
}
}
}
printMetadata("GGUF Metadata", cfg.GGUF)
printMetadata("Safetensors Metadata", cfg.Safetensors)
printMetadata("Diffusers Metadata", cfg.Diffusers)
}
}
return sb.String()
}