codex: a magpie model that takes images says so in the catalog magpie gives Codex, which otherwise drops an attached image before sending — every magpie model was listed as text-only, so a picture pasted into Codex never reached a vision model; whether a model takes images is what its vendor's models.dev entry says, or for one served by a vendor models.dev doesn't list, what most of the providers serving that model say, and a routing group takes them only when every member does

This commit is contained in:
yetone
2026-09-25 06:59:45 +08:00
parent bd5bf422ed
commit 626933ff2b
10 changed files with 119 additions and 10 deletions
+1 -1
View File
@@ -74,7 +74,7 @@ func magpieModels() []catalog.Model {
if e.Group != "" {
by = "routing group"
}
out = append(out, catalog.Model{ID: e.ID, Name: e.Name + " · " + by, Provider: firstOf(e.Provider.Catalogs()), Efforts: e.Efforts})
out = append(out, catalog.Model{ID: e.ID, Name: e.Name + " · " + by, Provider: firstOf(e.Provider.Catalogs()), Efforts: e.Efforts, Images: e.Images})
}
return out
}
+44 -2
View File
@@ -11,6 +11,7 @@ import (
"net/http"
"os"
"path/filepath"
"slices"
"sort"
"strings"
"sync"
@@ -32,6 +33,8 @@ type Model struct {
// APIs, when the vendor says, are the APIs the model is served on
// ("chat", "responses", "anthropic"); empty is not known.
APIs []string `json:",omitempty"`
// Images is set on a model that takes images as input.
Images bool `json:",omitempty"`
}
// Price is what a model costs, in USD per million tokens.
@@ -66,6 +69,7 @@ type mdModel struct {
Values []string `json:"values"`
} `json:"reasoning_options"`
Modalities struct {
Input []string `json:"input"`
Output []string `json:"output"`
} `json:"modalities"`
Cost *Price `json:"cost"`
@@ -76,6 +80,9 @@ const modelsDevURL = "https://models.dev/api.json"
var (
once sync.Once
mdev map[string]mdProvider
// images are the models, by bare id, most of the providers serving
// them say take images (a few mislabel a text model)
images map[string]bool
syncMu sync.Mutex
)
@@ -114,6 +121,22 @@ func load() map[string]mdProvider {
var m map[string]mdProvider
if json.Unmarshal(b, &m) == nil && len(m) > 0 {
mdev = m
votes := map[string]int{}
for _, p := range m {
for id, x := range p.Models {
if slices.Contains(x.Modalities.Input, "image") {
votes[bareID(id)]++
} else {
votes[bareID(id)]--
}
}
}
images = map[string]bool{}
for id, v := range votes {
if v > 0 {
images[id] = true
}
}
return
}
}
@@ -124,7 +147,7 @@ func load() map[string]mdProvider {
// Reset forgets the loaded catalog so the next call re-reads the cache.
func Reset() {
once = sync.Once{}
mdev = nil
mdev, images = nil, nil
}
// Sync downloads the models.dev catalog into CachePath. It serializes with
@@ -216,7 +239,8 @@ func Provider(id string) []Model {
if !textModel(m) {
continue
}
mm := Model{ID: m.ID, Name: m.Name, Provider: id, Released: m.ReleaseDate, Price: m.Cost, Temperature: m.Temperature}
mm := Model{ID: m.ID, Name: m.Name, Provider: id, Released: m.ReleaseDate, Price: m.Cost, Temperature: m.Temperature,
Images: slices.Contains(m.Modalities.Input, "image")}
for _, r := range m.Reasoning {
if r.Type == "effort" {
mm.Efforts = r.Values
@@ -239,6 +263,24 @@ func ProviderName(id string) string {
return load()[id].Name
}
// SeesImages reports whether models.dev says a model of this id takes
// images, as most of the providers it lists serving it do; for a vendor it
// doesn't list, serving a model it knows from others ("z-ai/glm-5.3" is
// glm-5.3).
func SeesImages(id string) bool {
load()
return images[bareID(id)]
}
// bareID is a model's id without the vendor's prefix, lowercase.
func bareID(id string) string {
id = strings.ToLower(id)
if i := strings.LastIndexByte(id, '/'); i >= 0 {
id = id[i+1:]
}
return id
}
func textModel(m mdModel) bool {
if len(m.Modalities.Output) > 0 {
text := false
+21
View File
@@ -68,3 +68,24 @@ func TestDecorateCarriesTemperature(t *testing.T) {
t.Fatalf("decorated: %+v", out[1])
}
}
// A model takes images where models.dev says so; one listed by several
// providers takes them as most of those say, whatever a vendor prefixes.
func TestImages(t *testing.T) {
writeCatalog(t, `{
"a": {"models": {
"vision": {"id":"vision","name":"V","modalities":{"input":["text","image"],"output":["text"]}},
"text": {"id":"text","name":"T","modalities":{"input":["text"],"output":["text"]}}
}},
"b": {"models": {"text": {"id":"text","name":"T","modalities":{"input":["text"],"output":["text"]}}}},
"c": {"models": {"org/text": {"id":"org/text","name":"T","modalities":{"input":["text","image"],"output":["text"]}}}}
}`)
for _, m := range Provider("a") {
if m.Images != (m.ID == "vision") {
t.Errorf("%s: images %v", m.ID, m.Images)
}
}
if !SeesImages("z-ai/Vision") || SeesImages("text") || SeesImages("unknown") {
t.Error("SeesImages")
}
}
+1
View File
@@ -192,6 +192,7 @@ func Decorate(live []Model, known []Model) []Model {
m.Name = k.Name
}
m.Efforts, m.Released, m.Provider = k.Efforts, k.Released, k.Provider
m.Images = m.Images || k.Images
if k.Temperature != nil {
m.Temperature = k.Temperature
}
+3
View File
@@ -86,6 +86,9 @@ func Entries(ms []catalog.Model, after int) []any {
Shell: "unified_exec", Visibility: "list", InAPI: true, Priority: after + i + 1,
ApplyPatch: "freeform", Tools: []string{}, Modalities: []string{"text"},
}
if m.Images {
e.Modalities = append(e.Modalities, "image")
}
e.Truncation.Mode, e.Truncation.Limit = "tokens", 10000
for _, ef := range m.Efforts {
e.Efforts = append(e.Efforts, level{Effort: ef})
+17
View File
@@ -47,3 +47,20 @@ func TestCodexCatalogKeepsOwnEntries(t *testing.T) {
t.Error("start-up notice kept")
}
}
// A model that takes images says so, and Codex lets images be attached.
func TestCodexCatalogImages(t *testing.T) {
t.Setenv("HOME", t.TempDir())
var got struct {
Models []struct {
Modalities []string `json:"input_modalities"`
} `json:"models"`
}
json.Unmarshal(Catalog([]catalog.Model{
{ID: "a/text", Name: "text"},
{ID: "a/vision", Name: "vision", Images: true},
}), &got)
if len(got.Models) != 2 || len(got.Models[0].Modalities) != 1 || len(got.Models[1].Modalities) != 2 || got.Models[1].Modalities[1] != "image" {
t.Errorf("%+v", got.Models)
}
}
+1 -1
View File
@@ -265,7 +265,7 @@ func (s *Server) codexModels(w http.ResponseWriter, r *http.Request) {
if e.Group != "" {
by = "routing group"
}
ms = append(ms, catalog.Model{ID: e.ID, Name: e.Name + " · " + by, Efforts: e.Efforts})
ms = append(ms, catalog.Model{ID: e.ID, Name: e.Name + " · " + by, Efforts: e.Efforts, Images: e.Images})
}
if etag != "" {
w.Header().Set("ETag", etag)
+4 -2
View File
@@ -187,17 +187,19 @@ func groupEntries(entries []Entry) []Entry {
if len(ms) == 0 {
continue
}
e := Entry{ID: GroupPrefix + g.ID, Model: ms[0].Model, Name: g.Name, Provider: ms[0].Provider, Group: g.ID}
e := Entry{ID: GroupPrefix + g.ID, Model: ms[0].Model, Name: g.Name, Provider: ms[0].Provider, Group: g.ID, Images: true}
for i, m := range ms {
if !slices.ContainsFunc(ms[:i], func(o Member) bool { return o.Provider.ID == m.Provider.ID }) {
e.Icons = append(e.Icons, m.Provider.Icon) // each provider once, "" for one without
}
var efforts []string
images := false
for _, x := range entries {
if x.Provider.ID == m.Provider.ID && x.Model == m.Model {
efforts = x.Efforts
efforts, images = x.Efforts, x.Images
}
}
e.Images = e.Images && images
if i == 0 {
e.Efforts = efforts
continue
+21
View File
@@ -31,3 +31,24 @@ func TestAutoGroupsSameModel(t *testing.T) {
}
}
// A group takes images only when every member does: any of them may be
// the one that answers.
func TestGroupImages(t *testing.T) {
t.Setenv("HOME", t.TempDir())
t.Setenv("XDG_CONFIG_HOME", "")
e := func(p, m string, images bool) Entry {
return Entry{ID: p + "/" + m, Model: m, Name: m, Provider: Provider{ID: p}, Images: images}
}
gs := groupEntries([]Entry{
e("a", "kimi-k3", true), e("b", "kimi-k3", true),
e("a", "glm-5.3", true), e("b", "glm-5.3", false),
})
got := map[string]bool{}
for _, g := range gs {
got[g.ID] = g.Images
}
if len(got) != 2 || !got[GroupPrefix+"auto-kimi-k3"] || got[GroupPrefix+"auto-glm-5-3"] {
t.Errorf("%v", got)
}
}
+6 -4
View File
@@ -236,9 +236,10 @@ type Entry struct {
Model string `json:"model"` // what magpie sends the vendor
Name string `json:"name"`
Efforts []string `json:"efforts,omitempty"`
Provider Provider `json:"-"` // a group's: its first member's
Group string `json:"group,omitempty"` // set on a routing group (group.go)
Icons []string `json:"-"` // a group's: its providers' icons, one per provider
Provider Provider `json:"-"` // a group's: its first member's
Group string `json:"group,omitempty"` // set on a routing group (group.go)
Icons []string `json:"-"` // a group's: its providers' icons, one per provider
Images bool `json:"images,omitempty"` // takes images as input (a group's: every member does)
}
// Catalog lists every exposed model of every ready provider, then the
@@ -256,7 +257,8 @@ func providerEntries() []Entry {
continue
}
for _, m := range p.Exposed() {
out = append(out, Entry{ID: p.ID + "/" + m.ID, Model: m.ID, Name: m.Name, Efforts: m.Efforts, Provider: p})
out = append(out, Entry{ID: p.ID + "/" + m.ID, Model: m.ID, Name: m.Name, Efforts: m.Efforts, Provider: p,
Images: m.Images || catalog.SeesImages(m.ID)})
}
}
return out