Skip to content

Commit fc07567

Browse files
committed
Add model name normalization and display stripping
Add normalization to configure, list, and unload commands Signed-off-by: Eric Curtin <eric.curtin@docker.com>
1 parent abad2d8 commit fc07567

File tree

16 files changed

+417
-32
lines changed

16 files changed

+417
-32
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ vendor/
1515
# model-distribution
1616
pkg/distribution/bin/
1717
/parallelget
18+
/cli

cmd/cli/commands/configure.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func newConfigureCmd() *cobra.Command {
3333
argsBeforeDash)
3434
}
3535
}
36-
opts.Model = args[0]
36+
opts.Model = normalizeModelName(args[0])
3737
opts.RuntimeFlags = args[1:]
3838
return nil
3939
},

cmd/cli/commands/inspect.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ func newInspectCmd() *cobra.Command {
4747
}
4848

4949
func inspectModel(args []string, openai bool, remote bool, desktopClient *desktop.Client) (string, error) {
50-
modelName := args[0]
50+
// Normalize model name to add default org and tag if missing
51+
modelName := normalizeModelName(args[0])
5152
if openai {
5253
model, err := desktopClient.InspectOpenAI(modelName)
5354
if err != nil {

cmd/cli/commands/list.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"fmt"
66
"os"
7-
"slices"
87
"strings"
98
"time"
109

@@ -89,12 +88,20 @@ func listModels(openai bool, backend string, desktopClient *desktop.Client, quie
8988
}
9089

9190
if modelFilter != "" {
91+
// Normalize the filter to match stored model names
92+
normalizedFilter := normalizeModelName(modelFilter)
9293
var filteredModels []dmrm.Model
9394
for _, m := range models {
9495
hasMatchingTag := false
9596
for _, tag := range m.Tags {
97+
if tag == normalizedFilter {
98+
hasMatchingTag = true
99+
break
100+
}
101+
// Also check without the tag part
96102
modelName, _, _ := strings.Cut(tag, ":")
97-
if slices.Contains([]string{modelName, tag + ":latest", tag}, modelFilter) {
103+
filterName, _, _ := strings.Cut(normalizedFilter, ":")
104+
if modelName == filterName {
98105
hasMatchingTag = true
99106
break
100107
}
@@ -165,8 +172,10 @@ func appendRow(table *tablewriter.Table, tag string, model dmrm.Model) {
165172
fmt.Fprintf(os.Stderr, "invalid model ID for model: %v\n", model)
166173
return
167174
}
175+
// Strip default "ai/" prefix and ":latest" tag for display
176+
displayTag := stripDefaultsFromModelName(tag)
168177
table.Append([]string{
169-
tag,
178+
displayTag,
170179
model.Config.Parameters,
171180
model.Config.Quantization,
172181
model.Config.Architecture,

cmd/cli/commands/ps.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ func psTable(ps []desktop.BackendStatus) string {
5454
modelName := status.ModelName
5555
if strings.HasPrefix(modelName, "sha256:") {
5656
modelName = modelName[7:19]
57+
} else {
58+
// Strip default "ai/" prefix and ":latest" tag for display
59+
modelName = stripDefaultsFromModelName(modelName)
5760
}
5861
table.Append([]string{
5962
modelName,

cmd/cli/commands/pull.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ func newPullCmd() *cobra.Command {
4141
}
4242

4343
func pullModel(cmd *cobra.Command, desktopClient *desktop.Client, model string, ignoreRuntimeMemoryCheck bool) error {
44+
// Normalize model name to add default org and tag if missing
45+
model = normalizeModelName(model)
46+
4447
var progress func(string)
4548
if isatty.IsTerminal(os.Stdout.Fd()) {
4649
progress = TUIProgress

cmd/cli/commands/push.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ func newPushCmd() *cobra.Command {
3434
}
3535

3636
func pushModel(cmd *cobra.Command, desktopClient *desktop.Client, model string) error {
37+
// Normalize model name to add default org and tag if missing
38+
model = normalizeModelName(model)
39+
3740
response, progressShown, err := desktopClient.Push(model, TUIProgress)
3841

3942
// Add a newline before any output (success or error) if progress was shown.

cmd/cli/commands/rm.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ func newRemoveCmd() *cobra.Command {
2727
if _, err := ensureStandaloneRunnerAvailable(cmd.Context(), cmd); err != nil {
2828
return fmt.Errorf("unable to initialize standalone model runner: %w", err)
2929
}
30-
response, err := desktopClient.Remove(args, force)
30+
// Normalize model names to add default org and tag if missing
31+
normalizedArgs := make([]string, len(args))
32+
for i, arg := range args {
33+
normalizedArgs[i] = normalizeModelName(arg)
34+
}
35+
response, err := desktopClient.Remove(normalizedArgs, force)
3136
if response != "" {
3237
cmd.Print(response)
3338
}

cmd/cli/commands/run.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,8 @@ func newRunCmd() *cobra.Command {
561561
return err
562562
}
563563

564-
model := args[0]
564+
// Normalize model name to add default org and tag if missing
565+
model := normalizeModelName(args[0])
565566
prompt := ""
566567
argsLen := len(args)
567568
if argsLen > 1 {

cmd/cli/commands/tag.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ func newTagCmd() *cobra.Command {
3636
}
3737

3838
func tagModel(cmd *cobra.Command, desktopClient *desktop.Client, source, target string) error {
39+
// Normalize source model name to add default org and tag if missing
40+
source = normalizeModelName(source)
41+
3942
// Ensure tag is valid
4043
tag, err := name.NewTag(target)
4144
if err != nil {

0 commit comments

Comments
 (0)