diff --git a/docs/subsystems/gateway-routing.md b/docs/subsystems/gateway-routing.md index 93a66d739..f2f855a85 100644 --- a/docs/subsystems/gateway-routing.md +++ b/docs/subsystems/gateway-routing.md @@ -811,7 +811,9 @@ A single decision provider of several keys or accounts (TypeSafe Jev with a key out of quota, fflake33 on Discord) is asked the same way, at `/v1/systemone` (`serveSystemOne`) and as a classifier (`askClassifier` → `askDecider`): `decideKeys` plans its keys in its routing's order (Smart, -In order), `probeOne` leaves out all but the resting one back soonest, and +In order), leaving out a key whose plan has no System One (a Volcengine +Coding Plan key beside pay as you go), `probeOne` leaves out all but the +resting one back soonest, and `serveDecideTries` / `askDecideTries` ask each in turn as for a group, a refused one resting. Before, every call went to its first key, whatever the others' state. As a classifier, every try shares the one classifier's wait diff --git a/docs/subsystems/providers-accounts.md b/docs/subsystems/providers-accounts.md index e4be16d78..2d6313694 100644 --- a/docs/subsystems/providers-accounts.md +++ b/docs/subsystems/providers-accounts.md @@ -115,7 +115,10 @@ conversation picks omit them. What a routing group's pickers, templates and the TUI offer is `OfferedDeciders`: with picks saved, only the picked decision models plus any a group names already, as the provider editor shows the rest unpicked (coeo91 on Discord: two free OpenRouter models -picked, OpenRouter's decision models still offered beside them). Only remote decision entries use `entryFor` +picked, OpenRouter's decision models still offered beside them). A +vendor's own one decision model beside its chat models (`bailianApart`: a +Bailian plan's, Ark's pay as you go) is no list to pick from, and is +offered whatever the picks. Only remote decision entries use `entryFor` to apply user model names and limits; other decision providers retain their previous entry formatting. The editor's `providerInfo` in [`providers.go`](../../internal/gui/providers.go) sends `deciders: []` when @@ -134,7 +137,18 @@ for it; `decideModels` lists it first, and `resolveDecideModel` asks System One by its own name (axelburks on Discord: an Ark endpoint id). `apisAmong` ignores `decide`, so it never picks a conversation URL. The GUI offers it when `providerInfo`'s `decideAPIKind` is set and a System One URL -is saved. +is saved or typed. A custom provider of any base URL API gives one under More +endpoints (*System One URL*, saved with any API; before, only a System One +base URL kept it, so a Responses provider had nowhere to give it). A +provider asked at Volcengine Ark's pay as you go (`ark..volces.com/api/v3`, +chat completions or Responses, its preset's or a custom one) needs none: +`normalize` sets its System One to `…/api/v1` on the same host +(`arkSystemOne`), where the same key answers with Ark's beta header, so +`ArkDecision` is a routing group's classifier with no URL typed. Ark's +Coding and Agent Plans answer System One nothing (404) and get none; a +key of another plan is never asked it (`decideKeys`). A URL the user gave +is kept. `TestArkPayAsYouGoDecides`, `TestArkDecisionSkipsPlanKeys`, +`custom-systemone-url.test.cjs`. Refresh replaces the list: removed decisions stop routing, and an empty remote list never gains a fabricated Jev alias. An older peer without the decision-list extension continues serving its diff --git a/internal/gateway/decide_ark_test.go b/internal/gateway/decide_ark_test.go index b2ae7ee6a..42133e361 100644 --- a/internal/gateway/decide_ark_test.go +++ b/internal/gateway/decide_ark_test.go @@ -67,3 +67,35 @@ func (u *arkUp) got() []string { defer u.mu.Unlock() return slices.Clone(u.asked) } + +// An Ark provider at pay as you go answers System One there, on its own +// key; a key of it on the Coding Plan is asked at the plan's endpoints, +// which have none, so a decision is never sent with it. +func TestArkDecisionSkipsPlanKeys(t *testing.T) { + fresh(t) + const v3 = "https://ark.cn-beijing.volces.com/api/v3" + if err := provider.Save(provider.Provider{ID: "volc", Name: "Volc", Preset: "volcengine", Chat: v3, Responses: v3, + Key: "k-api", KeyName: "API", Models: []string{"glm-4-7-251222"}, + Keys: []provider.KeyAccount{{Name: "Coding", Key: "k-coding", Plan: "coding"}}}); err != nil { + t.Fatal(err) + } + p, err := provider.Find("volc") + if err != nil { + t.Fatal(err) + } + if p.Decide != "https://ark.cn-beijing.volces.com/api/v1" { + t.Fatalf("System One at %q", p.Decide) + } + // the vendor's decision model, and one both plans serve (the Coding + // Plan's list has it, so PlanServing keeps its key) + for _, m := range []string{provider.ArkDecision, "doubao-seed-2.1-lite"} { + cs, _ := New().decideKeys(*p, m) + var keys []string + for _, c := range cs { + keys = append(keys, c.p.Key+" "+c.p.Decide) + } + if !slices.Equal(keys, []string{"k-api https://ark.cn-beijing.volces.com/api/v1"}) { + t.Fatalf("%s asked with: %q", m, keys) + } + } +} diff --git a/internal/gateway/decide_group.go b/internal/gateway/decide_group.go index b16ccff4d..a6600d9bf 100644 --- a/internal/gateway/decide_group.go +++ b/internal/gateway/decide_group.go @@ -149,7 +149,12 @@ func (s *Server) serveDecisionGroup(w http.ResponseWriter, r *http.Request, body // out of quota was asked on every turn, the next never). func (s *Server) decideKeys(p provider.Provider, model string) ([]candidate, planned) { p.Fallback = nil - return s.plan(p, model, provider.Chat) + cs, pl := s.plan(p, model, provider.Chat) + // a key on another of its preset's plans is asked at that plan's + // endpoints, where there may be no System One (Volcengine's Coding + // Plan beside its pay as you go): never there + cs = slices.DeleteFunc(cs, func(c candidate) bool { return !c.p.Decides() }) + return cs, pl } // serveDecideTries answers a System One request with cs, a decision diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index f8fd19eb3..682b81c3c 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -8050,7 +8050,8 @@ function asTyped() { const body = { typed: true, key: keys.length > 1 ? keys[0] : (draft.key || "").trim(), chat: (draft.chat || "").trim(), responses: (draft.responses || "").trim(), anthropic: (draft.anthropic || "").trim(), gemini: (draft.gemini || "").trim(), modelsURL: (draft.modelsURL || "").trim() }; Object.assign(body, movedURLs(draft)); // a System One base is asked at POST …/systemone, not on the three APIs - if (draft.api === "decide") body.decide = (draft.decide || "").trim(); + // and one given beside a conversation URL, under More endpoints + if (draft.api === "decide" || !draft.preset && (draft.decide || "").trim()) body.decide = (draft.decide || "").trim(); // a Vertex AI provider is asked at the project typed, with the // credentials typed, as a pasted key is if (draft.vertex) body.vertex = vertexOfDraft(); @@ -10008,7 +10009,13 @@ function drawEditor(p, presetID) { }; wsIn.oninput = () => { draft.workspace = wsIn.value; fill(); }; du.oninput = () => { draft.decide = du.value; }; - onRegion = (r) => { draft.region = r.id; if (r.decide) { draft.decide = du.value = r.decide; fill(); } }; + // a plan with none of its own (Volcengine's Coding Plan) drops the + // one of the plan it was at; the gateway finds pay as you go's itself + onRegion = (r) => { + draft.region = r.id; + if (r.decide) { draft.decide = du.value = r.decide; fill(); } + else if (!pr?.decide) draft.decide = du.value = r.chat && r.chat === p?.chat ? p?.decide || "" : ""; + }; ed.append(...wsRow); fill(); // Jev's own presets name it; the others ask their own decision models @@ -10021,7 +10028,7 @@ function drawEditor(p, presetID) { const row = field(t("Endpoints"), ebox, ""); refreshEndpoints = () => { const base = p || pr || {}; - const src = { chat: draft.chat || base.chat || "", responses: draft.responses || base.responses || "", anthropic: draft.anthropic || base.anthropic || "", decide: base.decide || "" }; + const src = { chat: draft.chat || base.chat || "", responses: draft.responses || base.responses || "", anthropic: draft.anthropic || base.anthropic || "", decide: (pr && !pr.decide ? draft.decide ?? base.decide : base.decide) || "" }; // Vertex AI's is the address its project and location make, shown // with its Test once a project is typed, saved one or not: with none // there is nowhere to ask @@ -10049,13 +10056,16 @@ function drawEditor(p, presetID) { const add = (label, key, ph, hint) => { if (apiField[draft.api] === key) return; const i = input(draft[key], ph, "url"); - i.oninput = () => { draft[key] = i.value; if (carried?.from === key) carried = null; showSearch(); showLocal(); showTLS(); showAuth(); showCompaction(); }; + i.oninput = () => { draft[key] = i.value; if (carried?.from === key) carried = null; showSearch(); showLocal(); showTLS(); showAuth(); showCompaction(); draft.onModelPrefs?.(); }; eps.append(...field(t(label), i, t(hint))); }; add("OpenAI URL", "chat", "https://…/v1", "if the vendor also serves chat completions"); add("Anthropic URL", "anthropic", "https://…", "if the vendor also serves Anthropic messages"); add("Responses URL", "responses", "https://…/v1", "if the vendor serves the OpenAI Responses API (Codex uses it natively)"); add("Gemini URL", "gemini", "https://…/v1beta", "if the vendor serves Google's Gemini API (generateContent)"); + // beside a conversation URL: a model can then be set to System One + // under Model settings, for a routing group to ask + add("System One URL", "decide", "https://…/v1", "if the vendor also serves a decision API, POST …/systemone under it; a model set to System One under Model settings is asked there"); }; fillEndpoints(); inner.append(eps); @@ -10153,7 +10163,7 @@ function drawEditor(p, presetID) { const ph = replyHeadersOf(draft.passHeaders, true); if (ph.error) { shown(ed.querySelector(".pass-headers"))?.focus(NO_SCROLL); return editorError(t("Request headers to pass: {why}", { why: ph.error }), "warn"); } body.passHeaders = ph.value; - if (decides || custom) body.decide = (custom && draft.api !== "decide" && !p?.decide ? "" : draft.decide || "").trim(); + if (decides || custom) body.decide = (draft.decide || "").trim(); if ((body.decide || "").includes(WORKSPACE)) { ed.querySelector(".workspace-id")?.focus(NO_SCROLL); return editorError(t("Give the workspace ID your API key belongs to, or pick the Token Plan"), "warn"); } if (custom) { // the API picked for the Base URL is saved with it, and one left with diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index 6f50c890d..143eebefd 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -2371,6 +2371,8 @@ const I18N = { "…/v1beta — Google's Gemini API (generateContent), or one that answers as it does; the key goes in x-goog-api-key": "…/v1beta — Google 的 Gemini API(generateContent),或与它应答方式相同的端点;密钥放在 x-goog-api-key 里", "Gemini URL": "Gemini 地址", "if the vendor serves Google's Gemini API (generateContent)": "如果供应商提供 Google 的 Gemini API(generateContent)", + "System One URL": "System One 地址", + "if the vendor also serves a decision API, POST …/systemone under it; a model set to System One under Model settings is asked there": "如果供应商也提供决策 API(其下的 POST …/systemone);在“模型设置”里设为 System One 的模型会在这里调用", "Gemini generateContent — what the Gemini CLI speaks": "Gemini generateContent — Gemini CLI 使用", "models.dev ids, e.g. openai, deepseek": "models.dev 上的 ID,例如 openai, deepseek", "Catalog": "目录", @@ -7109,6 +7111,8 @@ const I18N = { "…/v1beta — Google's Gemini API (generateContent), or one that answers as it does; the key goes in x-goog-api-key": "…/v1beta — Google 的 Gemini API(generateContent),或與它應答方式相同的端點;金鑰放在 x-goog-api-key 裡", "Gemini URL": "Gemini 位址", "if the vendor serves Google's Gemini API (generateContent)": "如果供應商提供 Google 的 Gemini API(generateContent)", + "System One URL": "System One 位址", + "if the vendor also serves a decision API, POST …/systemone under it; a model set to System One under Model settings is asked there": "如果供應商也提供決策 API(其下的 POST …/systemone);在「模型設定」裡設為 System One 的模型會在這裡呼叫", "Gemini generateContent — what the Gemini CLI speaks": "Gemini generateContent — Gemini CLI 使用", "models.dev ids, e.g. openai, deepseek": "models.dev 上的 ID,例如 openai, deepseek", "Catalog": "目錄", @@ -11823,6 +11827,8 @@ const I18N = { "…/v1beta — Google's Gemini API (generateContent), or one that answers as it does; the key goes in x-goog-api-key": "…/v1beta — Google の Gemini API(generateContent)、または同じように応答するもの。キーは x-goog-api-key で送ります", "Gemini URL": "Gemini URL", "if the vendor serves Google's Gemini API (generateContent)": "ベンダーが Google の Gemini API(generateContent)を提供している場合", + "System One URL": "System One URL", + "if the vendor also serves a decision API, POST …/systemone under it; a model set to System One under Model settings is asked there": "ベンダーが決定 API も提供している場合(その下の POST …/systemone)。「モデル設定」で System One にしたモデルはここに問い合わせます", "Gemini generateContent — what the Gemini CLI speaks": "Gemini generateContent — Gemini CLI が使う形式", "models.dev ids, e.g. openai, deepseek": "models.dev の ID、例:openai, deepseek", "Catalog": "カタログ", @@ -16568,6 +16574,8 @@ const I18N = { "…/v1beta — Google's Gemini API (generateContent), or one that answers as it does; the key goes in x-goog-api-key": "…/v1beta — Googles Gemini API (generateContent) oder eine, die genauso antwortet; der Schlüssel geht in x-goog-api-key", "Gemini URL": "Gemini-URL", "if the vendor serves Google's Gemini API (generateContent)": "falls der Anbieter Googles Gemini API (generateContent) bereitstellt", + "System One URL": "System-One-URL", + "if the vendor also serves a decision API, POST …/systemone under it; a model set to System One under Model settings is asked there": "falls der Anbieter auch eine Entscheidungs-API bereitstellt, POST …/systemone darunter; ein unter Modelleinstellungen auf System One gestelltes Modell wird dort gefragt", "Gemini generateContent — what the Gemini CLI speaks": "Gemini generateContent — spricht die Gemini CLI", "models.dev ids, e.g. openai, deepseek": "models.dev-IDs, z. B. openai, deepseek", "Catalog": "Katalog", diff --git a/internal/gui/tests/custom-systemone-url.test.cjs b/internal/gui/tests/custom-systemone-url.test.cjs new file mode 100644 index 000000000..0bd401f25 --- /dev/null +++ b/internal/gui/tests/custom-systemone-url.test.cjs @@ -0,0 +1,90 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// A custom provider whose base URL is OpenAI Responses (a user on Discord: +// "under More endpoints there are OpenAI / Anthropic / Gemini addresses +// but no System One address"): More endpoints has a System One URL, and +// once one is typed Model settings' API row offers System One, and the +// Save sends both. With System One picked as the base URL's API, the field +// is the base URL and More endpoints doesn't show it twice. Every +// language, Chromium and WebKit, wide and at a phone's width. +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(process.env.MAGPIE_ASSETS || path.resolve(__dirname, "../assets")); +const mine = { + icon: "generic", catalog: "", agents: [], fallback: [], headers: {}, keyList: [], balanceToken: { takes: false, set: false }, proxy: "", ready: true, key: { set: true, masked: "sk-…one" }, + id: "mine", name: "Mine", api: "responses", chat: "", responses: "https://relay.example.com/v1", anthropic: "", gemini: "", decideAPIKind: true, takesModelHeaders: true, + models: [{ id: "m-chat", name: "m-chat", on: true }, { id: "m-decide", name: "m-decide", on: true }], + chosen: ["m-chat", "m-decide"], +}; + +function serve(lang, posts) { + const providers = { providers: [mine], presets: [], excluded: [], gateway: { running: true, window: true } }; + const state = { agents: [], profiles: [], settings: { lang, theme: "light" } }; + 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:"${lang}",theme:"light",web:true};` }); + if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" }); + if (url.pathname === "/api/state") return json(state); + if (url.pathname === "/api/plugins") return json({ plugins: [] }); + if (url.pathname === "/api/providers") return json(providers); + if (url.pathname === "/api/groups") return json({ groups: [] }); + if (url.pathname === "/api/provider/save") { posts.push(route.request().postDataJSON()); return json(providers); } + if (url.pathname.startsWith("/api/")) return json({}); + const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname); + const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)]; + try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); } + }; +} + +const say = (page, lang, s) => page.evaluate(([l, s]) => (l === "en" ? s : I18N[l][s]), [lang, s]); + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) { + for (const width of [1200, 420]) { + test(`${engine} ${lang} ${width}px: a custom provider's System One URL under More endpoints`, async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + t.after(() => browser.close()); + const page = await (await browser.newContext({ viewport: { width, height: 900 }, reducedMotion: "reduce" })).newPage(); + page.setDefaultTimeout(5000); + const errors = [], posts = []; + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", serve(lang, posts)); + await page.goto("http://magpie.test/?view=providers"); + await page.locator(".row.provider", { hasText: "Mine" }).first().click(); + const editor = page.locator("#modal:not([hidden]) .editor"); + const label = await say(page, lang, "System One URL"); + assert.ok(label, "translated"); + const more = editor.locator("details.more", { has: page.locator(":scope > summary", { hasText: await say(page, lang, "More endpoints") }) }); + await more.locator(":scope > summary").click(); + const input = more.getByLabel(label, { exact: true }); + assert.equal(await input.count(), 1, "one System One URL field"); + await input.fill("https://relay.example.com/v1"); + + // Model settings: a model can now be set to System One + if (!(await editor.locator(".mnames:not([hidden])").count())) await editor.getByRole("button", { name: await say(page, lang, "Model settings"), exact: true }).click(); + const row = editor.locator(".mnames:not([hidden]) .mname", { has: page.locator("code", { hasText: /^m-decide$/ }) }); + await row.locator('.mapi .opt[data-api="decide"]').click(); + const over = await page.evaluate(() => document.documentElement.scrollWidth > innerWidth + 1); + assert.equal(over, false, "nothing wider than the window"); + if (process.env.ARTIFACT_DIR) { + await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true }); + await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${width}-custom-systemone-url.png`), fullPage: true }); + } + await editor.locator(".bar button.primary").click(); + for (let i = 0; i < 100 && !posts.length; i++) await page.waitForTimeout(20); + assert.equal(posts[0]?.decide, "https://relay.example.com/v1", "the System One URL is saved beside Responses"); + assert.deepEqual(posts[0]?.modelPrefs, { "m-decide": { api: "decide" } }); + + // System One as the base URL's API: the field isn't shown twice + await page.locator(".row.provider", { hasText: "Mine" }).first().click(); + await editor.locator('.base-apis .opt[data-api="decide"]').click(); + assert.equal(await editor.locator("details.more").getByLabel(label, { exact: true }).count(), 0, "the base URL is the System One URL"); + assert.deepEqual(errors, []); + }); + } + } +} diff --git a/internal/provider/decide.go b/internal/provider/decide.go index 0a29adce7..1944b9c35 100644 --- a/internal/provider/decide.go +++ b/internal/provider/decide.go @@ -68,6 +68,28 @@ func arkDecides(base string) bool { return strings.HasPrefix(h, "ark.") && strings.HasSuffix(h, ".volces.com") } +// arkSystemOne is the System One base of a key's provider asked at +// Volcengine Ark's pay as you go (ark..volces.com/api/v3, as chat +// completions or Responses): …/api/v1 on the same host, where +// volcengine-decision asks it; "" for any other provider. The Coding and +// Agent Plans' paths answer System One nothing, and a signed-in account, +// a plugin, a remote magpie and Vertex say their own. +func (p Provider) arkSystemOne() string { + if p.Account != nil || p.IsRemoteMagpie() || p.IsVertex() { + return "" + } + for _, raw := range []string{p.Chat, p.Responses} { + if !arkDecides(raw) { + continue + } + u, err := url.Parse(raw) + if err == nil && strings.TrimRight(u.Path, "/") == "/api/v3" { + return u.Scheme + "://" + u.Host + "/api/v1" + } + } + return "" +} + // vendorDecision is the decision model of the vendor whose System One // API base is, Bailian's or Ark's, which its model list never names. func vendorDecision(base string) (catalog.Model, bool) { @@ -649,13 +671,15 @@ func Deciders() []Entry { // OfferedDeciders are the Deciders a routing group's pickers and templates // offer: of a provider whose decision models are listed beside its chat -// models (OpenRouter's, a Bailian plan's, a plugin's, a remote magpie's), -// with picks saved, those among the picks alone, as its editor shows the +// models (OpenRouter's, a plugin's, a remote magpie's), with picks saved, +// those among the picks alone, as its editor shows the // rest unpicked (coeo91 on Discord: two OpenRouter models picked, and a // new group's picker listed OpenRouter's twenty-odd decision models after // them). With none picked every one is offered, as before. keep, when // given, says a decision model a group names already, offered whatever -// the picks, so a group made of one before reads as it did. +// the picks, so a group made of one before reads as it did. A vendor's +// own one decision model beside its chat models (a Bailian plan's, Ark's +// pay as you go) is offered whatever the picks. func OfferedDeciders(keep func(id string) bool) []Entry { if keep == nil { keep = func(string) bool { return false } @@ -676,7 +700,10 @@ func deciders(keep func(id string) bool) []Entry { ms := p.Exposed() if !p.DecideOnly() && (len(p.Models) == 0 || p.listsDecisions() || p.bailianApart() || p.IsRemoteMagpie() || p.IsPlugin()) { ms = p.decideModels() // the conversation picker's limit does not hide Jev - if keep != nil && len(p.Models) > 0 { + // a vendor's own one decision model (Bailian's, Ark's) is no + // list to pick from: its chat models picked, it is offered + // still, as nothing in the picks says it isn't wanted + if keep != nil && len(p.Models) > 0 && !p.bailianApart() { ms = slices.DeleteFunc(slices.Clone(ms), func(m catalog.Model) bool { return !slices.Contains(p.Models, m.ID) && !keep(p.ID+"/"+m.ID) }) diff --git a/internal/provider/decide_ark_test.go b/internal/provider/decide_ark_test.go index 5e5c03dec..f0b3cb1d5 100644 --- a/internal/provider/decide_ark_test.go +++ b/internal/provider/decide_ark_test.go @@ -9,6 +9,7 @@ import ( "net/http" "net/http/httptest" "path/filepath" + "slices" "strings" "sync" "testing" @@ -158,3 +159,46 @@ func TestArkHeaderScopedToArk(t *testing.T) { t.Fatalf("decision models: %+v", ms) } } + +// A user on Discord found no System One endpoint for Volcengine Ark, its +// preset's or a custom one (OpenAI Responses), and none of its models in +// a routing group's classifier picker. Ark's pay as you go answers System +// One on the same key at …/api/v1: a provider asked there, of either +// protocol, offers Ark's decision model with no URL typed, its chat models +// picked or not. The Coding and Agent Plans answer it nothing, and a URL +// the user gave is kept. +func TestArkPayAsYouGoDecides(t *testing.T) { + arkHome(t) + const v3, v1 = "https://ark.cn-beijing.volces.com/api/v3", "https://ark.cn-beijing.volces.com/api/v1" + for _, p := range []Provider{ + {ID: "ark-responses", Name: "Ark Responses", Responses: v3 + "/", Key: "ark-1", Models: []string{"doubao-seed-2-1-pro-260628"}}, + {ID: "ark-chat", Name: "Ark Chat", Chat: v3, Key: "ark-1"}, + {ID: "ark-preset", Name: "Volcengine Ark", Preset: "volcengine", Chat: v3, Responses: v3, Key: "ark-1", Models: []string{"glm-4-7-251222"}}, + {ID: "ark-coding", Name: "Ark Coding", Preset: "volcengine", Chat: "https://ark.cn-beijing.volces.com/api/coding/v3", Responses: "https://ark.cn-beijing.volces.com/api/coding/v3", Key: "ark-1", Models: []string{"glm-4-7-251222"}}, + {ID: "ark-agent", Name: "Ark Agent", Chat: "https://ark.cn-beijing.volces.com/api/plan/v3", Key: "ark-1"}, + {ID: "ark-own", Name: "Ark Own", Chat: v3, Decide: "https://ark.ap-southeast.volces.com/api/v3", Key: "ark-1"}, + {ID: "other", Name: "Other", Responses: "https://api.example.com/api/v3", Key: "k"}, + } { + if err := Save(p); err != nil { + t.Fatal(err) + } + } + want := map[string]string{"ark-responses": v1, "ark-chat": v1, "ark-preset": v1, "ark-coding": "", "ark-agent": "", "ark-own": "https://ark.ap-southeast.volces.com/api/v3", "other": ""} + for id, d := range want { + p, err := Find(id) + if err != nil { + t.Fatal(err) + } + if p.Decide != d { + t.Errorf("%s: System One at %q, want %q", id, p.Decide, d) + } + } + var got []string + for _, e := range OfferedDeciders(nil) { + got = append(got, e.ID) + } + slices.Sort(got) + if w := []string{"ark-chat/" + ArkDecision, "ark-own/" + ArkDecision, "ark-preset/" + ArkDecision, "ark-responses/" + ArkDecision}; !slices.Equal(got, w) { + t.Fatalf("classifiers offered: %q, want %q", got, w) + } +} diff --git a/internal/provider/provider.go b/internal/provider/provider.go index eb1aa6ff4..adeebe68d 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -1755,6 +1755,13 @@ func normalize(p Provider) Provider { if (p.Preset == OMLXPreset || p.Preset == MLXServePreset || p.Preset == "ollama" || p.Preset == "ollama-cloud") && p.Decide == "" && p.Chat != "" { p.Decide = p.Chat } + // one asked at Volcengine Ark's pay as you go, its preset's or a + // custom one of either protocol, answers System One on the same key: + // its decision model is offered with no URL to type (a user on + // Discord found no System One endpoint for Ark, custom or preset) + if p.Decide == "" { + p.Decide = p.arkSystemOne() + } if p.Routing != Ordered && p.Routing != Rotate && p.Routing != LeastUsed && p.Routing != Pace && p.Routing != Weighted && p.Routing != FreeFirst && p.Routing != Fastest && p.Routing != Drain && !PluginRouting(p.Routing) { p.Routing = "" }