Files
wojiecihuo 651a616b02 fix(visualize): raise the budget to 32k, cap it to the model, and retry without thinking (#3019)
* 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.
2026-11-27 22:26:59 +08:00

94 lines
2.6 KiB
Python

"""Orchestrates the three-stage visualization generation flow."""
from __future__ import annotations
from typing import Any, Callable
from deeptutor.core.context import Attachment
from .agents import AnalysisAgent, CodeGeneratorAgent, ReviewAgent
from .models import ReviewResult, VisualizationAnalysis
class VisualizePipeline:
def __init__(
self,
*,
api_key: str | None,
base_url: str | None,
api_version: str | None,
language: str = "zh",
trace_callback: Callable[[dict[str, Any]], Any] | None = None,
) -> None:
self.analysis_agent = AnalysisAgent(
api_key=api_key,
base_url=base_url,
api_version=api_version,
language=language,
)
self.code_agent = CodeGeneratorAgent(
api_key=api_key,
base_url=base_url,
api_version=api_version,
language=language,
)
self.review_agent = ReviewAgent(
api_key=api_key,
base_url=base_url,
api_version=api_version,
language=language,
)
self.set_trace_callback(trace_callback)
def set_trace_callback(self, callback: Callable[[dict[str, Any]], Any] | None) -> None:
for agent in (self.analysis_agent, self.code_agent, self.review_agent):
agent.set_trace_callback(callback)
async def run_analysis(
self,
*,
user_input: str,
history_context: str,
render_mode: str = "auto",
attachments: list[Attachment] | None = None,
) -> VisualizationAnalysis:
return await self.analysis_agent.process(
user_input=user_input,
history_context=history_context,
render_mode=render_mode,
attachments=attachments,
)
async def run_code_generation(
self,
*,
user_input: str,
history_context: str,
analysis: VisualizationAnalysis,
reasoning_effort: str | None = None,
) -> str:
return await self.code_agent.process(
user_input=user_input,
history_context=history_context,
analysis=analysis,
reasoning_effort=reasoning_effort,
)
async def run_repair(
self,
*,
user_input: str,
analysis: VisualizationAnalysis,
code: str,
error: str,
) -> ReviewResult:
return await self.review_agent.process(
user_input=user_input,
analysis=analysis,
code=code,
error=error,
)
__all__ = ["VisualizePipeline"]