The plugin host read a model's capabilities.input only for "image", and
fromModelsDev hard-coded output to text, so /v1/models listed
opencode-zen-free's muse-spark-1.3-contributor-free (models.opencode.ai:
input text/image/audio/video/pdf) as ["text","image"] with no output.
- host.js: fromModelsDev and the config merge keep modalities.input and
.output whole; the listing sends inputs/outputs, the kinds the
capabilities object marks true, in OpenCode's order.
- plugin.Model gets Inputs/Outputs; pluginCatalog puts them on
catalog.Model's new InputModalities/OutputModalities (input only where
the plugin said what it takes, as ImageInput already is).
- catalog: models.dev entries and a vendor's live list (now reading
modalities.output) fill the same fields; Decorate carries the catalog's
when the live list says nothing, beside ImageInput.
- provider.Entry.Modalities() is what the gateway lists: the source's
kinds, with "image" still decided by Images, so the user's own
"takes images" override still wins and the other kinds stay.
Not changed: the 7 models the report lists as having lost their levels
have reasoning_options [] upstream (models.opencode.ai), so "reasoning,
no levels" is what they are; mimo-v2.6-flash turns away levels (#214).
DSH's model kinds and Muse's list still say text/image only.
Tests: TestPluginModelModalities (gateway) with the reporter's literal
metadata: muse-spark's config as opencode-zen-free 0.1.3's configModels
writes it, and mimo-v2.6-flash-free's capabilities as its models hook
lists them; a model said nothing of stays unlisted, and the image
override drops image only. TestFetchedModalitiesKeepEveryKind (catalog).
Broken by hand: host.js without inputs gives the report's [text image]
(red); Entry.Modalities without the Inputs branch (red); Decorate
without the fill (red). Run: go test catalog, plugin, provider, gateway;
gofmt -l; GOOS=linux and windows go vet on the four; go test ./...
green on 76db4c6c2+this; after rebasing on e9b16ca18 the four packages
again: catalog, plugin and gateway green; provider red once in a run of
all four together (the failing test's name was cut off by a tail), then
green 3 runs of 3, two of them concurrent.
90 lines
3.0 KiB
Go
90 lines
3.0 KiB
Go
package gateway
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// A plugin's model is listed with every kind of input and output the
|
|
// plugin says it has, not image alone, and with its levels; one that
|
|
// thinks with no level to pick says it thinks and offers none (#1595,
|
|
// tkhs101). The two models are opencode-zen-free 0.1.3's, as its config
|
|
// hook writes muse-spark and its models hook lists mimo, from
|
|
// models.opencode.ai's own entries. Whether a model takes images is still
|
|
// the user's to say.
|
|
func TestPluginModelModalities(t *testing.T) {
|
|
t.Setenv("FAKE_ZEN", "1")
|
|
pid := besideFake(t, "opencode-zen-free", &cursorUp{})
|
|
|
|
type listed struct {
|
|
Reasoning bool `json:"reasoning"`
|
|
Levels []struct{ Effort string } `json:"supported_reasoning_levels"`
|
|
Modalities *struct {
|
|
Input []string `json:"input"`
|
|
Output []string `json:"output"`
|
|
} `json:"modalities"`
|
|
}
|
|
models := func() map[string]listed {
|
|
t.Helper()
|
|
rec := httptest.NewRecorder()
|
|
New().Handler().ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/v1/models", nil))
|
|
var list struct {
|
|
Data []struct {
|
|
ID string `json:"id"`
|
|
listed
|
|
} `json:"data"`
|
|
}
|
|
if err := json.Unmarshal(rec.Body.Bytes(), &list); err != nil {
|
|
t.Fatalf("/v1/models: %v\n%s", err, rec.Body.String())
|
|
}
|
|
out := map[string]listed{}
|
|
for _, m := range list.Data {
|
|
out[m.ID] = m.listed
|
|
}
|
|
return out
|
|
}
|
|
efforts := func(m listed) []string {
|
|
out := []string{}
|
|
for _, l := range m.Levels {
|
|
out = append(out, l.Effort)
|
|
}
|
|
return out
|
|
}
|
|
check := func(got map[string]listed, id string, in, out, levels []string) {
|
|
t.Helper()
|
|
m, ok := got[pid+"/"+id]
|
|
if !ok {
|
|
t.Fatalf("%s not listed: %v", id, got)
|
|
}
|
|
if m.Modalities == nil {
|
|
t.Fatalf("%s: no modalities", id)
|
|
}
|
|
if !reflect.DeepEqual(m.Modalities.Input, in) || !reflect.DeepEqual(m.Modalities.Output, out) {
|
|
t.Errorf("%s: modalities in %v out %v, want in %v out %v", id, m.Modalities.Input, m.Modalities.Output, in, out)
|
|
}
|
|
if !m.Reasoning || !reflect.DeepEqual(efforts(m), levels) {
|
|
t.Errorf("%s: reasoning %v at %v, want true at %v", id, m.Reasoning, efforts(m), levels)
|
|
}
|
|
}
|
|
|
|
got := models()
|
|
check(got, "muse-spark-1.3-contributor-free", []string{"text", "image", "audio", "video", "pdf"}, []string{"text"}, []string{"minimal", "low", "medium", "high", "xhigh"})
|
|
check(got, "mimo-v2.6-flash-free", []string{"text", "image", "audio", "video"}, []string{"text"}, []string{})
|
|
// a model the plugin says nothing of takes what isn't known
|
|
if m := got[pid+"/fake-1"]; m.Modalities != nil && m.Modalities.Input != nil {
|
|
t.Errorf("fake-1, not said of, takes %v", m.Modalities.Input)
|
|
}
|
|
|
|
// the user says mimo takes no images: the rest it takes stays
|
|
no := false
|
|
if err := provider.SetModelImage(pid+"/mimo-v2.6-flash-free", &no); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
check(models(), "mimo-v2.6-flash-free", []string{"text", "audio", "video"}, []string{"text"}, []string{})
|
|
}
|