diff --git a/internal/provider/icon_catalog_list_test.go b/internal/provider/icon_catalog_list_test.go new file mode 100644 index 000000000..7014d66fd --- /dev/null +++ b/internal/provider/icon_catalog_list_test.go @@ -0,0 +1,18 @@ +package provider + +import "testing" + +// A preset names several catalogs; each one's models get its logo +// (zzstar101 on X: step-5-preview of "stepfun-ai" had none of StepFun's). +func TestIconForCatalogFindsAListedCatalog(t *testing.T) { + for id, want := range map[string]string{ + "stepfun-ai": "stepfun-color", "stepfun-ai-step-plan": "stepfun-color", + "stepfun": "stepfun-color", "stepfun-step-plan": "stepfun-color", + "xiaomi": "mimocode", "xiaomi-token-plan-cn": "mimocode", + "openai": "openai", "azure": "azure-color", "": "", + } { + if got := IconForCatalog(id); got != want { + t.Errorf("IconForCatalog(%q) = %q, want %q", id, got, want) + } + } +} diff --git a/internal/provider/presets.go b/internal/provider/presets.go index 86efc975e..c776fb959 100644 --- a/internal/provider/presets.go +++ b/internal/provider/presets.go @@ -972,12 +972,24 @@ func (p *Provider) atRegionOf(pr *PresetDef, r Region) { } // IconForCatalog names the logo of the vendor behind a models.dev -// provider id, or "" when no preset covers it. +// provider id, or "" when no preset covers it. A preset names several +// catalogs ("stepfun-ai-step-plan, stepfun-ai"), so an id is also found in +// that list; a preset whose catalog is exactly the id comes first, so +// Azure's "azure, openai" never gives OpenAI's models Azure's logo. func IconForCatalog(catalogID string) string { + if catalogID == "" { + return "" + } for _, p := range presets { if p.Catalog == catalogID || slices.ContainsFunc(p.Regions, func(r Region) bool { return r.Catalog == catalogID }) { return p.Icon } } + for _, p := range presets { + if slices.Contains(Provider{Catalog: p.Catalog}.Catalogs(), catalogID) || + slices.ContainsFunc(p.Regions, func(r Region) bool { return slices.Contains(Provider{Catalog: r.Catalog}.Catalogs(), catalogID) }) { + return p.Icon + } + } return "" }