collectModels returns all models from the catalog, filtered by credential availability unless --all is set. Default models for each available provider are always included even if the catalog fetch fails.
(ctx context.Context, env environment.Provider, availableProviders map[string]bool, autoModel latest.ModelConfig)
| 184 | // availability unless --all is set. Default models for each available provider |
| 185 | // are always included even if the catalog fetch fails. |
| 186 | func (f *modelsListFlags) collectModels(ctx context.Context, env environment.Provider, availableProviders map[string]bool, autoModel latest.ModelConfig) []modelRow { |
| 187 | seen := make(map[string]bool) |
| 188 | var rows []modelRow |
| 189 | |
| 190 | // Always include the per-provider defaults so we have something even |
| 191 | // if the catalog is unreachable. |
| 192 | for prov, model := range config.DefaultModels { |
| 193 | if !f.all && !availableProviders[prov] { |
| 194 | continue |
| 195 | } |
| 196 | ref := prov + "/" + model |
| 197 | seen[ref] = true |
| 198 | rows = append(rows, modelRow{ |
| 199 | Provider: prov, |
| 200 | Model: model, |
| 201 | Default: prov == autoModel.Provider && model == autoModel.Model, |
| 202 | }) |
| 203 | } |
| 204 | |
| 205 | // Fetch catalog and add all text-capable models. |
| 206 | store, err := f.runConfig.ModelsDevStore() |
| 207 | if err != nil { |
| 208 | return rows |
| 209 | } |
| 210 | db, err := store.GetDatabase(ctx) |
| 211 | if err != nil { |
| 212 | return rows |
| 213 | } |
| 214 | |
| 215 | for providerID, prov := range db.Providers { |
| 216 | if !provider.IsCatalogProvider(providerID) { |
| 217 | continue |
| 218 | } |
| 219 | if !f.all && !availableProviders[providerID] { |
| 220 | continue |
| 221 | } |
| 222 | for modelID, model := range prov.Models { |
| 223 | if !slices.Contains(model.Modalities.Output, "text") { |
| 224 | continue |
| 225 | } |
| 226 | if isEmbeddingModel(model.Family, model.Name) { |
| 227 | continue |
| 228 | } |
| 229 | |
| 230 | ref := providerID + "/" + modelID |
| 231 | if seen[ref] { |
| 232 | continue |
| 233 | } |
| 234 | seen[ref] = true |
| 235 | |
| 236 | rows = append(rows, modelRow{ |
| 237 | Provider: providerID, |
| 238 | Model: modelID, |
| 239 | }) |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | // When the user explicitly filters by provider (--provider) and that |
no test coverage detected