fix(webui): allow custom context window token budgets (#5901)

* fix(webui): allow custom context window token budgets

* fix(i18n): translate context window hints in all locales

* fix(webui): accept context window K and M shorthand

* fix(webui): shorten context window hints

* refactor(webui): simplify context window validation
This commit is contained in:
chengyongru authored and GitHub committed 2026-09-24 18:26:03 +08:00
1 parent fdee134afb
commit eb3fc07087
17 files changed
+135 -49

No files matched your search

@@ -60,6 +60,21 @@ export function normalizeContextWindowTokens(value: number | null | undefined):
return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : 200_000;
}
export function parseContextWindowTokens(value: string): number {
const match = /^(\d+(?:\.\d+)?)\s*([km]?)$/i.exec(value.trim());
if (!match) return NaN;
const exponent = { k: 3, m: 6 }[match[2].toLowerCase()] ?? 0;
const tokens = Number(`${match[1]}e${exponent}`);
return Number.isSafeInteger(tokens) && tokens > 0 ? tokens : NaN;
}
export function formatContextWindowInput(tokens: number): string {
if (!Number.isFinite(tokens)) return "";
if (tokens % 1_000_000 === 0) return `${tokens / 1_000_000}m`;
if (tokens % 1_000 === 0) return `${tokens / 1_000}k`;
return String(tokens);
}
function settingsProviderRow(
payload: SettingsPayload,
provider: string | null | undefined,