MCPcopy Index your code
hub / github.com/docker/docker-agent / runModelsListCommand

Method runModelsListCommand

cmd/root/models.go:115–181  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

113}
114
115func (f *modelsListFlags) runModelsListCommand(cmd *cobra.Command, args []string) (commandErr error) {
116 ctx := cmd.Context()
117 telemetry.TrackCommand(ctx, "models", append([]string{"list"}, args...))
118 defer func() {
119 telemetry.TrackCommandError(ctx, "models", append([]string{"list"}, args...), commandErr)
120 }()
121
122 out := cli.NewPrinter(cmd.OutOrStdout())
123 env := f.runConfig.EnvProvider()
124
125 // Normalize the provider filter to lowercase so case-sensitive map lookups
126 // in AvailableProviders, db.Providers and IsCatalogProvider all match the
127 // same way strings.EqualFold does in the outer row filter below.
128 if f.providerFilter != "" {
129 f.providerFilter = strings.ToLower(f.providerFilter)
130 }
131
132 // Determine which providers the user has credentials for.
133 availableProviders := make(map[string]bool)
134 for _, p := range config.AvailableProviders(ctx, f.runConfig.ModelsGateway, env) {
135 availableProviders[p] = true
136 }
137
138 // Determine which model auto-selection would pick. DMR discovery is left
139 // out here (nil lister) so listing models stays a pure, side-effect-free
140 // operation; the default marker therefore reflects the static per-provider
141 // default rather than a locally-pulled DMR model.
142 autoModel := config.AutoModelConfig(ctx, f.runConfig.ModelsGateway, env, f.runConfig.DefaultModel, nil)
143
144 rows := f.collectModels(ctx, env, availableProviders, autoModel)
145
146 // Apply provider filter
147 if f.providerFilter != "" {
148 rows = slices.DeleteFunc(rows, func(r modelRow) bool {
149 return !strings.EqualFold(r.Provider, f.providerFilter)
150 })
151 }
152
153 // Sort: default first, then by provider, then by model
154 slices.SortFunc(rows, func(a, b modelRow) int {
155 if a.Default != b.Default {
156 if a.Default {
157 return -1
158 }
159 return 1
160 }
161 if c := strings.Compare(a.Provider, b.Provider); c != 0 {
162 return c
163 }
164 return strings.Compare(a.Model, b.Model)
165 })
166
167 if len(rows) == 0 {
168 out.Println("No models available.")
169 out.Println("\nConfigure a provider API key or install Docker Model Runner.")
170 return nil
171 }
172

Callers

nothing calls this directly

Calls 11

collectModelsMethod · 0.95
PrintlnMethod · 0.95
renderJSONMethod · 0.95
renderTableMethod · 0.95
TrackCommandFunction · 0.92
TrackCommandErrorFunction · 0.92
NewPrinterFunction · 0.92
AvailableProvidersFunction · 0.92
AutoModelConfigFunction · 0.92
ContextMethod · 0.80
EnvProviderMethod · 0.80

Tested by

no test coverage detected