routing: a weighted group's editor sorts its members by weight once (Norcleeh)
Norcleeh (Discord #general) asked for a way to order a By weight group's members by weight. The order matters there: it is the fallback's when a model fails. Now the group editor has a "Sort by weight" text button beside Add another model. It shows while the group routes By weight and the order would change. A press puts the named members heaviest first (no weight counts as 1, equal weights keep their order, one switched off is sorted too; a pattern's members stay after them) and draw()s. The button then goes. It is a one-off reorder of the draft, saved with the group's Save; no mode is stored. Its title says the order is the fallback's. Strings in zh, zh-TW, ja and de. The routing plugin's client.js isn't a core script; no budget changed. Run (mote-run, at this head ona1f06bd78): - group-member-weight.test.cjs, Chromium and WebKit, en/zh 1100px and en/de 420px: In order offers no sort. By weight it does and fits. The press orders glm-5 (6), gpt (3), kimi (2, off), o4-mini (1), each keeps its weight, the button goes, and Save sends that member order. Every new string has its four translations. 8/8. - Red on origin/main's client.js: 8/8 fail (no button). Broken by hand, the button kept while sorted: 4/4 Chromium red at "sorted, it has nothing to do". - The routing GUI files (group-*, routing-*, panel-routing*), i18n-keys and gui-de/ja/zh-tw, both engines, at load ~230: 1879 of 1913 passed. Adding the button into .rt-gadds made routing-intent-entry count 3 buttons, so the row has its own class, rt-madds; that file passes. The reds left are in routing-flood, -levels, -row-swap, -rule-drag, -rule-remove, -rules-line, -steady and -story-shrinks. The same 27 fail ata1f06bd78without this change, and rule-drag, row-swap and steady fail 7/7 at7fcf642ee. Each has an open issue: #2215, #3620, #3799, #3789, #3096/#3094, #3593, #3412/#1804 and #3954. - go test -tags nogui ./internal/gui: ok. gofmt -l: clean. - Again after the rebase onto7fe98c2af: go build ./..., go test ./internal/gui ok; group-member-weight 8/8, routing-intent-entry 8/8, group-context 4/4. i18n-keys is 3/4: its "a plugin's words are its own" is red on main, from a masking.go comment that quotes "masking…" (e296211b8), not from these strings. Filed as #4053. Not tried: the real desktop app, and a group with members by pattern (those aren't sorted, by the code).
This commit is contained in:
@@ -5698,6 +5698,14 @@ function routingPage(part) {
|
||||
const list = el("div", "fbl");
|
||||
const addBtn = el("button", "rt-gadd");
|
||||
addBtn.append(svg(PLUS, 11, 1.8), el("span", "", t("Add a model")));
|
||||
// By weight, the named members put heaviest first once (Norcleeh on
|
||||
// Discord): the order is the fallback's, so it is written, not a mode.
|
||||
// Shown only while it would move something; equal weights keep theirs
|
||||
const sortBtn = el("button", "text rt-wsort", t("Sort by weight"));
|
||||
sortBtn.type = "button";
|
||||
sortBtn.title = t("Heaviest first. When a model fails, the next one in this order takes over");
|
||||
const byWeight = () => d.members.slice(0, named()).map((id, i) => [id, i]).sort(([a, i], [b, j]) => Math.max(d.weights[b] || 0, 1) - Math.max(d.weights[a] || 0, 1) || i - j).map(([id]) => id);
|
||||
sortBtn.onclick = () => { d.members.splice(0, named(), ...byWeight()); draw(); };
|
||||
// moveMember puts the member at `from` at `to` among those named — a
|
||||
// pattern's follow them, in the catalog's order — and keeps the
|
||||
// keyboard on its handle when it was there
|
||||
@@ -5887,6 +5895,7 @@ function routingPage(part) {
|
||||
list.append(row);
|
||||
});
|
||||
addBtn.querySelector("span").textContent = t(d.members.length ? "Add another model" : "Add a model");
|
||||
sortBtn.hidden = d.routing !== "weight" || byWeight().every((id, i) => d.members[i] === id);
|
||||
};
|
||||
// the picker stays open for as many models as are wanted, each ticked
|
||||
// once in, and says which other groups a model is in already (PAMI on
|
||||
@@ -5921,7 +5930,9 @@ function routingPage(part) {
|
||||
draw(); drawRules();
|
||||
} }, addBtn, ev);
|
||||
};
|
||||
box.append(list, addBtn);
|
||||
const adds = el("div", "rt-madds");
|
||||
adds.append(addBtn, sortBtn);
|
||||
box.append(list, adds);
|
||||
draw();
|
||||
const mw = el("div");
|
||||
mw.append(box, el("div", "hint", t("The first answers for what the model can do. In order, they are tried top first.")));
|
||||
|
||||
@@ -100,6 +100,8 @@ magpie.strings({
|
||||
"Read the accounts' allowances again": "重新读取各账号的额度",
|
||||
"live, as the gateway decides": "实时 · 网关正在做的决定",
|
||||
"Add another model": "再添加一个模型",
|
||||
"Sort by weight": "按权重排序",
|
||||
"Heaviest first. When a model fails, the next one in this order takes over": "权重大的排在前面:某个模型失败时按这个顺序接替",
|
||||
"Add pattern": "添加模式",
|
||||
"e.g. openrouter/*:free or re:…": "例如 openrouter/*:free 或 re:…",
|
||||
"Every model this pattern matches is in the group, as providers list them": "此模式匹配的模型都在组内,随供应商模型列表变化",
|
||||
@@ -682,6 +684,8 @@ magpie.strings({
|
||||
"Read the accounts' allowances again": "重新讀取各帳號的額度",
|
||||
"live, as the gateway decides": "即時 · 閘道正在做的決定",
|
||||
"Add another model": "再新增一個模型",
|
||||
"Sort by weight": "依權重排序",
|
||||
"Heaviest first. When a model fails, the next one in this order takes over": "權重大的排在前面:某個模型失敗時依這個順序接替",
|
||||
"Add pattern": "新增模式",
|
||||
"e.g. openrouter/*:free or re:…": "例如 openrouter/*:free 或 re:…",
|
||||
"Every model this pattern matches is in the group, as providers list them": "此模式匹配的模型都在組內,隨供應商模型列表變化",
|
||||
@@ -1242,6 +1246,8 @@ magpie.strings({
|
||||
"Read the accounts' allowances again": "アカウントの利用枠を読み直します",
|
||||
"live, as the gateway decides": "ライブ · ゲートウェイの判断どおり",
|
||||
"Add another model": "別のモデルを追加",
|
||||
"Sort by weight": "重みで並べ替え",
|
||||
"Heaviest first. When a model fails, the next one in this order takes over": "重みの大きい順に並べます:モデルが失敗したときはこの順で代わります",
|
||||
"Add pattern": "パターンを追加",
|
||||
"e.g. openrouter/*:free or re:…": "例:openrouter/*:free または re:…",
|
||||
"Every model this pattern matches is in the group, as providers list them": "このパターンに一致するモデルは、プロバイダの一覧に合わせてすべてグループに入ります",
|
||||
@@ -1814,6 +1820,8 @@ magpie.strings({
|
||||
"Read the accounts' allowances again": "Kontingente der Konten neu lesen",
|
||||
"live, as the gateway decides": "live, während der Zugangspunkt entscheidet",
|
||||
"Add another model": "Weiteres Modell hinzufügen",
|
||||
"Sort by weight": "Nach Gewicht sortieren",
|
||||
"Heaviest first. When a model fails, the next one in this order takes over": "Schwerstes zuerst: In dieser Reihenfolge springt das nächste Modell ein, wenn eines ausfällt",
|
||||
"Add pattern": "Muster hinzufügen",
|
||||
"e.g. openrouter/*:free or re:…": "z. B. openrouter/*:free oder re:…",
|
||||
"Every model this pattern matches is in the group, as providers list them": "Jedes Modell, auf das dieses Muster passt, ist in der Gruppe, so wie die Anbieter es auflisten",
|
||||
|
||||
@@ -650,6 +650,9 @@ button.rt-session { cursor: pointer; }
|
||||
/* Add a rule, and beside it a rule by what the message asks for */
|
||||
.rt-gadds { display: flex; flex-wrap: wrap; gap: 6px; }
|
||||
.rt-gadds > [hidden] { display: none; }
|
||||
/* Add a model, and beside it Sort by weight while it would move something */
|
||||
.rt-madds { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
|
||||
.rt-madds > [hidden] { display: none; }
|
||||
/* a group's rules, each one line read as a sentence: the conditions it
|
||||
has, → and the model it sends that turn to first; its acts under ⋯ */
|
||||
.rt-rules .fbl:not(:empty) + .rt-gadds { margin-top: 2px; }
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
// Enter keeps it, Escape puts it back, and one out of 1 to 1000 is refused
|
||||
// with a warning. Nothing on the page moves. Saved, the group goes with
|
||||
// routing "weight" and the weights above 1 of the members it still has. At
|
||||
// Sort by weight puts the heaviest first once, and is saved so. At
|
||||
// 420px the segments and the rows don't spill. English, Chinese and German,
|
||||
// Chromium and WebKit; no backend, the API is faked here.
|
||||
const assert = require("node:assert/strict");
|
||||
@@ -85,6 +86,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
const weight = (name) => row(name).locator("button.rt-weight");
|
||||
await row("glm-5").waitFor();
|
||||
assert.equal(await ed.locator("button.rt-weight").count(), 0, "In order shows no weights");
|
||||
const sort = ed.locator("button.rt-wsort");
|
||||
assert.equal(await sort.isVisible(), false, "In order offers no sort by weight");
|
||||
|
||||
const byWeight = ed.locator(".segs .opt", { hasText: await tr("By weight") });
|
||||
// what is clicked is wheeled into view by the test, as the reader
|
||||
@@ -129,6 +132,22 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert.equal(await weight("o4-mini").textContent(), await tr("Weight {n} · {share}%", { n: 1, share: 10 }));
|
||||
assert(await page.locator("body", { hasText: await tr("A weight is 1 to 1000") }).count(), "the refusal is said");
|
||||
|
||||
// Sort by weight (Norcleeh on Discord) puts the heaviest first once,
|
||||
// equal weights in their order, one switched off too; then it goes,
|
||||
// since nothing is left to move
|
||||
const order = async () => {
|
||||
const names = await ed.locator(".fbl").first().locator(":scope > .fbrow .n > span:first-child").allTextContents();
|
||||
return names.map((x) => ["gpt-6.1-sol", "glm-5", "o4-mini", "kimi-k2.6"].find((n) => x.includes(n)));
|
||||
};
|
||||
assert.deepEqual(await order(), ["gpt-6.1-sol", "glm-5", "o4-mini", "kimi-k2.6"]);
|
||||
assert.equal(await sort.textContent(), await tr("Sort by weight"));
|
||||
await reach(page, sort);
|
||||
assert(await page.evaluate(() => document.querySelector(".rt-wsort").getBoundingClientRect().right <= document.querySelector(".rt-gedit").getBoundingClientRect().right + 1), "Sort by weight fits at " + width);
|
||||
await sort.click();
|
||||
assert.deepEqual(await order(), ["glm-5", "gpt-6.1-sol", "kimi-k2.6", "o4-mini"], "heaviest first");
|
||||
assert.equal(await sort.isVisible(), false, "sorted, it has nothing to do");
|
||||
assert.equal(await weight("glm-5").textContent(), await tr("Weight {n} · {share}%", { n: 6, share: 60 }), "each keeps its weight");
|
||||
|
||||
// nothing spills, and no left-border accent
|
||||
const spill = await page.evaluate(() => {
|
||||
const ed = document.querySelector(".rt-gedit").getBoundingClientRect();
|
||||
@@ -153,9 +172,10 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
const sent = posts.find((p) => p.path === "/api/groups/save");
|
||||
assert.equal(sent.body.routing, "weight");
|
||||
assert.deepEqual(sent.body.weights, { "oa/gpt-6.1-sol:high": 3, "rl/glm-5": 6, "rl/kimi-k2.6": 2 });
|
||||
assert.deepEqual(sent.body.members, ["rl/glm-5", "oa/gpt-6.1-sol:high", "rl/kimi-k2.6", "rl/o4-mini"], "the sorted order is saved");
|
||||
|
||||
const missing = await page.evaluate(() => [
|
||||
"By weight", "Weight {n}", "Weight {n} · {share}%", "Weight of {name}", "A weight is 1 to 1000",
|
||||
"By weight", "Sort by weight", "Heaviest first. When a model fails, the next one in this order takes over", "Weight {n}", "Weight {n} · {share}%", "Weight of {name}", "A weight is 1 to 1000",
|
||||
"Its share of the requests: a model weighing 3 takes three for every one a model weighing 1 takes",
|
||||
"By weight: each model takes its share of the requests by the weight set beside it — one weighing 3 three for every one a model weighing 1 takes, spread out rather than in bursts. One resting after a failure leaves the round and the others share its requests; the next model is the fallback when one fails.",
|
||||
].filter((k) => !I18N.zh[k] || !I18N["zh-TW"][k] || !I18N.ja[k] || !I18N.de[k]));
|
||||
|
||||
Reference in New Issue
Block a user