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

+4 -6
View File
@@ -1066,7 +1066,7 @@ def test_update_model_configuration_preserves_custom_context_windows(
assert saved.model_presets["codex"].context_window_tokens == 128000
def test_update_context_window_rejects_unknown_values(
def test_update_context_window_persists_custom_value(
tmp_path,
monkeypatch: pytest.MonkeyPatch,
) -> None:
@@ -1074,11 +1074,9 @@ def test_update_context_window_rejects_unknown_values(
save_config(Config(), config_path)
monkeypatch.setattr("nanobot.config.loader._current_config_path", config_path)
with pytest.raises(
WebUISettingsError,
match="context_window_tokens must be 65536, 200000, 262144, 500000, or 1048576",
):
update_agent_settings({"context_window_tokens": ["128000"]})
payload = update_agent_settings({"context_window_tokens": ["128000"]})
assert payload["agent"]["context_window_tokens"] == 128000
assert load_config(config_path).agents.defaults.context_window_tokens == 128000
def test_update_model_configuration_rejects_default_preset(
+23
View File
@@ -2,8 +2,11 @@ from __future__ import annotations
from typing import Any
import pytest
from nanobot.config.schema import Config
from nanobot.webui.settings_models import (
WebUISettingsError,
model_settings_payload,
update_agent_model_settings,
update_provider_settings,
@@ -57,3 +60,23 @@ def test_model_domain_owns_dto_and_config_updates() -> None:
"providers",
}
assert payload["agent"]["model"] == "openai/gpt-5.4"
@pytest.mark.parametrize("tokens", [128_000, 131_072, 1_000_000])
def test_default_context_window_accepts_custom_tokens(tokens: int) -> None:
config = Config()
assert update_agent_model_settings(
config, {"context_window_tokens": [str(tokens)]}, oauth_status=_oauth_status,
)
assert config.agents.defaults.context_window_tokens == tokens
assert model_settings_payload(config, oauth_status=_oauth_status)["agent"]["context_window_tokens"] == tokens
@pytest.mark.parametrize("value", ["", "0", "-1", "1.5", "abc"])
def test_default_context_window_rejects_invalid_tokens(value: str) -> None:
config = Config()
with pytest.raises(WebUISettingsError, match="context_window_tokens must"):
update_agent_model_settings(
config, {"context_window_tokens": [value]}, oauth_status=_oauth_status,
)
assert config.agents.defaults.context_window_tokens == 200_000