draw: a plugin's model that says it gives images alone is an image model
maonekone (Discord #feedback, 11-09): a plugin can't say which of its
models draw; magpie took a plugin's image model only by its name
(DrawsID and ImagesAPI words). Now a model the plugin lists with
modalities.output ["image"] (no text), on its openai-compatible API, is
listed among the drawers and drawn at the images API through the
plugin's fetch, whatever its name. A model that answers in text and
images still chats.
Run (mote): TestPluginDeclaredDrawerDraws red on the old code ("drawers
[]"); with only the listing change, red again (the draw went to chat
completions); green with both. go vet ./internal/gateway ok; go test
-run "Draw|Image|SenseNova|Loomy|Plugin" ./internal/gateway ok (74s).
Not tried: a real plugin declaring such a model; the full suite.
Reported-by: maonekone (Discord #feedback)
This commit is contained in:
@@ -373,7 +373,9 @@ func DrawersOf(p provider.Provider, avail func() []catalog.Model) []catalog.Mode
|
||||
if p.ModelKind(m.ID) == provider.KindVideo {
|
||||
continue
|
||||
}
|
||||
if catalog.DrawsID(m.ID) && catalog.ImagesAPI(m.ID) && p.PluginOpenAICompatible(m.ID) ||
|
||||
// or one the plugin says gives images alone, whatever its name
|
||||
// (maonekone on Discord)
|
||||
if (catalog.DrawsID(m.ID) && catalog.ImagesAPI(m.ID) || imagesOnly(m.OutputModalities)) && p.PluginOpenAICompatible(m.ID) ||
|
||||
pluginDrawsGemini(p, m.ID) && (catalog.DrawsID(m.ID) || slices.Contains(m.OutputModalities, "image")) {
|
||||
m.Provider = p.ID
|
||||
out = append(out, m)
|
||||
@@ -1145,12 +1147,23 @@ func viaFor(p provider.Provider, model string) drawVia {
|
||||
return viaImages
|
||||
}
|
||||
return viaChat
|
||||
case catalog.ImagesAPI(model):
|
||||
case catalog.ImagesAPI(model), p.IsPlugin() && pluginImagesOnly(p, model):
|
||||
return viaImages
|
||||
}
|
||||
return viaChat
|
||||
}
|
||||
|
||||
// imagesOnly is whether a model's output modalities are images and no text.
|
||||
func imagesOnly(out []string) bool {
|
||||
return slices.Contains(out, "image") && !slices.Contains(out, "text")
|
||||
}
|
||||
|
||||
// pluginImagesOnly is whether p, a plugin, lists model as giving images
|
||||
// alone: it draws at the images API, as one named for it does.
|
||||
func pluginImagesOnly(p provider.Provider, model string) bool {
|
||||
return slices.ContainsFunc(p.Available(), func(m catalog.Model) bool { return m.ID == model && imagesOnly(m.OutputModalities) })
|
||||
}
|
||||
|
||||
// answersInImages is whether p's fetched list says model answers with images
|
||||
// and no text: OpenRouter's Recraft, Riverflow, Krea and MAI Image, whose ids
|
||||
// name no images API, draw at its /images as FLUX and Seedream do, and only
|
||||
|
||||
@@ -168,3 +168,36 @@ func TestSenseNovaPluginDraws(t *testing.T) {
|
||||
t.Fatalf("edit was sent %v", sent)
|
||||
}
|
||||
}
|
||||
|
||||
// A plugin's model that says it gives images alone (modalities.output
|
||||
// ["image"]) is an image model whatever its name: Settings' picker lists
|
||||
// it, and it draws on the images API through the plugin's fetch, never on
|
||||
// chat. One that answers in text and images stays a chat model
|
||||
// (maonekone on Discord).
|
||||
func TestPluginDeclaredDrawerDraws(t *testing.T) {
|
||||
t.Setenv("FAKE_DECLARED_DRAWS", "1")
|
||||
v := &senseNova{}
|
||||
pid := besideFake(t, "sensenova", v)
|
||||
p, err := provider.Find(pid)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var drawers []string
|
||||
for _, m := range Drawers(*p) {
|
||||
drawers = append(drawers, m.ID)
|
||||
}
|
||||
if !slices.Equal(drawers, []string{"jimeng-4.0"}) {
|
||||
t.Fatalf("drawers %v, want jimeng-4.0 alone", drawers)
|
||||
}
|
||||
s := New()
|
||||
code, a, raw := postImages(t, s, "/v1/images/generations", "application/json", `{"model":"`+pid+`/jimeng-4.0","prompt":"a magpie","size":"1024x1024"}`)
|
||||
if code != 200 || len(a.Data) != 1 {
|
||||
t.Fatalf("%d %s", code, raw)
|
||||
}
|
||||
if sent := v.got("/v1/images/generations"); len(sent) != 1 || !strings.Contains(sent[0], `"model":"jimeng-4.0"`) {
|
||||
t.Fatalf("generation was sent %v", sent)
|
||||
}
|
||||
if sent := v.got("/v1/chat/completions"); len(sent) != 0 {
|
||||
t.Fatalf("an image model was asked on chat: %v", sent)
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -99,6 +99,13 @@ export const FakePlugin = async ({ client }) => ({
|
||||
cfg.provider[ID].models["sensenova-u1.5-lite"] = { name: "sensenova-u1.5-lite", limit: { context: 131072, output: 32768 } }
|
||||
cfg.provider[ID].models["flux-2"] = { name: "Flux 2", provider: { npm: "@ai-sdk/anthropic" }, limit: { context: 1000, output: 100 } }
|
||||
}
|
||||
// $FAKE_DECLARED_DRAWS: image models whose names say nothing, on the
|
||||
// provider's openai-compatible: one that says it gives images alone,
|
||||
// and one that answers in text and images, which chats (maonekone)
|
||||
if (process.env.FAKE_DECLARED_DRAWS) {
|
||||
cfg.provider[ID].models["jimeng-4.0"] = { name: "Jimeng 4.0", modalities: { input: ["text", "image"], output: ["image"] }, limit: { context: 1000, output: 100 } }
|
||||
cfg.provider[ID].models["fake-canvas"] = { name: "Fake Canvas", modalities: { input: ["text"], output: ["text", "image"] }, limit: { context: 1000, output: 100 } }
|
||||
}
|
||||
// $FAKE_LOOMY: iFlytek's Loomy gateway's three image generators as its
|
||||
// /v1/models lists them (#4913), on the provider's openai-compatible;
|
||||
// all three draw on its images API
|
||||
|
||||
Reference in New Issue
Block a user