Skip to content

Commit be5c0fc

Browse files
committed
update model filtering logic to match docker cli
1 parent 2560aef commit be5c0fc

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

cmd/cli/commands/list.go

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,25 +72,39 @@ func listModels(openai bool, desktopClient *desktop.Client, quiet bool, jsonForm
7272
}
7373

7474
if modelFilter != "" {
75+
// If filter doesn't contain '/', prepend default namespace 'ai/'
76+
if !strings.Contains(modelFilter, "/") {
77+
modelFilter = "ai/" + modelFilter
78+
}
79+
7580
var filteredModels []dmrm.Model
81+
82+
// Check if filter has a colon (i.e., includes a tag)
83+
hasColon := strings.Contains(modelFilter, ":")
84+
7685
for _, m := range models {
77-
hasMatchingTag := false
86+
var matchingTags []string
7887
for _, tag := range m.Tags {
79-
// Tags are stored in normalized format by the backend
80-
if tag == modelFilter {
81-
hasMatchingTag = true
82-
break
83-
}
84-
// Also check without the tag part
85-
modelName, _, _ := strings.Cut(tag, ":")
86-
filterName, _, _ := strings.Cut(modelFilter, ":")
87-
if modelName == filterName {
88-
hasMatchingTag = true
89-
break
88+
if hasColon {
89+
// Filter includes a tag part - do exact match
90+
// Tags are stored in normalized format by the backend
91+
if tag == modelFilter {
92+
matchingTags = append(matchingTags, tag)
93+
}
94+
} else {
95+
// Filter has no colon - match repository name only (part before ':')
96+
repository, _, _ := strings.Cut(tag, ":")
97+
if repository == modelFilter {
98+
matchingTags = append(matchingTags, tag)
99+
}
90100
}
91101
}
92-
if hasMatchingTag {
93-
filteredModels = append(filteredModels, m)
102+
// Only include the model if at least one tag matched, and only include matching tags
103+
if len(matchingTags) > 0 {
104+
// Create a copy of the model with only the matching tags
105+
filteredModel := m
106+
filteredModel.Tags = matchingTags
107+
filteredModels = append(filteredModels, filteredModel)
94108
}
95109
}
96110
models = filteredModels

0 commit comments

Comments
 (0)