diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css index 11c1ca4b6..44fbe88c4 100644 --- a/internal/gui/assets/app.css +++ b/internal/gui/assets/app.css @@ -2866,8 +2866,8 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; } .row.model .minfo .mi-ctx, .rt-gedit .fbrow .minfo .mi-ctx { font-variant-numeric: tabular-nums; } /* the image chip holds a glyph, not a line of text: it is given the text chips' 16px line as its height, so it stands as tall as they do (nb5p) */ -.row.model .minfo .mi-img, .rt-gedit .fbrow .minfo .mi-img { padding: 0 4px; height: 16px; box-sizing: border-box; } -.row.model .minfo .mi-img svg, .rt-gedit .fbrow .minfo .mi-img svg { display: block; } +.row.model .minfo :is(.mi-img, .mi-media), .rt-gedit .fbrow .minfo :is(.mi-img, .mi-media) { padding: 0 4px; height: 16px; box-sizing: border-box; } +.row.model .minfo :is(.mi-img, .mi-media) svg, .rt-gedit .fbrow .minfo :is(.mi-img, .mi-media) svg { display: block; } .provider .pswitch { margin-left: 8px; } .editor .off-note { grid-column: 1 / -1; } .editor .self-note label.tick { margin-top: 6px; } diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index 272a1405f..748a0a9cc 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -1981,6 +1981,10 @@ const I18N = { "Reasoning levels: none known": "推理强度:未知", "Decision model: routing groups ask it, agents never see it": "决策模型:路由组会问它,agent 看不到它", "Accepts images (one of its models does)": "支持图片输入(组内有一个模型支持)", + "Accepts video": "支持视频输入", + "Accepts video (one of its models does)": "支持视频输入(组内有一个模型支持)", + "Accepts audio": "支持音频输入", + "Accepts audio (one of its models does)": "支持音频输入(组内有一个模型支持)", "Images: not known": "图片:未知", "Text only": "仅文本", "Context: {n} tokens": "上下文:{n} tokens", @@ -7129,6 +7133,10 @@ const I18N = { "Reasoning levels: none known": "推理強度:未知", "Decision model: routing groups ask it, agents never see it": "決策模型:路由組會問它,agent 看不到它", "Accepts images (one of its models does)": "支援圖片輸入(組內有一個模型支援)", + "Accepts video": "支援影片輸入", + "Accepts video (one of its models does)": "支援影片輸入(組內有一個模型支援)", + "Accepts audio": "支援音訊輸入", + "Accepts audio (one of its models does)": "支援音訊輸入(組內有一個模型支援)", "Images: not known": "圖片:未知", "Text only": "僅文本", "Context: {n} tokens": "上下文:{n} tokens", @@ -12251,6 +12259,10 @@ const I18N = { "Reasoning levels: none known": "推論レベル:不明", "Decision model: routing groups ask it, agents never see it": "決定モデル:ルーティンググループが問い合わせ、エージェントには見えません", "Accepts images (one of its models does)": "画像入力に対応(含まれるいずれかのモデルが対応)", + "Accepts video": "動画入力に対応", + "Accepts video (one of its models does)": "動画入力に対応(含まれるいずれかのモデルが対応)", + "Accepts audio": "音声入力に対応", + "Accepts audio (one of its models does)": "音声入力に対応(含まれるいずれかのモデルが対応)", "Images: not known": "画像:不明", "Text only": "テキストのみ", "Context: {n} tokens": "コンテキスト:{n} トークン", @@ -17404,6 +17416,10 @@ const I18N = { "Reasoning levels: none known": "Reasoning-Stufen: keine bekannt", "Decision model: routing groups ask it, agents never see it": "Entscheidungsmodell: Routing-Gruppen fragen es, Agents sehen es nie", "Accepts images (one of its models does)": "Akzeptiert Bilder (eines seiner Modelle)", + "Accepts video": "Akzeptiert Video", + "Accepts video (one of its models does)": "Akzeptiert Video (eines seiner Modelle)", + "Accepts audio": "Akzeptiert Audio", + "Accepts audio (one of its models does)": "Akzeptiert Audio (eines seiner Modelle)", "Images: not known": "Bilder: unbekannt", "Text only": "Nur Text", "Context: {n} tokens": "Kontext: {n} Token", diff --git a/internal/gui/assets/plugins/gateway/client.js b/internal/gui/assets/plugins/gateway/client.js index 410bc9db6..34236ac2c 100644 --- a/internal/gui/assets/plugins/gateway/client.js +++ b/internal/gui/assets/plugins/gateway/client.js @@ -534,6 +534,27 @@ function envSnippet(vars) { return vars.map(([k, v]) => (snipWin() ? `$env:${k}=${psHeader(v)}` : `export ${k}=${shQuote(v)}`)).join("\n"); } +// The row's chips (modelInfo) with video and audio after the image one, +// when its source listed them (pingqipai3 on X); a group's are any one of +// its models', as its images are. Their tooltip lines follow the images' +// one, the second of modelInfo's. +const MEDIA_GLYPH = { video: "M2 4.5h8.5v7H2zM10.5 7l3.5-2v6l-3.5-2", audio: "M3 6.5v3M5.5 4.5v7M8 2.5v11M10.5 4.5v7M13 6.5v3" }; +function mediaInfo(m) { + const box = modelInfo(m); + const kinds = ["video", "audio"].filter((k) => m.inputs?.includes(k)); + if (!kinds.length) return box; + const ctx = box.querySelector(".mi-ctx"); + const lines = box.title.split("\n"); + for (const k of kinds) { + const c = el("span", "badge mi-media mi-" + k); + c.append(svg(MEDIA_GLYPH[k], 11, 1.4)); + box.insertBefore(c, ctx); + } + lines.splice(2, 0, ...kinds.map((k) => t(k === "video" ? (m.group ? "Accepts video (one of its models does)" : "Accepts video") : m.group ? "Accepts audio (one of its models does)" : "Accepts audio"))); + box.title = lines.join("\n"); + return box; +} + // every exposed model, as the ids agents use function gatewayModels() { // the routing groups first, as the agents' pickers list them @@ -541,7 +562,7 @@ function gatewayModels() { // every model off the list const out = (providers.gateway.groups || []).filter((g) => g && typeof g.id === "string").map((g) => ({ id: g.id, name: g.name || g.id, icons: g.icons || [], group: true, provider: { name: [t("routing group"), (g.providers || []).join(", ")].filter(Boolean).join(" · ") }, - efforts: g.efforts || [], images: !!g.images, context: g.context, output: g.output, members: g.members || [] })); + efforts: g.efforts || [], images: !!g.images, inputs: g.inputs || [], context: g.context, output: g.output, members: g.members || [] })); // a provider switched off is skipped: the gateway refuses its models, so // they are not ids an agent can use, and listing them here would show a // model the picker's own list, the Gateway count and the Connect example @@ -551,7 +572,7 @@ function gatewayModels() { // levels aren't known (given) offers only those it was given; one sent // no reasoning field (reasonless) offers none const offered = (m) => m.reasonless ? [] : m.kept?.length || m.given ? m.kept || [] : m.efforts || []; - for (const p of providers.providers) { if (p.off) continue; for (const m of p.models) if (m.on) out.push({ id: `${p.id}/${m.id}`, name: m.name, provider: p, context: m.context, output: m.output, efforts: offered(m), images: !!m.images }); } + for (const p of providers.providers) { if (p.off) continue; for (const m of p.models) if (m.on) out.push({ id: `${p.id}/${m.id}`, name: m.name, provider: p, context: m.context, output: m.output, efforts: offered(m), images: !!m.images, inputs: m.inputs || [] }); } return out; } @@ -727,7 +748,7 @@ function renderGatewayModels() { const name = el("div", "name", m.id); if (namedFree(m.id, m.name)) name.append(freeBadge(false)); who.append(name, el("div", "sub", m.name && m.name !== m.id.split("/")[1] ? `${m.name} · ${m.provider.name}` : m.provider.name)); - row.append(m.group ? stackIcon(m.icons) : icon(m.provider.icon || "generic"), who, modelInfo(m), copyBtn(m.id, t("Model id"))); + row.append(m.group ? stackIcon(m.icons) : icon(m.provider.icon || "generic"), who, mediaInfo(m), copyBtn(m.id, t("Model id"))); row.title = t("Use this model in the snippets"); // a decision model is put in System One's snippets, any other in the // other APIs'; the API follows the model clicked diff --git a/internal/gui/media_inputs_test.go b/internal/gui/media_inputs_test.go new file mode 100644 index 000000000..83c4e275f --- /dev/null +++ b/internal/gui/media_inputs_test.go @@ -0,0 +1,74 @@ +package gui + +import ( + "os" + "slices" + "testing" + + "github.com/yetone/magpie/internal/catalog" + "github.com/yetone/magpie/internal/provider" +) + +// The Gateway list shows video and audio beside images when a model's +// source listed them (pingqipai3 on X): only those two, in that order, +// whatever form its list wrote them in. +func TestMediaInputs(t *testing.T) { + for _, c := range []struct { + in []string + want []string + }{ + {nil, nil}, + {[]string{"text", "image", "pdf"}, nil}, + {[]string{"audio", "text", "video"}, []string{"video", "audio"}}, + {[]string{"Video/MP4", "audio/wav"}, []string{"video", "audio"}}, + {[]string{"image", "audio"}, []string{"audio"}}, + } { + if got := mediaInputs(c.in); !slices.Equal(got, c.want) { + t.Errorf("mediaInputs(%q) = %q, want %q", c.in, got, c.want) + } + } +} + +// What the provider's model list says it takes reaches the Gateway list: +// each model's video and audio, and a group's from any one of its models. +func TestGatewayListSaysVideoAndAudio(t *testing.T) { + t.Setenv("HOME", t.TempDir()) + t.Setenv("USERPROFILE", os.Getenv("HOME")) + t.Setenv("XDG_CONFIG_HOME", t.TempDir()) + t.Setenv("XDG_CACHE_HOME", t.TempDir()) + if err := provider.Save(provider.Provider{ID: "p", Name: "P", Key: "k", Chat: "http://127.0.0.1:1/v1", + Models: []string{"omni", "ear", "text"}}); err != nil { + t.Fatal(err) + } + if err := catalog.SaveLive("p", "http://127.0.0.1:1/v1", []catalog.Model{ + {ID: "omni", InputModalities: []string{"text", "image", "video", "audio"}}, + {ID: "ear", InputModalities: []string{"text", "audio"}}, + {ID: "text", InputModalities: []string{"text"}}, + }); err != nil { + t.Fatal(err) + } + if err := provider.SaveGroup(provider.Group{ID: "g", Name: "G", Members: []string{"p/ear", "p/text"}}); err != nil { + t.Fatal(err) + } + s := providersState() + got := map[string][]string{} + for _, p := range s.Providers { + if p.ID == "p" { + for _, m := range p.Models { + got[m.ID] = m.Inputs + } + } + } + for id, want := range map[string][]string{"omni": {"video", "audio"}, "ear": {"audio"}, "text": nil} { + if !slices.Equal(got[id], want) { + t.Errorf("%s says %q, want %q", id, got[id], want) + } + } + i := slices.IndexFunc(s.Gateway.Groups, func(g gwGroupJSON) bool { return g.ID == "group/g" }) + if i < 0 { + t.Fatal("group/g isn't listed") + } + if g := s.Gateway.Groups[i]; !slices.Equal(g.Inputs, []string{"audio"}) { + t.Errorf("group/g says %q, want audio (one of its models takes it)", g.Inputs) + } +} diff --git a/internal/gui/providers.go b/internal/gui/providers.go index 4d08a8bf5..3898e6738 100644 --- a/internal/gui/providers.go +++ b/internal/gui/providers.go @@ -68,6 +68,9 @@ type modelJSON struct { Same string `json:"same,omitempty"` // the model the user said it is the same as, for the groups magpie finds (#583) Merge string `json:"merge,omitempty"` // what those groups merge it by when the user says nothing; absent when ID Kind string `json:"kind,omitempty"` // what the user said it makes: image or video (#1399) + // Inputs are the media beyond text and images its source listed it + // takes, video and audio (catalog.Model.InputModalities; pingqipai3 on X) + Inputs []string `json:"inputs,omitempty"` // Headers are the request headers the user gave the model, sent after // the provider's (provider.SetModelHeaders) Headers map[string]string `json:"headers,omitempty"` @@ -708,11 +711,25 @@ type gwGroupJSON struct { // output its members all hold Efforts []string `json:"efforts,omitempty"` Images bool `json:"images,omitempty"` + Inputs []string `json:"inputs,omitempty"` // video and audio, when one of its models takes them (provider.Entry.Inputs) Context int `json:"context,omitempty"` Output int `json:"output,omitempty"` Members []string `json:"members,omitempty"` // the models it sends to, provider/model, in its order } +// mediaInputs is which of video and audio a model's input kinds hold, in +// that order: what the Gateway list shows beside its images (images have +// their own flag, and pdf and text go without saying). +func mediaInputs(kinds []string) []string { + var out []string + for _, k := range []string{"video", "audio"} { + if slices.Contains(catalog.Kinds(kinds), k) { + out = append(out, k) + } + } + return out +} + type excludedJSON struct { provider.Exclusion Name string `json:"agentName"` @@ -1100,7 +1117,7 @@ func providerInfoWith(p provider.Provider, ls provider.Listing, agents []agentUs images = said } window := p.WindowIn(m, set) - j := modelJSON{ID: m.ID, Name: m.Name, Efforts: provider.EffortsOf(m), On: on, Context: window, Output: provider.OutputWithin(window, p.ReplyLimitIn(m, set)), Listed: provider.ListedWindow(m), ListedOutput: provider.OutputWithin(provider.ListedWindow(m), p.ReplyLimitIn(m, settings.Settings{})), Max: m.MaxContext, Free: m.Free, Rate: m.Rate, RateWas: m.RateWas, Images: images, ImageSet: imageSet, Own: own, Best: newest[m.ID]} + j := modelJSON{ID: m.ID, Name: m.Name, Efforts: provider.EffortsOf(m), On: on, Context: window, Output: provider.OutputWithin(window, p.ReplyLimitIn(m, set)), Listed: provider.ListedWindow(m), ListedOutput: provider.OutputWithin(provider.ListedWindow(m), p.ReplyLimitIn(m, settings.Settings{})), Max: m.MaxContext, Free: m.Free, Rate: m.Rate, RateWas: m.RateWas, Images: images, ImageSet: imageSet, Own: own, Best: newest[m.ID], Inputs: mediaInputs(m.InputModalities)} list, listed, free := pricer.Prices(set, m.ID) j.Zero = !m.Free && free // a plugin reports a model's load by its own id, not one the user @@ -1434,7 +1451,7 @@ func providersState() providersJSON { } // its lists are [] when empty, never null, which the page can't // read as a list (#1585) - g := gwGroupJSON{ID: e.ID, Name: e.Name, Icons: append([]string{}, e.Icons...), Providers: []string{}, Efforts: e.Efforts, Images: e.Images, Context: e.Context, Output: e.PublishedOutput()} + g := gwGroupJSON{ID: e.ID, Name: e.Name, Icons: append([]string{}, e.Icons...), Providers: []string{}, Efforts: e.Efforts, Images: e.Images, Inputs: mediaInputs(e.Inputs), Context: e.Context, Output: e.PublishedOutput()} if _, ms, ok := findGroup(e.ID); ok { for _, m := range ms { if id := m.Provider.ID + "/" + m.Model; !slices.Contains(g.Members, id) { diff --git a/internal/gui/tests/gateway-model-info.test.cjs b/internal/gui/tests/gateway-model-info.test.cjs index 5f385153b..761150381 100644 --- a/internal/gui/tests/gateway-model-info.test.cjs +++ b/internal/gui/tests/gateway-model-info.test.cjs @@ -2,7 +2,7 @@ // The Gateway page's model list (ARNO on Discord): a search box finds models // by id, name, provider and a group's models, and each row ends with what // agents are told of the model — its reasoning levels, whether it takes -// images, its context, its reply limit — the full detail in the chips' tooltip; a routing +// images, video or audio, its context, its reply limit — the full detail in the chips' tooltip; a routing // group's levels are what its models all have, its images any one's and its context the largest, its tooltip naming them. const assert = require("node:assert/strict"); const fs = require("node:fs/promises"); @@ -21,13 +21,13 @@ const providers = { { id: "hidden", name: "Hidden", on: false, efforts: ["low"] }, ] }, { id: "zeta", name: "Zeta Cloud", icon: "generic", agents: [], models: [ - { id: "glm-5", name: "GLM-5", on: true, efforts: ["high"], images: false, context: 1000000 }, - { id: "kimi-k3", name: "Kimi K3", on: true, given: true, efforts: ["low", "high"], images: true }, + { id: "glm-5", name: "GLM-5", on: true, efforts: ["high"], images: false, inputs: ["audio"], context: 1000000 }, + { id: "kimi-k3", name: "Kimi K3", on: true, given: true, efforts: ["low", "high"], images: true, inputs: ["video", "audio"] }, ] }, ], gateway: { running: true, window: true, mine: true, url: "http://127.0.0.1:3999", models: 6, calls: [], groups: [ { id: "group/smart", name: "Smart", icons: ["generic", "generic"], providers: ["Acme", "Zeta Cloud"], - efforts: ["low", "medium", "high"], images: true, context: 272000, output: 64000, members: ["acme/gpt-5.5-mini", "zeta/kimi-k3"] }, + efforts: ["low", "medium", "high"], images: true, inputs: ["video"], context: 272000, output: 64000, members: ["acme/gpt-5.5-mini", "zeta/kimi-k3"] }, ] }, }; const state = { agents: [], profiles: [], settings: { lang: "en", theme: "light" } }; @@ -83,7 +83,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", // the info at each row's end, and its tooltip const info = async (id) => { const box = rowOf(page, id).locator(".minfo"); - return { chips: (await box.locator(".badge").allTextContents()).map((s) => s.trim()), img: await box.locator(".mi-img").count(), tip: await box.getAttribute("title") }; + return { chips: (await box.locator(".badge").allTextContents()).map((s) => s.trim()), img: await box.locator(".mi-img").count(), media: await box.locator(".mi-media").evaluateAll((cs) => cs.map((c) => c.classList[2])), tip: await box.getAttribute("title") }; }; let i = await info("acme/gpt-5.5"); assert.deepEqual(i.chips, ["low–xhigh", "", "400K"]); @@ -97,14 +97,21 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.deepEqual(i.chips, ["128K"]); assert.equal(i.img, 0); assert.equal(i.tip, "Reasoning levels: none known\nText only\nContext: 128,000 tokens"); + assert.deepEqual(i.media, [], "no video or audio listed, none said"); + // video and audio, when its list says so (pingqipai3 on X) i = await info("zeta/glm-5"); - assert.deepEqual(i.chips, ["high", "1M"]); + assert.deepEqual(i.chips, ["high", "", "1M"]); + assert.deepEqual(i.media, ["mi-audio"]); + assert.equal(i.tip, "Reasoning: high\nText only\nAccepts audio\nContext: 1,000,000 tokens"); i = await info("zeta/kimi-k3"); - assert.deepEqual(i.chips, [""], "levels it can be given but wasn't aren't said"); + assert.deepEqual(i.chips, ["", "", ""], "levels it can be given but wasn't aren't said"); assert.equal(i.img, 1); + assert.deepEqual(i.media, ["mi-video", "mi-audio"]); + assert.equal(i.tip, "Reasoning levels: none known\nAccepts images\nAccepts video\nAccepts audio"); i = await info("group/smart"); - assert.deepEqual(i.chips, ["low–high", "", "272K"]); - assert.equal(i.tip, "Reasoning: low, medium, high (the levels every model in it has)\nAccepts images (one of its models does)\nContext: 272,000 tokens (the largest of its models')\nOutput: up to 64,000 tokens\nModels: acme/gpt-5.5-mini, zeta/kimi-k3"); + assert.deepEqual(i.chips, ["low–high", "", "", "272K"]); + assert.deepEqual(i.media, ["mi-video"]); + assert.equal(i.tip, "Reasoning: low, medium, high (the levels every model in it has)\nAccepts images (one of its models does)\nAccepts video (one of its models does)\nContext: 272,000 tokens (the largest of its models')\nOutput: up to 64,000 tokens\nModels: acme/gpt-5.5-mini, zeta/kimi-k3"); // the chips sit at the row's end, before its copy button const [infoBox, copyBox, whoBox] = await Promise.all([".minfo", ".copy", ".who"].map((s) => rowOf(page, "acme/gpt-5.5").locator(s).boundingBox())); assert(infoBox.x > whoBox.x && infoBox.x + infoBox.width <= copyBox.x + 1, "info between the name and the copy button");