diff --git a/internal/codexcat/codexcat.go b/internal/codexcat/codexcat.go index d8faa170e..480cac78e 100644 --- a/internal/codexcat/codexcat.go +++ b/internal/codexcat/codexcat.go @@ -239,6 +239,13 @@ func entriesAt(ms []catalog.Model, after int, effort string) []any { } if m.Images { e.Modalities = append(e.Modalities, "image") + } else if !strings.HasPrefix(m.ID, "group/") { + // Codex turns a pasted image away itself, saying only that the + // model doesn't take images; /model says where that is changed + // (KimYx0207 on X). The description still ends " via magpie", + // which is how its entry is told from Codex's own + // (catalog.MagpieAdded) + e.Description = m.Name + " (text only: Accepts images is in its provider's Names & levels in magpie) via magpie" } if c := m.Context; c > 0 { // the model's or its provider's threshold, else the one for diff --git a/internal/codexcat/codexcat_test.go b/internal/codexcat/codexcat_test.go index f6f832a4a..3285f5e29 100644 --- a/internal/codexcat/codexcat_test.go +++ b/internal/codexcat/codexcat_test.go @@ -4,6 +4,7 @@ import ( "encoding/json" "os" "path/filepath" + "strings" "testing" "github.com/yetone/magpie/internal/catalog" @@ -167,3 +168,34 @@ func TestCodexCatalogServiceTiers(t *testing.T) { } } } + +// Codex turns a pasted image away for a model without "image" itself, so +// /model says such a model is text-only and where that is changed, and the +// entry still reads as magpie's (KimYx0207 on X). +func TestCodexCatalogSaysTextOnly(t *testing.T) { + home := t.TempDir() + t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) + var got struct { + Models []struct { + Slug string `json:"slug"` + Description string `json:"description"` + Modalities []string `json:"input_modalities"` + } `json:"models"` + } + json.Unmarshal(Catalog([]catalog.Model{ + {ID: "probe/text", Name: "Text"}, + {ID: "probe/sees", Name: "Sees", Images: true}, + {ID: "group/words", Name: "Words"}, + }), &got) + if len(got.Models) != 3 { + t.Fatalf("%+v", got.Models) + } + text, sees, group := got.Models[0], got.Models[1], got.Models[2] + if !strings.Contains(text.Description, "text only") || !strings.Contains(text.Description, "Names & levels") || !catalog.MagpieAdded("", text.Slug, text.Description) { + t.Errorf("text-only model: %q", text.Description) + } + if sees.Description != "Sees via magpie" || group.Description != "Words via magpie" { + t.Errorf("a model that sees, and a group: %q, %q", sees.Description, group.Description) + } +} diff --git a/internal/gateway/gateway.go b/internal/gateway/gateway.go index e458fb26c..9435acc13 100644 --- a/internal/gateway/gateway.go +++ b/internal/gateway/gateway.go @@ -1909,7 +1909,11 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro } if currentImage { call.Status, call.Error = 400, "model does not support image input" - writeError(w, from, 400, fmt.Sprintf("model %q does not support image input%s", call.Model, noSeerNote())) + group := "" + if isGroup { + group = g.Name + } + writeError(w, from, 400, fmt.Sprintf("model %q does not support image input%s%s", call.Model, textOnlyNote(p, model, group), noSeerNote())) turnedAway() return } @@ -2157,7 +2161,7 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro } if len(cands) == 0 { call.Status, call.Error = 400, "model does not support image input" - writeError(w, from, 400, fmt.Sprintf("model %q does not support image input%s", call.Model, noSeerNote())) + writeError(w, from, 400, fmt.Sprintf("model %q does not support image input%s%s", call.Model, textOnlyNote(p, model, g.Name), noSeerNote())) turnedAway() return } diff --git a/internal/gateway/image_input_test.go b/internal/gateway/image_input_test.go index 1d6b37286..e4ce8783a 100644 --- a/internal/gateway/image_input_test.go +++ b/internal/gateway/image_input_test.go @@ -12,6 +12,7 @@ import ( "github.com/yetone/magpie/internal/catalog" "github.com/yetone/magpie/internal/provider" + "github.com/yetone/magpie/internal/settings" ) func TestKnownTextOnlyModelRejectsImagesBeforeUpstream(t *testing.T) { @@ -51,6 +52,11 @@ func TestKnownTextOnlyModelRejectsImagesBeforeUpstream(t *testing.T) { if rec.Code != 400 || !strings.Contains(rec.Body.String(), "does not support image input") { t.Errorf("%s: %d %s", tc.path, rec.Code, rec.Body.String()) } + // it says why magpie takes it for text-only, and where that is + // changed (KimYx0207 on X) + if b := rec.Body.String(); !strings.Contains(b, "Probe's model list marks it as not taking images") || !strings.Contains(b, "Providers → Probe → Names & levels") { + t.Errorf("%s: doesn't say why or where: %s", tc.path, b) + } } if sent != 0 { t.Fatalf("text-only images reached upstream %d times", sent) @@ -481,3 +487,44 @@ func TestGeminiNonImageFileTranslation(t *testing.T) { }) } } + +// A model the user marked text-only themselves is turned away saying so, +// and a group with no member that takes images says that, each with where +// it is changed (KimYx0207 on X). +func TestTextOnlyRefusalSaysWhyAndWhere(t *testing.T) { + fresh(t) + noVision(t) + up := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + t.Errorf("an image for a text-only model reached upstream: %s", r.URL) + })) + defer up.Close() + if err := provider.Save(provider.Provider{ID: "probe", Name: "Probe", Chat: up.URL + "/v1", Key: "key", Models: []string{"sol", "text"}}); err != nil { + t.Fatal(err) + } + if err := catalog.SaveLive("probe", up.URL+"/v1", []catalog.Model{ + {ID: "sol", Images: true, ImageInput: imageInputBool(true)}, + {ID: "text", ImageInput: imageInputBool(false)}, + }); err != nil { + t.Fatal(err) + } + s0 := settings.Load() + s0.ModelImages = map[string]bool{"probe/sol": false} + if err := settings.Save(s0); err != nil { + t.Fatal(err) + } + if err := provider.SaveGroup(provider.Group{Name: "Words", Members: []string{"probe/text", "probe/sol"}, Routing: provider.Ordered}); err != nil { + t.Fatal(err) + } + s := New() + body := `{"model":"MODEL","messages":[{"role":"user","content":[{"type":"text","text":"read"},{"type":"image_url","image_url":{"url":"data:image/png;base64,aGVsbG8="}}]}]}` + for model, want := range map[string]string{ + "probe/sol": "Accepts images is turned off for it in magpie, in Providers → Probe → Names & levels", + "group/words": "no model in the group Words is marked as taking images", + } { + rec := httptest.NewRecorder() + s.Handler().ServeHTTP(rec, httptest.NewRequest("POST", "/v1/chat/completions", strings.NewReader(strings.Replace(body, "MODEL", model, 1)))) + if rec.Code != 400 || !strings.Contains(rec.Body.String(), want) { + t.Errorf("%s: %d %s, want %q", model, rec.Code, rec.Body.String(), want) + } + } +} diff --git a/internal/gateway/vision.go b/internal/gateway/vision.go index 9bb33eb69..c3a4b8b53 100644 --- a/internal/gateway/vision.go +++ b/internal/gateway/vision.go @@ -143,6 +143,26 @@ func missingSeerNote() string { return "" } +// textOnlyNote is what a request turned away for its image says of why +// magpie takes the model for text-only and where that is changed, so the +// reader turns on the model's switch rather than trying another model or +// reinstalling the agent (KimYx0207 on X, over mark_li21's Codex paste): the +// user's own answer, else what the provider's list says; for a group, that +// none of its members is marked as taking images. +func textOnlyNote(p provider.Provider, model string, group string) string { + if group != "" { + return fmt.Sprintf("; no model in the group %s is marked as taking images: turn on Accepts images for one that does, in its provider's Names & levels in magpie", group) + } + name := p.Name + if name == "" { + name = p.ID + } + if v, ok := provider.ImageOverride(p.ID, model); ok && !v { + return fmt.Sprintf("; Accepts images is turned off for it in magpie, in Providers → %s → Names & levels", name) + } + return fmt.Sprintf("; %s's model list marks it as not taking images: if it does, turn on Accepts images for it in magpie, in Providers → %s → Names & levels", name, name) +} + // noSeerNote is what a request turned away for an image says of why no // model described it: the picked one is missing, Image recognition is // off, or none of the models the user enabled can see.