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:
1 parent
fdee134afb
commit
eb3fc07087
17 files changed
+135
-49
No files matched your search
@@ -283,17 +283,48 @@ describe("Settings models", () => {
|
||||
|
||||
expect(await screen.findByText("Context window")).toBeInTheDocument();
|
||||
expect(screen.getByText("Temperature")).toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "64K" })).toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "200K" })).toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "256K" })).toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "500K" })).toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "1M" })).toBeInTheDocument();
|
||||
expect(screen.getByRole("textbox", { name: "Context window" })).toHaveValue("200k");
|
||||
const reasoningEffort = screen.getByLabelText("Reasoning effort");
|
||||
expect(reasoningEffort).toHaveProperty("type", "text");
|
||||
fireEvent.change(reasoningEffort, { target: { value: "provider-native-mode" } });
|
||||
expect(reasoningEffort).toHaveValue("provider-native-mode");
|
||||
});
|
||||
|
||||
it.each([["128000", 128000], ["131072", 131072], ["272k", 272000], ["256K", 256000], ["1.5m", 1500000], ["1.001k", 1001]] as const)("saves a custom context budget (%s)", async (input, tokens) => {
|
||||
const payload = settingsPayload();
|
||||
vi.stubGlobal("fetch", vi.fn(() => new Promise<Response>(() => {})));
|
||||
requestMutationMock.mockResolvedValue({
|
||||
...payload,
|
||||
model_presets: payload.model_presets.map((preset) => ({ ...preset, context_window_tokens: tokens })),
|
||||
});
|
||||
renderSettingsView({ initialSection: "models", initialSettings: payload });
|
||||
await togglePresetEditor();
|
||||
fireEvent.click(screen.getByRole("button", { name: /Advanced options/ }));
|
||||
fireEvent.change(screen.getByRole("textbox", { name: "Context window" }), {
|
||||
target: { value: input },
|
||||
});
|
||||
fireEvent.click(screen.getByRole("button", { name: "Save" }));
|
||||
await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith(
|
||||
"settings.model_configuration.update", expect.objectContaining({ context_window_tokens: tokens }), expect.any(Number),
|
||||
));
|
||||
expect(screen.getByRole("textbox", { name: "Context window" })).toHaveValue(input);
|
||||
});
|
||||
|
||||
it.each(["", "0", "-1", "1.5", "abc", "2ki", "0.0001k", "9007199254740992"])("keeps invalid context input unsaved (%s)", async (value) => {
|
||||
vi.stubGlobal("fetch", vi.fn(() => new Promise<Response>(() => {})));
|
||||
renderSettingsView({ initialSection: "models", initialSettings: settingsPayload() });
|
||||
await togglePresetEditor();
|
||||
fireEvent.click(screen.getByRole("button", { name: /Advanced options/ }));
|
||||
const input = screen.getByRole("textbox", { name: "Context window" });
|
||||
fireEvent.change(input, { target: { value } });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Save" }));
|
||||
expect(input).toHaveAttribute("aria-invalid", "true");
|
||||
expect(input).toHaveAccessibleDescription("Enter a positive token count, such as 200k, 1m, or 131072.");
|
||||
await new Promise((resolve) => setTimeout(resolve, 750));
|
||||
expect(requestMutationMock).not.toHaveBeenCalled();
|
||||
expect(input).toHaveValue(value);
|
||||
});
|
||||
|
||||
it("opens the preset editor in a dialog and protects the primary preset", async () => {
|
||||
vi.stubGlobal(
|
||||
"fetch",
|
||||
|
||||
Reference in new issue
Block a user