Skip to content

Commit 0d38d3c

Browse files
committed
stripDefaultsFromModelName fixed to account for default registries
So we strip defaults fully. Signed-off-by: Eric Curtin <[email protected]>
1 parent 6f0be5b commit 0d38d3c

File tree

2 files changed

+52
-5
lines changed

2 files changed

+52
-5
lines changed

cmd/cli/commands/utils.go

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,46 @@ func asPrinter(cmd *cobra.Command) standalone.StatusPrinter {
8787
return &commandPrinter{cmd: cmd}
8888
}
8989

90-
// stripDefaultsFromModelName removes the default "ai/" prefix and ":latest" tag for display.
90+
// stripDefaultsFromModelName removes the default "ai/" prefix, default registry, and ":latest" tag for display.
9191
// Examples:
9292
// - "ai/gemma3:latest" -> "gemma3"
9393
// - "ai/gemma3:v1" -> "ai/gemma3:v1"
9494
// - "myorg/gemma3:latest" -> "myorg/gemma3"
9595
// - "gemma3:latest" -> "gemma3"
96+
// - "index.docker.io/ai/gemma3:latest" -> "gemma3"
97+
// - "docker.io/ai/gemma3:latest" -> "gemma3"
98+
// - "docker.io/myorg/gemma3:latest" -> "myorg/gemma3"
9699
// - "hf.co/bartowski/model:latest" -> "hf.co/bartowski/model"
97100
func stripDefaultsFromModelName(model string) string {
98-
// Check if model has ai/ prefix without tag (implicitly :latest) - strip just ai/
101+
// First, let's handle the default registry prefixes
102+
defaultRegistries := []string{"index.docker.io/", "docker.io/"}
103+
for _, reg := range defaultRegistries {
104+
if strings.HasPrefix(model, reg) {
105+
// Remove the registry prefix
106+
model = strings.TrimPrefix(model, reg)
107+
break
108+
}
109+
}
110+
111+
// If model has default org prefix (without tag, or with :latest tag), strip the org
112+
// but preserve other tags
99113
if strings.HasPrefix(model, defaultOrg+"/") {
100-
model = strings.TrimPrefix(model, defaultOrg+"/")
114+
rest := strings.TrimPrefix(model, defaultOrg+"/")
115+
// Check if the remaining part has :latest tag
116+
if strings.HasSuffix(rest, ":"+defaultTag) {
117+
// Strip the :latest tag to get just the name
118+
nameWithoutTag := strings.TrimSuffix(rest, ":"+defaultTag)
119+
return nameWithoutTag
120+
}
121+
// If it doesn't have latest tag, keep the rest intact
122+
return rest
101123
}
102124

103-
// Check if model has :latest but no slash (no org specified) - strip :latest
125+
// For models without the default org but with :latest tag, just strip the tag (keep the org part)
104126
if strings.HasSuffix(model, ":"+defaultTag) {
105127
model = strings.TrimSuffix(model, ":"+defaultTag)
106128
}
107129

108-
// For other cases (ai/ with custom tag, custom org with :latest, etc.), keep as-is
130+
// For other cases (custom org with :latest, etc.), return as is
109131
return model
110132
}

cmd/cli/commands/utils_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,31 @@ func TestStripDefaultsFromModelName(t *testing.T) {
137137
input: "",
138138
expected: "",
139139
},
140+
{
141+
name: "docker.io registry with ai prefix and latest tag",
142+
input: "docker.io/ai/gemma3:latest",
143+
expected: "gemma3",
144+
},
145+
{
146+
name: "index.docker.io registry with ai prefix and latest tag",
147+
input: "index.docker.io/ai/gemma3:latest",
148+
expected: "gemma3",
149+
},
150+
{
151+
name: "docker.io registry with ai prefix and custom tag",
152+
input: "docker.io/ai/gemma3:v1",
153+
expected: "gemma3:v1",
154+
},
155+
{
156+
name: "docker.io registry with custom org and latest tag",
157+
input: "docker.io/myorg/gemma3:latest",
158+
expected: "myorg/gemma3",
159+
},
160+
{
161+
name: "index.docker.io registry with custom org and latest tag",
162+
input: "index.docker.io/myorg/gemma3:latest",
163+
expected: "myorg/gemma3",
164+
},
140165
}
141166

142167
for _, tt := range tests {

0 commit comments

Comments
 (0)