providers: the context window can be set in the app — a provider's editor has a Context window field, 128k for all its models or gpt-6=1m for one, comma separated, which agents are told over what the vendor or models.dev says (as magpie provider set … context= already did); empty leaves it to them again. Asked on X
This commit is contained in:
@@ -2105,7 +2105,7 @@ function renderEditor(p, presetID) {
|
||||
// more provider of it, under a name and id of its own
|
||||
const another = isNew && !!pr?.added;
|
||||
draft = draft || (p
|
||||
? { id: p.id, name: p.name, preset: p.preset, chat: p.chat, responses: p.responses, anthropic: p.anthropic, catalog: p.catalog, key: "", api: p.chat ? "openai" : p.anthropic ? "anthropic" : p.responses ? "responses" : "openai", chosen: p.models.filter((m) => m.on).map((m) => m.id), extra: [], headers: headerRows(p.headers), icon: p.icon || "", fallback: [...(p.fallback || [])], unlisted: !!p.unlisted, balanceURL: p.balanceURL || "", balancePath: p.balancePath || "", modelsURL: p.modelsURL || "" }
|
||||
? { id: p.id, name: p.name, preset: p.preset, chat: p.chat, responses: p.responses, anthropic: p.anthropic, catalog: p.catalog, key: "", api: p.chat ? "openai" : p.anthropic ? "anthropic" : p.responses ? "responses" : "openai", chosen: p.models.filter((m) => m.on).map((m) => m.id), extra: [], headers: headerRows(p.headers), icon: p.icon || "", fallback: [...(p.fallback || [])], unlisted: !!p.unlisted, balanceURL: p.balanceURL || "", balancePath: p.balancePath || "", modelsURL: p.modelsURL || "", contexts: contextsText(p.contexts) }
|
||||
: pr
|
||||
? { id: pr.id, name: pr.name, preset: pr.id, key: "", chosen: [], extra: [], headers: [] }
|
||||
: { id: "", name: "", preset: "", chat: "", responses: "", anthropic: "", catalog: "", key: "", api: "openai", chosen: [], extra: [], headers: [], icon: "" });
|
||||
@@ -2293,6 +2293,13 @@ function renderEditor(p, presetID) {
|
||||
}
|
||||
|
||||
if (p) ed.append(...field(t("Models"), renderModels(p), ""));
|
||||
{
|
||||
// the window agents are told a model has, over what the vendor or
|
||||
// models.dev says: one for all of them, and model=size for one
|
||||
const cx = input(draft.contexts || "", t("e.g. 128k · or gpt-6=1m, comma separated"));
|
||||
cx.oninput = () => { draft.contexts = cx.value; };
|
||||
ed.append(...field(t("Context window"), cx, t("How long a request the models take, told to the agents; empty leaves it to the vendor and models.dev")));
|
||||
}
|
||||
if (p) ed.append(...field(t("Fallback"), renderFallback(p), fallbackHint(p)));
|
||||
else if (custom) {
|
||||
const ex = input(draft.extra.join(", "), t("model ids, comma separated · e.g. gpt-5.5, claude-sonnet-5"));
|
||||
@@ -2370,6 +2377,9 @@ function renderEditor(p, presetID) {
|
||||
const body = { id: draft.id, name: draft.name, preset: draft.preset, key: draft.key || "", chat: draft.chat, responses: draft.responses, anthropic: draft.anthropic, catalog: draft.catalog, models: p ? draft.chosen : draft.extra, headers: headersOf(draft.headers), new: isNew };
|
||||
if (custom) { body.icon = draft.icon || "generic"; body.balanceURL = (draft.balanceURL || "").trim(); body.balancePath = (draft.balancePath || "").trim(); body.modelsURL = (draft.modelsURL || "").trim(); }
|
||||
if (p) { body.fallback = draft.fallback; body.unlisted = draft.unlisted; }
|
||||
const cx = parseContexts(draft.contexts || "");
|
||||
if (cx.error) return editorError(t("Context window: {v} is not a length like 128k or 1m", { v: cx.error }), "warn");
|
||||
body.contexts = cx.map;
|
||||
if (draft.balanceToken) body.balanceToken = draft.balanceToken;
|
||||
else if (draft.clearBalanceToken) body.clearBalanceToken = true;
|
||||
if (isNew && custom && !body.name) { name.focus(); return editorError(t("Give it a name"), "warn"); }
|
||||
@@ -2385,6 +2395,31 @@ function renderEditor(p, presetID) {
|
||||
return ed;
|
||||
}
|
||||
|
||||
// contextsText is a provider's contexts as the editor shows them: the one
|
||||
// for all its models first, then model=size.
|
||||
function contextsText(cx) {
|
||||
if (!cx) return "";
|
||||
const size = (n) => n % 1e6 === 0 ? n / 1e6 + "m" : n % 1e3 === 0 ? n / 1e3 + "k" : String(n);
|
||||
const out = cx["*"] ? [size(cx["*"])] : [];
|
||||
for (const [id, n] of Object.entries(cx).sort()) if (id !== "*") out.push(id + "=" + size(n));
|
||||
return out.join(", ");
|
||||
}
|
||||
|
||||
// parseContexts reads "128k, gpt-6=1m" back: sizes by model id, "*" for
|
||||
// all; error is the first part that isn't a size.
|
||||
function parseContexts(text) {
|
||||
const map = {};
|
||||
for (const part of text.split(/[,,\n]/).map((x) => x.trim()).filter(Boolean)) {
|
||||
const i = part.lastIndexOf("=");
|
||||
const id = i < 0 ? "*" : part.slice(0, i).trim(), v = (i < 0 ? part : part.slice(i + 1)).trim().toLowerCase().replace(/_/g, "");
|
||||
const m = /^(\d+(?:\.\d+)?)([km]?)$/.exec(v);
|
||||
if (!m || !id) return { error: part };
|
||||
const n = Math.round(parseFloat(m[1]) * (m[2] === "m" ? 1e6 : m[2] === "k" ? 1e3 : 1));
|
||||
if (n > 0) map[id] = n;
|
||||
}
|
||||
return { map };
|
||||
}
|
||||
|
||||
// fetchImportIcon asks the server to download the vendor's own logo, named
|
||||
// by the link. It swaps the header mark when it lands; a failure is silent
|
||||
// (the generic outline stays), since the icon is decoration, not the deal.
|
||||
|
||||
@@ -180,6 +180,10 @@ const I18N = {
|
||||
"Account": "账号",
|
||||
"Accounts": "账号",
|
||||
"Fallback": "备用",
|
||||
"Context window": "上下文窗口",
|
||||
"e.g. 128k · or gpt-6=1m, comma separated": "如 128k · 或 gpt-6=1m,逗号分隔",
|
||||
"How long a request the models take, told to the agents; empty leaves it to the vendor and models.dev": "模型能接受的上下文长度,会告诉各个 Agent;留空则按厂商和 models.dev 的",
|
||||
"Context window: {v} is not a length like 128k or 1m": "上下文窗口:{v} 不是 128k、1m 这样的长度",
|
||||
"add a model: filter, or type provider/model…": "添加模型:筛选,或输入 provider/model…",
|
||||
"No provider serves {id} now; it is skipped": "现在没有供应商提供 {id},会跳过它",
|
||||
"Up": "上移",
|
||||
|
||||
@@ -63,6 +63,7 @@ type providerJSON struct {
|
||||
Models []modelJSON `json:"models"` // everything the vendor lists, exposed ones flagged
|
||||
Exposed int `json:"exposed"` // how many reach the agents
|
||||
Unlisted bool `json:"unlisted"` // its models serve only through routing groups
|
||||
Contexts map[string]int `json:"contexts,omitempty"` // the windows the user set, "*" for all its models
|
||||
Fetched string `json:"fetched"` // "3h ago" when the list came from the vendor
|
||||
Agents []providerAgent `json:"agents"` // detected agents, current ones flagged
|
||||
Sponsored bool `json:"sponsored"`
|
||||
@@ -152,7 +153,7 @@ func providerInfo(p provider.Provider, agents []*agent.Agent) providerJSON {
|
||||
Catalog: p.Catalog, Website: p.Website, KeysURL: p.KeysURL,
|
||||
Headers: p.Headers, BalanceURL: p.BalanceURL, BalancePath: p.BalancePath, ModelsURL: p.ModelsURL,
|
||||
Ready: p.Ready(), Chosen: p.Models, Models: []modelJSON{}, Agents: []providerAgent{},
|
||||
Fallback: p.Fallback, Routing: p.Routing, Affinity: p.Affinity, Unlisted: p.Unlisted,
|
||||
Fallback: p.Fallback, Routing: p.Routing, Affinity: p.Affinity, Unlisted: p.Unlisted, Contexts: p.Contexts,
|
||||
}
|
||||
if out.Fallback == nil {
|
||||
out.Fallback = []string{}
|
||||
@@ -352,7 +353,7 @@ func providerRoutes(mux *http.ServeMux, w Windows) {
|
||||
// a preset needs nothing but the key; a saved provider keeps
|
||||
// its key when the form left it blank
|
||||
if pr, err := provider.FromPreset(in.Preset); err == nil && in.Chat == "" && in.Responses == "" && in.Anthropic == "" {
|
||||
pr.Key, pr.Models, pr.Fallback, pr.Headers, pr.BalanceToken = in.Key, in.Models, in.Fallback, in.Headers, in.BalanceToken
|
||||
pr.Key, pr.Models, pr.Fallback, pr.Headers, pr.BalanceToken, pr.Contexts = in.Key, in.Models, in.Fallback, in.Headers, in.BalanceToken, in.Contexts
|
||||
if in.Name != "" {
|
||||
pr.Name = in.Name
|
||||
}
|
||||
@@ -384,7 +385,7 @@ func providerRoutes(mux *http.ServeMux, w Windows) {
|
||||
in.Keys = old.Keys
|
||||
in.Routing = old.Routing // set on its own, with route
|
||||
if in.Contexts == nil {
|
||||
in.Contexts = old.Contexts // set from the terminal
|
||||
in.Contexts = old.Contexts // a save that doesn't say
|
||||
}
|
||||
if in.Key == old.Key {
|
||||
in.KeyName, in.KeyProtocol = old.KeyName, old.KeyProtocol
|
||||
|
||||
Reference in New Issue
Block a user