heatonz on Discord (#help, 11-05): a custom provider whose models are only
embedding and rerank models couldn't be added. Detect APIs ("检测协议")
picked the first listed model, an embedding model, and asked it to chat on
every API, so nothing answered.
- tiny: an embedding or rerank model (catalog.ServesOf) on Chat is asked
where the gateway's retrieve sends it: the OpenAI base's /embeddings
({"model","input"}) or /rerank ({"model","query","documents"}). tested
adds no extra body there, as the gateway sends none.
- detectModel asks each API a model that chats when the list has one, so
a chat vendor's detection is unchanged. A retrieval model is a last
resort on Chat only. Responses, Anthropic and Gemini say why they weren't
asked (DetectModels too).
- testModel: a saved provider with nothing to chat with tests on a
retrieval model its list keeps apart (LiveServing). testOne asks such a
model on Chat and never moves it to another API.
- provider.ListAll is List with Serves models kept. /api/provider/list and
the provider's JSON carry a `retrieval` count. The add form's Fetch models
and the saved editor say "Only embedding and rerank models are listed.
They need no pick: ask them on /v1/embeddings and /v1/rerank." in place
of "the list is empty". One new string, in zh, zh-TW, ja and de.
- app.js stays under TestCoreScriptBudget with no raise: +42 bytes, paid
for by two add-form comments cut.
- The gateway already routes /v1/embeddings and /v1/rerank to such a
provider (#765, resolveRetrievalModel by prefix or KindGroup), so nothing
changed there.
Run (mote, at this tree on origin/main 60fe6645a):
- go test ./internal/provider ./internal/catalog: ok.
- go test ./internal/gui: ok, except TestMainWindowCorners/macOS_26_SDK,
which is #3949 (mote is macOS 27).
- go build ./..., go vet (darwin), GOOS=linux go vet -tags nogui and
GOOS=windows go vet of provider and gui: ok. gofmt -l: clean.
- node --test, chromium and webkit: provider-retrieval-only (new: en, zh,
zh-TW, ja, de, with and without retrieval models, add form and saved
editor), provider-detect, provider-add-models, azure-endpoint,
provider-listed-as, provider-add-gemini, i18n-en-no-cjk and i18n-keys.
94 of 95 pass. The red is i18n-keys "a plugin's words are its own", red
on origin/main 60fe6645a too (#5332/#5327).
Broken by hand:
- New tests on origin/main's code. TestDetectEmbeddingOnly red ("The
model BAAI/bge-m3 does not support chat" on chat, 404 on the rest).
TestTestEmbeddingOnly red ("no model to try"). TestProviderListBeforeSave
red (retrieval = 0).
- Retrieval models not kept out of chat probes: the mixed-list case is red
(bge-m3 asked beside glm-5).
- tested adding the extra body to /embeddings: red (prompt_cache_key
sent).
- detectOne asking non-Chat APIs with a retrieval model: red (404 on
/v1/responses).
- testModel's LiveServing fallback off: TestTestEmbeddingOnly red.
- provider-retrieval-only on the old app.js with the new i18n.js: the 5
retrieval cases red, the 5 empty-list ones green.
Not tried:
- A real embedding/rerank vendor (heatonz's is unknown). Fake httptest
servers only.
- The whole GUI suite.
- Windows and Linux test runs (vet only).
- Models whose ids don't say embed, bge- or rerank (gte-, e5-, m3e-,
text2vec-, voyage-) are still taken as chat models. The /embeddings probe
goes by the id, and a Xinference model_type isn't read.
83 lines
5.2 KiB
JavaScript
83 lines
5.2 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// A vendor that lists only embedding and rerank models (heatonz on Discord,
|
|
// 11-05): there is nothing for an agent to chat with, and nothing to pick,
|
|
// as they are served on /v1/embeddings and /v1/rerank as listed. The add
|
|
// form's Fetch models, and a saved provider's editor, say so rather than
|
|
// that the list is empty; a list that is empty still says it is. Every
|
|
// language; no backend, the API is faked here.
|
|
const assert = require("node:assert/strict");
|
|
const fs = require("node:fs/promises");
|
|
const path = require("node:path");
|
|
const { test } = require("node:test");
|
|
const { chromium, webkit } = require("playwright");
|
|
|
|
const assets = path.resolve(__dirname, "../assets");
|
|
const { I18N } = require("./strings.cjs").strings();
|
|
const ONLY = "Only embedding and rerank models are listed. They need no pick: ask them on /v1/embeddings and /v1/rerank.";
|
|
const ADD_EMPTY = "The vendor's list is empty. Type the model ids instead.";
|
|
const SAVED_EMPTY = "The vendor's list is empty. Fetch models again, or type a model id.";
|
|
const say = (lang, k) => lang === "en" ? k : I18N[lang][k];
|
|
|
|
const relay = (retrieval) => ({ id: "relay", name: "Embed Relay", icon: "openai", models: [], agents: [], key: { set: true, masked: "sk-…ab12" }, chat: "http://embed.test/v1", ...(retrieval ? { retrieval } : {}) });
|
|
|
|
function server(lang, list, retrieval) {
|
|
const providers = { providers: list, presets: [], excluded: [], gateway: { running: true, window: true } };
|
|
return async (route) => {
|
|
const url = new URL(route.request().url());
|
|
const json = (data) => route.fulfill({ json: data });
|
|
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:${JSON.stringify(lang)},theme:"light",web:false};` });
|
|
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
|
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang, theme: "light" } });
|
|
if (url.pathname === "/api/providers") return json(providers);
|
|
if (url.pathname === "/api/groups") return json({ groups: [], pools: [] });
|
|
if (url.pathname === "/api/provider/list") return json({ models: [], ...(retrieval ? { retrieval } : {}) });
|
|
if (url.pathname.startsWith("/api/")) return json({});
|
|
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
|
try { await route.fulfill({ body: await fs.readFile(file), contentType: { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)] }); } catch { await route.fulfill({ status: 404, body: "" }); }
|
|
};
|
|
}
|
|
|
|
test("each language says it", () => {
|
|
for (const lang of ["zh", "zh-TW", "ja", "de"]) assert(I18N[lang][ONLY], lang);
|
|
});
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
test(engine + ": a list of embedding and rerank models alone", async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: process.env.PLAYWRIGHT_CHANNEL || "chromium" }));
|
|
t.after(() => browser.close());
|
|
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) for (const retrieval of [2, 0]) {
|
|
await t.test(`${lang}, ${retrieval} retrieval`, async () => {
|
|
const page = await (await browser.newContext({ viewport: { width: 900, height: 760 }, reducedMotion: "reduce" })).newPage();
|
|
page.setDefaultTimeout(5000);
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/*", server(lang, [relay(retrieval)], retrieval));
|
|
await page.goto("http://magpie.test/?view=providers");
|
|
|
|
// the add form's Fetch models
|
|
await page.locator("#addProvider").click();
|
|
await page.locator("#addSheet .custom-foot .custom").click();
|
|
const ed = page.locator(".editor.new");
|
|
await ed.locator(".add-models").waitFor();
|
|
await ed.locator('input[type="url"][placeholder="https://…/v1"]').first().fill("http://embed.test/v1");
|
|
await ed.locator(".add-models .detect-row button").click();
|
|
// past "Asking the vendor…", the one hint the answer leaves
|
|
const hint = ed.locator(".add-models-list .hint");
|
|
await page.waitForFunction(() => !/…$/.test(document.querySelector(".editor.new .add-models-list .hint")?.textContent ?? "…"));
|
|
assert.deepEqual(await hint.allTextContents(), [say(lang, retrieval ? ONLY : ADD_EMPTY)]);
|
|
|
|
// the saved provider's editor
|
|
await page.goto("http://magpie.test/?view=providers");
|
|
await page.locator(".row.provider", { hasText: "Embed Relay" }).first().click();
|
|
await page.locator(".editor .ehead b", { hasText: "Embed Relay" }).waitFor();
|
|
const all = await page.locator(".editor .hint").allTextContents();
|
|
const want = say(lang, retrieval ? ONLY : SAVED_EMPTY), not = say(lang, retrieval ? SAVED_EMPTY : ONLY);
|
|
assert(all.includes(want), `no ${JSON.stringify(want)} among ${JSON.stringify(all)}`);
|
|
assert(!all.includes(not), "also " + not);
|
|
assert.deepEqual(errors, []);
|
|
await page.context().close();
|
|
});
|
|
}
|
|
});
|
|
}
|