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.
186 lines
5.6 KiB
Go
186 lines
5.6 KiB
Go
package catalog
|
|
|
|
// models.dev keeps two lists. api.json is each provider's models, with
|
|
// what that host charges; models.json is each lab's models (labs/<maker>),
|
|
// with only what is the model's on every host: name, window, reply limit,
|
|
// thinking, inputs, release. A model can be in the second alone: models.dev
|
|
// took the gated Claude Mythos 5.1 out of anthropic's provider list
|
|
// (models.dev #11327) and kept its lab file (#11328), since not every
|
|
// account may call it. An account that has it still lists it — Anthropic's
|
|
// /v1/models with its key, the models Claude Code was told a Claude account
|
|
// has — and magpie describes it from its lab file (iebb on Discord).
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"os"
|
|
"path/filepath"
|
|
"slices"
|
|
"strings"
|
|
"sync/atomic"
|
|
)
|
|
|
|
// LabsPath is where Sync keeps models.dev's lab catalog (models.json),
|
|
// beside its provider catalog.
|
|
func LabsPath() string { return filepath.Join(filepath.Dir(CachePath()), "labs.json") }
|
|
|
|
// labsTried is set once this process asked models.dev for its lab
|
|
// catalog, answered or not: one models.dev stops serving doesn't have the
|
|
// provider catalog fetched again every hour (Stale).
|
|
var labsTried atomic.Bool
|
|
|
|
// labsURL is the lab catalog beside the provider catalog modelsDevURL
|
|
// names, or "" when it names none (a test's own server root).
|
|
func labsURL() string {
|
|
if base, ok := strings.CutSuffix(modelsDevURL, "/api.json"); ok {
|
|
return base + "/models.json"
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// readLabs is the lab catalog Sync kept, by "lab/model", or none when it
|
|
// has none or can't be read: the provider catalog answers alone, as it did
|
|
// before there was one.
|
|
func readLabs() map[string]mdModel {
|
|
b, err := os.ReadFile(LabsPath())
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
var m map[string]mdModel
|
|
if json.Unmarshal(b, &m) != nil {
|
|
return nil
|
|
}
|
|
return m
|
|
}
|
|
|
|
// syncLabs fetches the lab catalog into LabsPath, written whole through a
|
|
// rename. A failed fetch keeps the one kept before.
|
|
func syncLabs(ctx context.Context) error {
|
|
u := labsURL()
|
|
if u == "" {
|
|
return nil
|
|
}
|
|
labsTried.Store(true)
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
req.Header.Set("User-Agent", "magpie")
|
|
resp, err := http.DefaultClient.Do(req)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer resp.Body.Close()
|
|
if resp.StatusCode != http.StatusOK {
|
|
return fmt.Errorf("models.dev labs: %s", resp.Status)
|
|
}
|
|
b, err := io.ReadAll(io.LimitReader(resp.Body, 64<<20))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
var probe map[string]mdModel
|
|
if err := json.Unmarshal(b, &probe); err != nil || len(probe) == 0 {
|
|
return fmt.Errorf("models.dev labs: unexpected payload")
|
|
}
|
|
p := LabsPath()
|
|
if err := os.MkdirAll(filepath.Dir(p), 0o755); err != nil {
|
|
return err
|
|
}
|
|
tmp, err := os.CreateTemp(filepath.Dir(p), ".labs-*.json")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if _, err := tmp.Write(b); err != nil {
|
|
tmp.Close()
|
|
os.Remove(tmp.Name())
|
|
return err
|
|
}
|
|
if err := tmp.Close(); err != nil {
|
|
os.Remove(tmp.Name())
|
|
return err
|
|
}
|
|
if err := os.Chmod(tmp.Name(), 0o644); err != nil {
|
|
os.Remove(tmp.Name())
|
|
return err
|
|
}
|
|
if err := os.Rename(tmp.Name(), p); err != nil {
|
|
os.Remove(tmp.Name())
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// labsMissing says the provider catalog is magpie's own but no lab catalog
|
|
// was kept beside it, and none was asked for yet: one kept before magpie
|
|
// read labs is fetched again at once, not a day later.
|
|
func labsMissing() bool {
|
|
if labsTried.Load() || labsURL() == "" || Source() != CachePath() {
|
|
return false
|
|
}
|
|
_, err := os.Stat(LabsPath())
|
|
return err != nil
|
|
}
|
|
|
|
// labKinEfforts gives a lab-only model that thinks and lists no levels
|
|
// (lab files have none) the levels of the newest thinking model of its
|
|
// family released by then that any provider gives levels: Claude Mythos
|
|
// 5.1 takes Mythos 5's. Called under loadMu, as the tables are built.
|
|
func labKinEfforts(all map[string]mdProvider) {
|
|
type kin struct{ id, date string }
|
|
byFamily := map[string][]kin{}
|
|
for _, p := range all {
|
|
for id, x := range p.Models {
|
|
if x.Family != "" {
|
|
byFamily[x.Family] = append(byFamily[x.Family], kin{bareID(id), x.ReleaseDate})
|
|
}
|
|
}
|
|
}
|
|
for b, x := range labs {
|
|
if len(efforts[b]) > 0 || !thinks[b] || x.Family == "" {
|
|
continue
|
|
}
|
|
var best kin
|
|
for _, k := range byFamily[x.Family] {
|
|
if len(efforts[k.id]) == 0 || !thinks[k.id] || x.ReleaseDate != "" && k.date > x.ReleaseDate {
|
|
continue
|
|
}
|
|
if best.id == "" || k.date > best.date || k.date == best.date && k.id > best.id {
|
|
best = k
|
|
}
|
|
}
|
|
if best.id != "" {
|
|
efforts[b] = slices.Clone(efforts[best.id])
|
|
}
|
|
}
|
|
}
|
|
|
|
// Describe is a model a vendor or an account lists by id, described as
|
|
// models.dev knows it on any host — most providers' word, else its lab's —
|
|
// for a list that has it where the provider's own catalog doesn't: its
|
|
// window, reply limit, thinking, levels, images and release. name is the
|
|
// list's own, kept when it gives one. It has no price: a lab gives none,
|
|
// and another host's isn't this one's.
|
|
func Describe(id, name string) Model {
|
|
load()
|
|
m := Model{ID: id, Name: strings.TrimSpace(name)}
|
|
if m.Name == "" || m.Name == id {
|
|
m.Name = id
|
|
if n := NameOf(id); n != "" {
|
|
m.Name = n
|
|
}
|
|
}
|
|
m.Context, m.Output = ContextOf(id), OutputOf(id)
|
|
m.Efforts = EffortsOf(id)
|
|
m.Reasoning = Thinks(id) || len(m.Efforts) > 0
|
|
m.Images = SeesImages(id)
|
|
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 = Kinds(x.Modalities.Input), Kinds(x.Modalities.Output)
|
|
}
|
|
return m
|
|
}
|