From 8413267097c8bbef6e47409f936c21c173e140d3 Mon Sep 17 00:00:00 2001 From: yetone Date: Sat, 31 Oct 2026 14:49:05 +0800 Subject: [PATCH] catalog: a list's image/jpeg is an image, so OpenCode Go's models that see take images again (zeo9901) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit zeo9901 (CC01CC) on Discord #feedback: "magpie 中 opencode go 所有的模型似乎 都无法实现图片输入了". Their screenshot is a routing group of DeepSeek V4.1 Flash at Open Design and at OpenCode Go. Cause: OpenCode Go's own /models (https://opencode.ai/inference/go/v1/models, the same at /zen/go/v1/models) lists what a model takes as media types: deepseek-v4.1-flash's modalities.input is ["text","image/jpeg","image/png", "image/gif","image/webp"], Gemini's adds application/pdf and audio/*, and so on. catalog's live-list reader took the list word for word and asked for "image", found none, and recorded ImageInput = false, an explicit answer. entryFor puts a list's explicit answer over models.dev's (which says image), so with a working Go key every Go model was text-only: a direct pick had its image described or turned away with "model does not support image input", a group member was sent it described or not at all, and agents were told the models take text only. It used to work while Go's list spelt modalities as models.dev does, or said nothing. Fix: catalog.Kinds reads a modalities list as models.dev words it (image/* image, video/* video, audio/* audio, text/* text, application/pdf pdf, each once, an unknown word kept, nil stays nil). imageInput and the live reader's InputModalities/OutputModalities go through it, as do Codex's input_modalities, the labs rows and a decision provider's listed facts (decide.go). A list saved before this, still holding Go's media types and false, is mended when read (mendKinds), so a user sees images from the first read after the update, not the next fetch. A user's own Accepts images answer still wins. Which OpenCode Go models take images, per Go's list on 2026-10-31: deepseek-v4.1-flash, kimi-k3, kimi-k3.1-pro, kimi-k2.7-code, glm-5.3-flash, qwen3.8-max, qwen3.8-flash, qwen3.7-plus, minimax-m3, minimax-m3.1-flash, mimo-v2.6-flash, mimo-v2.6-pro, step-5-preview, gemini-4-argon, grok-4.7, gpt-6-luna, gpt-5.6-luna, claude-haiku-5-5, muse-spark-1.2/1.3-contributor. Text only: deepseek-v4-pro, glm-5.2, glm-5.3, hy3, hy4-preview, longcat-2.0, beam-free, iceman-contributor-free. Tests (fixture: four rows of Go's real list, read without a key, no test reaches the network): - TestOpenCodeGoMediaTypesSee (catalog), TestKinds, TestSavedMediaTypesListSees, TestListedFactsMediaTypesSee (provider). - Broken by hand: Kinds returning its input unchanged turns all four red (deepseek-v4.1-flash, kimi-k3, gemini-4-argon "Images false"); the mendKinds call taken out turns TestSavedMediaTypesListSees red. Run on mote at the working tree on 82b45888a (origin/main 82b45888a plus this change): - gofmt -l internal cmd: nothing. - GOOS=linux go vet -tags nogui and GOOS=windows go vet of ./internal/catalog ./internal/provider ./internal/gateway: ok. - go test -tags nogui ./internal/catalog ./internal/provider ./internal/gateway ./internal/agent -count=1 -timeout 45m: all ok (catalog 0.7s, provider 129s, gateway 665s, agent 203s). The docs paragraph was added after the run; no code changed since. The full go test ./... and the GUI suite were not run (no GUI file changed). - Rebased onto ceeb73a0f (two commits outside catalog); at the rebased tree go test -tags nogui ./internal/catalog ./internal/provider -count=1 -timeout 45m: ok (catalog 0.8s, provider 98s). Docs: gateway-routing.md, "A model that turns an image away". Not tried: a real OpenCode Go request with an image (the only Go key here has expired, and it isn't to be used). Not known: which agent and version the reporter uses; Open Design's DeepSeek in the same group is a separate provider and wasn't looked at. --- docs/subsystems/gateway-routing.md | 7 +- internal/catalog/catalog.go | 32 ++++++- internal/catalog/labs.go | 2 +- internal/catalog/live.go | 28 +++++- internal/catalog/media_types_test.go | 95 +++++++++++++++++++ .../opencode-go-models-2026-10-31.json | 1 + internal/provider/decide.go | 2 +- internal/provider/decide_media_types_test.go | 19 ++++ 8 files changed, 180 insertions(+), 6 deletions(-) create mode 100644 internal/catalog/media_types_test.go create mode 100644 internal/catalog/testdata/opencode-go-models-2026-10-31.json create mode 100644 internal/provider/decide_media_types_test.go diff --git a/docs/subsystems/gateway-routing.md b/docs/subsystems/gateway-routing.md index 40f46ad8b..014a7db40 100644 --- a/docs/subsystems/gateway-routing.md +++ b/docs/subsystems/gateway-routing.md @@ -1174,7 +1174,12 @@ Covered by `TestSearchMCPServesWebSearch`, `TestSearchMCPWithNoSearcher`, Whether a model sees is its provider's list's word (`ImageInput`), else the served entry's (`blindTo`), and a list that says nothing takes -models.dev's modalities for the model (`catalog.SeesImages`). A relay's +models.dev's modalities for the model (`catalog.SeesImages`). A list's +modalities are read as models.dev words them (`catalog.Kinds`): OpenCode +Go's `/models` names media types (`image/jpeg`, `video/mp4`, +`application/pdf`), which read word for word held no `image`, so every +Go model was text-only (zeo9901 on Discord); a list saved that way is +mended when read (`mendKinds`). A relay's copy of a model can take text only where models.dev says it sees: xyenon (Discord) picked provider-1/DeepSeek-V4.1-Flash in pi with Image recognition set, magpie sent it the raw image, DeepSeek answered 400 diff --git a/internal/catalog/catalog.go b/internal/catalog/catalog.go index fd40e7dd8..2f5c38044 100644 --- a/internal/catalog/catalog.go +++ b/internal/catalog/catalog.go @@ -195,10 +195,40 @@ func imageInput(modalities []string) *bool { if modalities == nil { return nil } - yes := slices.Contains(modalities, "image") + yes := slices.Contains(Kinds(modalities), "image") return &yes } +// Kinds is a list's modalities as models.dev words them (text, image, +// audio, video, pdf), each once and in the order first met. A vendor may +// list the media types it takes instead: OpenCode Go's /models gives +// deepseek-v4.1-flash ["text","image/jpeg","image/png","image/gif", +// "image/webp"] and Gemini's application/pdf, which read word for word +// were no "image", so every model there that sees was taken for +// text-only (zeo9901 on Discord). An unknown word is kept as it is; nil +// stays nil, a list that said nothing. +func Kinds(modalities []string) []string { + if modalities == nil { + return nil + } + out := make([]string, 0, len(modalities)) + for _, m := range modalities { + k := strings.ToLower(strings.TrimSpace(m)) + if typ, _, ok := strings.Cut(k, "/"); ok { + switch { + case typ == "image" || typ == "video" || typ == "audio" || typ == "text": + k = typ + case k == "application/pdf": + k = "pdf" + } + } + if k != "" && !slices.Contains(out, k) { + out = append(out, k) + } + } + return out +} + // Price is what a model costs, in USD per million tokens. type Price struct { Input float64 `json:"input"` diff --git a/internal/catalog/labs.go b/internal/catalog/labs.go index f6ff334d3..13f3bcc60 100644 --- a/internal/catalog/labs.go +++ b/internal/catalog/labs.go @@ -179,7 +179,7 @@ func Describe(id, name string) Model { if x, ok := lookup(id, labs); ok { m.ImageInput = imageInput(x.Modalities.Input) m.Released, m.Temperature = x.ReleaseDate, x.Temperature - m.InputModalities, m.OutputModalities = x.Modalities.Input, x.Modalities.Output + m.InputModalities, m.OutputModalities = Kinds(x.Modalities.Input), Kinds(x.Modalities.Output) } return m } diff --git a/internal/catalog/live.go b/internal/catalog/live.go index d05ec4d0d..821d7a94f 100644 --- a/internal/catalog/live.go +++ b/internal/catalog/live.go @@ -51,6 +51,10 @@ func readLive(provider string) (liveFile, error) { if err := json.Unmarshal(b, &f); err != nil { return f, err } + mendKinds(f.Models) + for _, side := range f.Sides { + mendKinds(side) + } f.byID = map[string][]Model{} for _, m := range Chat(f.Models) { f.byID[m.ID] = append(f.byID[m.ID], m) @@ -59,6 +63,24 @@ func readLive(provider string) (liveFile, error) { }) } +// mendKinds reads a list saved before Kinds as Kinds reads it now: an +// OpenCode Go list kept with media types ("image/jpeg") said its models +// took no image until it was fetched again, so a model that sees is told +// so from the first read after the update, not the next fetch. +func mendKinds(ms []Model) { + for i := range ms { + m := &ms[i] + if m.InputModalities == nil { + continue + } + m.InputModalities, m.OutputModalities = Kinds(m.InputModalities), Kinds(m.OutputModalities) + if m.ImageInput != nil && !*m.ImageInput && slices.Contains(m.InputModalities, "image") { + yes := true + m.ImageInput, m.Images = &yes, true + } + } +} + // LiveByID are the models of Live with this id, in the list's order // (a list may name one twice): what a look through Live finds, without // the list copied for each model asked about. @@ -616,7 +638,8 @@ func fetchPage(ctx context.Context, url, key string, anthropic bool, headers map if name == "" { name = id } - input := imageInput(r.Modalities.Input) + ins, outs := Kinds(r.Modalities.Input), Kinds(r.Modalities.Output) + input := imageInput(ins) apis := EndpointAPIs(r.Endpoints) if native := EndpointAPIs(r.Native); len(native) > 0 { apis = native @@ -625,7 +648,7 @@ func fetchPage(ctx context.Context, url, key string, anthropic bool, headers map apis = targetAPIs(r.TypeTarget) } m := Model{ID: id, Name: name, Plain: plain, ImageInput: input, APIs: apis, Draws: drawer, Films: films, Decides: decision, - InputModalities: r.Modalities.Input, OutputModalities: r.Modalities.Output} + InputModalities: ins, OutputModalities: outs} if n, ok := r.ContextLength.(float64); ok && n > 0 { m.Context = int(n) } @@ -792,6 +815,7 @@ func codexFacts(m *Model, r liveModel, raw json.RawMessage) { in = append(in, s) } } + in = Kinds(in) m.InputModalities, m.ImageInput = in, imageInput(in) m.Images = *m.ImageInput } diff --git a/internal/catalog/media_types_test.go b/internal/catalog/media_types_test.go new file mode 100644 index 000000000..397038e83 --- /dev/null +++ b/internal/catalog/media_types_test.go @@ -0,0 +1,95 @@ +package catalog + +import ( + "context" + "net/http" + "net/http/httptest" + "os" + "slices" + "testing" +) + +// OpenCode Go's /models lists what a model takes as media types +// ("image/jpeg", "video/mp4", "application/pdf"), not models.dev's words. +// Read word for word there was no "image" in them, so every Go model that +// sees was taken for text-only, its list's answer over models.dev's +// (zeo9901 on Discord: no Go model took an image). The rows are Go's own, +// as its list answered on 2026-10-31. +func TestOpenCodeGoMediaTypesSee(t *testing.T) { + body, err := os.ReadFile("testdata/opencode-go-models-2026-10-31.json") + if err != nil { + t.Fatal(err) + } + srv := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { + rw.Write(body) + })) + defer srv.Close() + ms, _, err := FetchAt(context.Background(), srv.URL+"/v1", "k", false, nil) + if err != nil { + t.Fatal(err) + } + want := map[string]struct { + images bool + in []string + }{ + "deepseek-v4.1-flash": {true, []string{"text", "image"}}, + "kimi-k3": {true, []string{"text", "image", "video"}}, + "gemini-4-argon": {true, []string{"text", "image", "video", "audio", "pdf"}}, + "glm-5.2": {false, []string{"text"}}, + } + if len(ms) != len(want) { + t.Fatalf("%d models, want %d: %+v", len(ms), len(want), ms) + } + for _, m := range ms { + w, ok := want[m.ID] + if !ok { + t.Errorf("unexpected %s", m.ID) + continue + } + if m.ImageInput == nil || *m.ImageInput != w.images || m.Images != w.images { + t.Errorf("%s: Images %v ImageInput %v, want %v", m.ID, m.Images, m.ImageInput, w.images) + } + if !slices.Equal(m.InputModalities, w.in) { + t.Errorf("%s: input %v, want %v", m.ID, m.InputModalities, w.in) + } + if !slices.Equal(m.OutputModalities, []string{"text"}) { + t.Errorf("%s: output %v", m.ID, m.OutputModalities) + } + } +} + +func TestKinds(t *testing.T) { + for _, c := range []struct{ in, want []string }{ + {nil, nil}, + {[]string{}, []string{}}, + {[]string{"text", "image"}, []string{"text", "image"}}, + {[]string{"text", "image/png", "IMAGE/JPEG", "audio/wav", "video/mp4", "application/pdf", "text/plain"}, []string{"text", "image", "audio", "video", "pdf"}}, + {[]string{"text", "file", "application/zip"}, []string{"text", "file", "application/zip"}}, + } { + if got := Kinds(c.in); !slices.Equal(got, c.want) || (got == nil) != (c.want == nil) { + t.Errorf("Kinds(%q) = %q, want %q", c.in, got, c.want) + } + } +} + +// A list saved before Kinds, its media types kept as Go gave them and its +// models taken for text-only, is read as seeing from the first read after +// the update, not only once it is fetched again. +func TestSavedMediaTypesListSees(t *testing.T) { + no := false + saved := []Model{ + {ID: "kimi-k3", ImageInput: &no, InputModalities: []string{"text", "image/jpeg", "image/png", "video/mp4"}, OutputModalities: []string{"text"}}, + {ID: "glm-5.2", ImageInput: &no, InputModalities: []string{"text"}, OutputModalities: []string{"text"}}, + } + if err := SaveLive("opencode-go-saved", "https://opencode.ai/zen/go/v1", saved); err != nil { + t.Fatal(err) + } + k := LiveByID("opencode-go-saved", "kimi-k3") + if len(k) != 1 || k[0].ImageInput == nil || !*k[0].ImageInput || !k[0].Images || !slices.Equal(k[0].InputModalities, []string{"text", "image", "video"}) { + t.Errorf("kimi-k3 read back as %+v", k) + } + g := LiveByID("opencode-go-saved", "glm-5.2") + if len(g) != 1 || g[0].ImageInput == nil || *g[0].ImageInput || g[0].Images { + t.Errorf("glm-5.2 read back as %+v", g) + } +} diff --git a/internal/catalog/testdata/opencode-go-models-2026-10-31.json b/internal/catalog/testdata/opencode-go-models-2026-10-31.json new file mode 100644 index 000000000..4ddbccba1 --- /dev/null +++ b/internal/catalog/testdata/opencode-go-models-2026-10-31.json @@ -0,0 +1 @@ +{"object":"list","data":[{"id":"deepseek-v4.1-flash","object":"model","created":1793428469,"owned_by":"opencode","name":"DeepSeek V4.1 Flash","canonical_id":"deepseek/deepseek-v4.1-flash","type":"chat","description":"DeepSeek V4.1 Flash model for reasoning and agentic coding","family":"deepseek-flash","open_weights":true,"knowledge":"2025-05","release_date":"2026-09-10","last_updated":"2026-09-10","modalities":{"input":["text","image/jpeg","image/png","image/gif","image/webp"],"output":["text"]},"capabilities":{"tools":{"supported":true},"reasoning":{"supported":true,"effort":["low","high","max"]},"structured_output":true,"temperature":true,"top_p":true,"top_k":true,"system_updates":true,"effort_updates":false},"limit":{"context":1000000,"output":384000},"cost":{"text":{"input":{"price":0.15,"cache":{"read":0.003}},"output":{"price":0.6}},"multipliers":[{"when":{"utc_days":{"in":["mon","tue","wed","thu","fri"]},"any":[{"all":[{"utc_hours":{"gte":"01:00"}},{"utc_hours":{"lt":"04:00"}}]},{"all":[{"utc_hours":{"gte":"06:00"}},{"utc_hours":{"lt":"10:00"}}]}]},"factor":2}]},"api":{"chat-completions":{"base_url":"https://opencode.ai/inference/go/openai/v1","sdk":{"aisdk":"@ai-sdk/openai-compatible","opencodeai":"@opencode/ai/providers/openai-compatible"},"compatibility":{"reasoning_field":"reasoning_content"},"capabilities":{"tools":{"choice":["auto","none","required","tool"],"updates":false}}}}},{"id":"glm-5.2","object":"model","created":1793428469,"owned_by":"opencode","name":"GLM-5.2","canonical_id":"zhipuai/glm-5.2","type":"chat","description":"Open flagship GLM for long-horizon coding agents and million-token context work","family":"glm","open_weights":true,"release_date":"2026-06-13","last_updated":"2026-06-13","modalities":{"input":["text"],"output":["text"]},"capabilities":{"tools":{"supported":true},"reasoning":{"supported":true,"effort":["high","max"]},"structured_output":true,"temperature":true,"top_p":true,"top_k":true,"system_updates":true,"effort_updates":false},"limit":{"context":1000000,"output":131072},"cost":{"text":{"input":{"price":1.4,"cache":{"read":0.26}},"output":{"price":4.4}}},"api":{"chat-completions":{"base_url":"https://opencode.ai/inference/go/openai/v1","sdk":{"aisdk":"@ai-sdk/openai-compatible","opencodeai":"@opencode/ai/providers/openai-compatible"},"compatibility":{"reasoning_field":"reasoning_content"},"capabilities":{"tools":{"choice":["auto"],"updates":false}}}}},{"id":"kimi-k3","object":"model","created":1793428469,"owned_by":"opencode","name":"Kimi K3","canonical_id":"moonshotai/kimi-k3","type":"chat","description":"Multimodal Kimi model with 1M context and toggleable max-effort thinking for long-horizon agent work","family":"kimi-k3","open_weights":true,"release_date":"2026-07-16","last_updated":"2026-07-16","modalities":{"input":["text","image/jpeg","image/png","image/gif","image/webp","image/bmp","image/heic","image/heif","video/mp4","video/mpeg","video/mov","video/avi","video/x-flv","video/mpg","video/webm","video/wmv","video/3gpp"],"output":["text"]},"capabilities":{"tools":{"supported":true},"reasoning":{"supported":true,"effort":["max"]},"structured_output":true,"temperature":false,"top_p":false,"top_k":false,"system_updates":true,"effort_updates":false},"limit":{"context":1048576,"output":131072},"cost":{"text":{"input":{"price":3,"cache":{"read":0.3,"write":3}},"output":{"price":15}}},"api":{"chat-completions":{"base_url":"https://opencode.ai/inference/go/openai/v1","sdk":{"aisdk":"@ai-sdk/openai-compatible","opencodeai":"@opencode/ai/providers/openai-compatible"},"compatibility":{"reasoning_field":"reasoning_content"},"capabilities":{"tools":{"strict":true,"choice":["auto","none","required"],"updates":true}}}}},{"id":"gemini-4-argon","object":"model","created":1793428469,"owned_by":"opencode","name":"Gemini 4 Argon","canonical_id":"google/gemini-4-argon","type":"chat","description":"Google's flagship reasoning model for complex software engineering, deep math and science, and long-horizon autonomous agents","family":"gemini","open_weights":false,"knowledge":"2026-03","release_date":"2026-10-13","last_updated":"2026-10-13","modalities":{"input":["text","image/png","image/jpeg","image/webp","image/heic","image/heif","video/mp4","video/mpeg","video/mov","video/avi","video/x-flv","video/mpg","video/webm","video/wmv","video/3gpp","audio/wav","audio/mp3","audio/aiff","audio/aac","audio/ogg","audio/flac","audio/mpeg","audio/m4a","audio/l16","audio/opus","audio/alaw","audio/mulaw","audio/webm","application/pdf"],"output":["text"]},"capabilities":{"tools":{"supported":true},"reasoning":{"supported":true,"effort":["low","medium","high"]},"cache":{"implicit":true},"structured_output":true,"temperature":false,"top_p":false,"top_k":false,"system_updates":false,"effort_updates":false},"limit":{"context":1048576,"output":65536},"cost":{"text":{"input":{"price":2,"cache":{"read":0.1}},"output":{"price":10}},"audio":{"input":{"price":2}},"multipliers":[{"when":{"date":{"gte":"2026-12-01"}},"factor":2}]},"api":{"generate-content":{"base_url":"https://opencode.ai/inference/go/google/v1beta","sdk":{"aisdk":"@ai-sdk/google","opencodeai":"@opencode/ai/providers/google"},"capabilities":{"tools":{"choice":["auto","none","required","tool"],"updates":false}}}}}]} \ No newline at end of file diff --git a/internal/provider/decide.go b/internal/provider/decide.go index d41769aec..7463c5c82 100644 --- a/internal/provider/decide.go +++ b/internal/provider/decide.go @@ -1020,7 +1020,7 @@ type listedFacts struct { func (f listedFacts) model(name string) catalog.Model { m := catalog.Model{ID: name, Name: name, Context: cmp.Or(f.ContextLength, f.ContextWindow)} if in := cmp.Or(len(f.Architecture.InputModalities), len(f.Modalities.Input)); in > 0 { - images := slices.Contains(f.Architecture.InputModalities, "image") || slices.Contains(f.Modalities.Input, "image") + images := slices.Contains(catalog.Kinds(f.Architecture.InputModalities), "image") || slices.Contains(catalog.Kinds(f.Modalities.Input), "image") m.ImageInput, m.Images = &images, images } return m diff --git a/internal/provider/decide_media_types_test.go b/internal/provider/decide_media_types_test.go new file mode 100644 index 000000000..00089bd5f --- /dev/null +++ b/internal/provider/decide_media_types_test.go @@ -0,0 +1,19 @@ +package provider + +import "testing" + +// A decision provider's list that names media types ("image/png") rather +// than models.dev's words says its model sees, as OpenCode Go's does +// (catalog.Kinds); one that lists text alone says it doesn't. +func TestListedFactsMediaTypesSee(t *testing.T) { + var f listedFacts + f.Modalities.Input = []string{"text", "image/jpeg", "image/png"} + if m := f.model("m"); m.ImageInput == nil || !*m.ImageInput || !m.Images { + t.Errorf("media types: %+v", m) + } + f = listedFacts{} + f.Architecture.InputModalities = []string{"text"} + if m := f.model("m"); m.ImageInput == nil || *m.ImageInput || m.Images { + t.Errorf("text only: %+v", m) + } +}