Before, if the picked model didn't resolve (its provider removed or turned off, or the model gone), seer() and drawer() quietly fell back to AutoVision/AutoDrawer. Settings still showed the gone id as the pick, and Routing showed only the automatic model. The turn still goes ahead with the automatic model, so nothing the user sends breaks. What changed is that magpie now says so:
- VisionMissing and DrawerMissing (pickedMissing) name the pick that doesn't resolve. /api/settings carries them as visionMissing and imageGenMissing.
- CallFor.Missing is set on every description (withDescribeFor). This covers the single-model and group paths and every protocol. routing.js tells that story first.
- With no automatic describer either, the 400 and 502 a turn is refused with name the missing pick and where to change it. So does a draw request that names no model.
- renderImages and renderImageGen show "<id> · missing" in the picker and a red line under the row. The line names what stands in, or says nothing does, and asks the user to pick another model.
- zh, zh-TW, ja and de are translated.
Verified:
- New internal/gateway/vision_missing_test.go. I took out the behaviour (Missing on the row, the notes, the draw message) but kept the helpers so it compiles. Both tests then FAIL:
vision_missing_test.go:80: probe/text anthropic: the description's row is for {Agent:other Model:probe/text Unknown:false Missing:}, want it to name the missing gone/bigeye
(the same on responses, codex and chat, and for group/mixed)
vision_missing_test.go:116: probe/text with no describer: 400 ... "model \"probe/text\" does not support image input"
vision_missing_test.go:135: no drawer: 400 ... "no model to draw with: pick one in magpie's Settings → Images → Image generation, or name one"
- New internal/gui/tests/images-missing.test.cjs checks Settings › Models in en and zh at 1000px and 360px: the picker text, the line inside its row, and no page overflow. A pick that is found shows as before. routing-vision-why.test.cjs gains the missing row. With app.js and routing.js from before this change (Chromium): pass 2, fail 7.
- node --test images-missing, routing-vision-why, routing-side-calls, settings-sections, gui-ja, gui-de, gui-zh-tw and i18n-keys in Chromium and WebKit: 42 pass, 0 fail.
- go vet -tags nogui ./internal/gateway ./internal/gui passes on darwin, GOOS=linux and GOOS=windows. go build -tags nogui ./... passes.
- HOME=<tmp> go test -tags nogui ./internal/gateway ./internal/gui: ok (208.5s, 36.9s).
Not verified: no real magpie instance with a provider actually removed. The gateway was exercised through Handler with fake upstreams, and the GUI with a faked /api/settings. Drawing's own Routing row still doesn't say its model fell back: drawing calls have no story in kindWhy. Only the Settings row and the refusal say it.
145 lines
5.7 KiB
Go
145 lines
5.7 KiB
Go
package gateway
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
// pickVision saves the Image recognition model the user picked.
|
|
func pickVision(t *testing.T, v string) {
|
|
t.Helper()
|
|
st := settings.Load()
|
|
st.Vision = v
|
|
if err := settings.Save(st); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
// An Image recognition model the user picked that magpie can't find any
|
|
// more (its provider removed) is not replaced in silence by the one magpie
|
|
// picks: the description's row in Routing names it, on every route an
|
|
// agent sends an image by and for a group's member, and a request turned
|
|
// away for want of any describer says it is missing.
|
|
func TestMissingImageRecognitionModelIsSaid(t *testing.T) {
|
|
s, u := eyed(t)
|
|
pickVision(t, "gone/bigeye")
|
|
if m, ok := seer(); !ok || m != "probe/eye" {
|
|
t.Fatalf("seer = %q %v, want the automatic probe/eye", m, ok)
|
|
}
|
|
if got := VisionMissing(); got != "gone/bigeye" {
|
|
t.Fatalf("VisionMissing = %q", got)
|
|
}
|
|
if err := provider.SaveGroup(provider.Group{Name: "Mixed", Members: []string{"probe/text", "probe/eye"}, Routing: provider.Ordered}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
img := 0
|
|
src := func() string {
|
|
img++
|
|
return fmt.Sprintf("data:image/png;base64,aW1n%03d=", img)
|
|
}
|
|
bodies := map[string]func(model string) (string, string){
|
|
"responses": func(m string) (string, string) {
|
|
return "/v1/responses", `{"model":"` + m + `","input":[{"role":"user","content":[{"type":"input_text","text":"read"},{"type":"input_image","image_url":"` + src() + `"}]}]}`
|
|
},
|
|
"codex": func(m string) (string, string) {
|
|
return CodexPath + "/responses", `{"model":"` + m + `","stream":true,"input":[{"role":"user","content":[{"type":"input_text","text":"read"},{"type":"input_image","image_url":"` + src() + `"}]}]}`
|
|
},
|
|
"chat": func(m string) (string, string) {
|
|
return "/v1/chat/completions", `{"model":"` + m + `","messages":[{"role":"user","content":[{"type":"text","text":"read"},{"type":"image_url","image_url":{"url":"` + src() + `"}}]}]}`
|
|
},
|
|
"anthropic": func(m string) (string, string) {
|
|
data := strings.TrimPrefix(src(), "data:image/png;base64,")
|
|
return "/v1/messages", `{"model":"` + m + `","max_tokens":16,"messages":[{"role":"user","content":[{"type":"text","text":"read"},{"type":"image","source":{"type":"base64","media_type":"image/png","data":"` + data + `"}}]}]}`
|
|
},
|
|
}
|
|
for _, model := range []string{"probe/text", "group/mixed"} {
|
|
for name, body := range bodies {
|
|
before := len(s.trace.routes)
|
|
path, b := body(model)
|
|
rec := httptest.NewRecorder()
|
|
s.Handler().ServeHTTP(rec, httptest.NewRequest("POST", path, strings.NewReader(b)))
|
|
if rec.Code != 200 {
|
|
t.Fatalf("%s %s: %d %s", model, name, rec.Code, rec.Body.String())
|
|
}
|
|
var vision *Route
|
|
for _, r := range s.trace.routes[before:] {
|
|
if r.Kind == "vision" {
|
|
vision = r
|
|
}
|
|
}
|
|
if vision == nil || vision.Model != "probe/eye" || vision.For == nil {
|
|
t.Fatalf("%s %s: no description by probe/eye in Routing: %+v", model, name, vision)
|
|
}
|
|
if vision.For.Missing != "gone/bigeye" {
|
|
t.Errorf("%s %s: the description's row is for %+v, want it to name the missing gone/bigeye", model, name, *vision.For)
|
|
}
|
|
}
|
|
}
|
|
if n := len(u.sent("eye")); n != 8 {
|
|
t.Fatalf("the automatic describer was asked %d times, want 8", n)
|
|
}
|
|
|
|
// a picked model that resolves is not missing
|
|
pickVision(t, "probe/eye")
|
|
if got := VisionMissing(); got != "" {
|
|
t.Fatalf("VisionMissing with probe/eye = %q", got)
|
|
}
|
|
code, out := postAs(t, s, "", `{"model":"probe/text","messages":[{"role":"user","content":[{"type":"image_url","image_url":{"url":"data:image/png;base64,c2Vlbg=="}}]}]}`)
|
|
if code != 200 {
|
|
t.Fatalf("resolving vision: %d %s", code, out)
|
|
}
|
|
if r := s.trace.routes[len(s.trace.routes)-2]; r.Kind != "vision" || r.For == nil || r.For.Missing != "" {
|
|
t.Fatalf("resolving vision's row: kind %q for %+v", r.Kind, r.For)
|
|
}
|
|
|
|
// no model that sees to fall back on: turned away, naming the missing one
|
|
pickVision(t, "gone/bigeye")
|
|
p, _ := provider.Find("probe")
|
|
if err := catalog.SaveLive("probe", p.Chat, []catalog.Model{
|
|
{ID: "text", ImageInput: imageInputBool(false)},
|
|
{ID: "eye", ImageInput: imageInputBool(false)},
|
|
}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if m, ok := seer(); ok {
|
|
t.Fatalf("seer = %q with no model that sees", m)
|
|
}
|
|
for _, model := range []string{"probe/text", "group/mixed"} {
|
|
code, out = postAs(t, s, "", `{"model":"`+model+`","messages":[{"role":"user","content":[{"type":"image_url","image_url":{"url":"data:image/png;base64,bm9uZQ=="}}]}]}`)
|
|
if code != 400 || !strings.Contains(out, "gone/bigeye") || !strings.Contains(out, "Image recognition") {
|
|
t.Errorf("%s with no describer: %d %s, want 400 naming the missing gone/bigeye", model, code, out)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Image generation's pick is the same: one magpie can't find is named, and
|
|
// a request that names no model, with nothing else to draw with, says so.
|
|
func TestMissingImageGenerationModelIsSaid(t *testing.T) {
|
|
s, _ := eyed(t)
|
|
st := settings.Load()
|
|
st.ImageGen = "gone/gpt-image-2"
|
|
if err := settings.Save(st); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := DrawerMissing(); got != "gone/gpt-image-2" {
|
|
t.Fatalf("DrawerMissing = %q", got)
|
|
}
|
|
code, _, raw := postImages(t, s, "/v1/images/generations", "application/json", `{"prompt":"a magpie"}`)
|
|
if code != 400 || !strings.Contains(raw, "gone/gpt-image-2") || !strings.Contains(raw, "Image generation") {
|
|
t.Fatalf("no drawer: %d %s, want 400 naming the missing gone/gpt-image-2", code, raw)
|
|
}
|
|
st.ImageGen = "off"
|
|
if err := settings.Save(st); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := DrawerMissing(); got != "" {
|
|
t.Fatalf("DrawerMissing with off = %q", got)
|
|
}
|
|
}
|