catalog: a list's image/jpeg is an image, so OpenCode Go's models that see take images again (zeo9901)
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 on82b45888a(origin/main82b45888aplus 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 ontoceeb73a0f(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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user