settings: a MiniMax key kept for images can be picked in Settings → Images (netube99 on X)

Settings → Images checked the pick with provider.Resolve, which finds no
model of a key set to Select none (it serves no chat model), so
minimax-cn/MiniMax-H3-Image was refused with "no model ... to generate
images", and resolveDrawing, which the gateway draws through, refused it the
same way. image-01, image-01-live and -Highspeed and the international
minimax provider had the same gap. Settings now asks gateway.DrawerMissingOf
(the Drawers of the provider count), and resolveDrawing falls back to the
provider's Drawers when Resolve finds nothing.

Request shape checked against platform.minimax.io/docs/guides/image-generation:
POST /v1/images/generations (api.minimax.io; the CN key's host likewise), as
draw_minimax.go already sends it.

Run: TestMiniMaxImageModelPickable (both providers; all, none, picks; every
image model; one real draw through the gateway against a fake host) and
TestImageGenAcceptsMiniMaxImageModel, red on the old code (Select none case,
settings check reverted by hand). No real MiniMax account was asked.
This commit is contained in:
yetone
2026-11-12 23:37:30 +08:00
parent 8cacbaa7d4
commit a5e5f539ad
4 changed files with 91 additions and 2 deletions
+20 -1
View File
@@ -114,9 +114,19 @@ func DrawerMissing() string { return drawerMissing(settings.Load().ImageGen) }
// drawerMissing is v, an Image generation pick, when magpie can't draw
// with it: pickedMissing's, and a routing group ("group/<id>", 7up6666 on
// X) none of whose members draws any more.
// DrawerMissingOf is drawerMissing: what Settings checks an Image
// generation pick with before it saves it.
func DrawerMissingOf(v string) string { return drawerMissing(v) }
func drawerMissing(v string) string {
if !provider.IsGroupRef(v) {
return pickedMissing(v)
if v == "" || v == "off" {
return ""
}
if _, _, ok := resolveDrawing(v); ok {
return ""
}
return v
}
// a group of image models only is no model agents are offered, so
// Resolve doesn't take it: it is missing when none of it draws
@@ -172,6 +182,15 @@ func resolveDrawing(id string) (provider.Provider, string, bool) {
return provider.Resolve(id)
}
if strings.Contains(id, "/") {
if p, m, ok := provider.Resolve(id); ok {
return p, m, true
}
// an image model of a key kept for them: Select none serves no
// chat model, yet the key still draws (netube99 on X, minimax-cn)
pid, model, _ := strings.Cut(id, "/")
if p, err := provider.Find(pid); err == nil && p.On() && !p.DecideOnly() && drawsModel(*p, model) {
return *p, model, true
}
return provider.Resolve(id)
}
for _, p := range provider.All() {
@@ -0,0 +1,44 @@
package gateway
import (
"testing"
"github.com/yetone/magpie/internal/provider"
)
// netube99 on X: a MiniMax key kept for its image models (Select none, or
// a few chat picks) refused minimax-cn/MiniMax-H3-Image in Settings → Images
// with "no model … to generate images".
func TestMiniMaxImageModelPickable(t *testing.T) {
for _, preset := range []string{"minimax-cn", "minimax"} {
for _, state := range []string{"all", "none", "picks"} {
t.Run(preset+"/"+state, func(t *testing.T) {
s, _, p := minimaxDrawing(t, preset)
switch state {
case "none":
p.NoModels = true
case "picks":
p.Models = []string{"MiniMax-M2.7"}
}
if err := provider.Save(p); err != nil {
t.Fatal(err)
}
if state == "none" {
code, a, raw := postImages(t, s, "/v1/images/generations", "application/json", `{"model":"`+preset+`/MiniMax-H3-Image","prompt":"a cat"}`)
if code != 200 || len(a.Data) != 1 {
t.Fatalf("drew %d %s", code, raw)
}
}
for _, m := range []string{"image-01", "image-01-live", "MiniMax-H3-Image", "MiniMax-H3-Image-Highspeed"} {
ref := preset + "/" + m
if got := DrawerMissingOf(ref); got != "" {
t.Errorf("%s is missing", got)
}
if _, id, ok := resolveDrawing(ref); !ok || id != m {
t.Errorf("%s doesn't resolve for drawing: %q %v", ref, id, ok)
}
}
})
}
}
}
+1 -1
View File
@@ -414,7 +414,7 @@ func Merge(body []byte, cur settings.Settings, web bool) (settings.Settings, err
}
}
if v := strings.TrimSpace(in.ImageGen); v != "" && v != "off" && v != cur.ImageGen {
if _, _, ok := provider.Resolve(v); !ok {
if gateway.DrawerMissingOf(v) != "" {
return in, fmt.Errorf("no model %s to generate images", v)
}
}
+26
View File
@@ -360,3 +360,29 @@ func TestRestoreOnQuitKeptUnlessSent(t *testing.T) {
t.Error("restoreOnQuit sent false left it on")
}
}
// netube99 on X: Settings → Images refused minimax-cn/MiniMax-H3-Image with
// "no model … to generate images" when the key serves no chat model.
func TestImageGenAcceptsMiniMaxImageModel(t *testing.T) {
home(t)
for _, preset := range []string{"minimax-cn", "minimax"} {
p, err := provider.FromPreset(preset)
if err != nil {
t.Fatal(err)
}
p.ID, p.Key, p.NoModels = preset, "key", true
if err := provider.Save(p); err != nil {
t.Fatal(err)
}
for _, m := range []string{"MiniMax-H3-Image", "MiniMax-H3-Image-Highspeed", "image-01"} {
body, _ := json.Marshal(map[string]any{"imageGen": preset + "/" + m})
if _, err := Merge(body, settings.Settings{}, true); err != nil {
t.Errorf("%s/%s: %v", preset, m, err)
}
}
}
body, _ := json.Marshal(map[string]any{"imageGen": "minimax-cn/nothing"})
if _, err := Merge(body, settings.Settings{}, true); err == nil {
t.Error("a model it doesn't draw was taken")
}
}