mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 00:39:47 +08:00
* fix(book): retry an interactive page with thinking off when it runs out of room deepseek-flash thinks by default and can spend the whole 16000-token visualize budget on reasoning, so a book interactive block came back with no code. When the page is empty or cut off before </html>, ask once more with thinking turned off (thinking_off_effort_for) before failing. If that still runs out of room, the error names the budget sent to the model and the settings that change it. The shipped default stays at 16000: the budget is shared by every visualize caller, and 32768 breaks models with a lower output cap (#3018). Refs #3011 * fix(llm): raise the visualize budget to 32k and cap each request to the model A thinking model can spend 16k tokens before it writes any code, so the visualize default is now 32768. Sent unchanged that would be rejected by models whose output stops lower (gpt-4o and gpt-4o-mini at 16384) and could overflow a small local context window, so every request now carries min(budget, the model's known output limit, half the configured context window). The cap lives in get_token_limit_kwargs, so it applies to every caller; BaseAgent and the agentic loop pass the configured window.
75 lines
2.6 KiB
Python
75 lines
2.6 KiB
Python
"""The visualize loop's output budget must be readable from agents.yaml.
|
|
|
|
``visualize`` built its pipeline with ``max_tokens=16000`` written into the call,
|
|
so a reasoning model that spends most of a round inside ``<think>`` truncated the
|
|
``submit_visualization`` arguments mid-JSON and the canvas came back empty — with
|
|
no setting anywhere that changed it (#1546).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
import pytest
|
|
import yaml
|
|
|
|
from deeptutor.services.config import capabilities_settings as module
|
|
from deeptutor.services.config.capabilities_settings import get_visualize_params
|
|
from deeptutor.services.setup.init import DEFAULT_AGENTS_SETTINGS
|
|
|
|
|
|
def _settings_root(tmp_path: Path, content: dict[str, Any]) -> Path:
|
|
settings_dir = tmp_path / "data" / "user" / "settings"
|
|
settings_dir.mkdir(parents=True, exist_ok=True)
|
|
(settings_dir / "agents.yaml").write_text(yaml.dump(content), encoding="utf-8")
|
|
return tmp_path
|
|
|
|
|
|
def test_visualize_default_leaves_room_for_a_reasoning_model(
|
|
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
) -> None:
|
|
"""A thinking model can spend 16k tokens before writing any code, so the
|
|
default is 32k; the request is still capped to the model's own limit."""
|
|
monkeypatch.setattr(module, "PROJECT_ROOT", _settings_root(tmp_path, {"capabilities": {}}))
|
|
|
|
assert get_visualize_params() == {"temperature": 0.15, "max_tokens": 32768}
|
|
|
|
|
|
def test_fresh_setup_keeps_the_visualize_runtime_default() -> None:
|
|
"""Seeding agents.yaml must not change a fresh install's visualize budget."""
|
|
assert (
|
|
DEFAULT_AGENTS_SETTINGS["capabilities"]["visualize"]
|
|
== module._SIMPLE_LLM_DEFAULTS["visualize"]
|
|
)
|
|
|
|
|
|
def test_visualize_budget_is_overridable_from_agents_yaml(
|
|
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
) -> None:
|
|
monkeypatch.setattr(
|
|
module,
|
|
"PROJECT_ROOT",
|
|
_settings_root(
|
|
tmp_path,
|
|
{"capabilities": {"visualize": {"temperature": 0.4, "max_tokens": 48000}}},
|
|
),
|
|
)
|
|
|
|
assert get_visualize_params() == {"temperature": 0.4, "max_tokens": 48000}
|
|
|
|
|
|
def test_visualize_is_exposed_to_the_settings_page(
|
|
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
) -> None:
|
|
"""The same block the UI reads and writes, so the page cannot drift."""
|
|
monkeypatch.setattr(module, "PROJECT_ROOT", _settings_root(tmp_path, {"capabilities": {}}))
|
|
|
|
payload = module.capabilities_settings_dict()
|
|
|
|
assert payload["visualize"] == {"temperature": 0.15, "max_tokens": 32768}
|
|
|
|
module.save_capabilities_settings({"visualize": {"max_tokens": 32000}})
|
|
|
|
assert get_visualize_params()["max_tokens"] == 32000
|