Files
DeepTutor/deeptutor/agents/visualize/pipeline.py
Bingxi Zhao (Frank) e8f0e77f83 refactor(visualize): migrate Book blocks to validate+repair, drop LLM review
Finishes the visualize overhaul (517c90b backend + b499ba7 frontend).

- Book figure/interactive now share the chat path: deterministic local
  validate_visualization, one targeted repair on failure (figure), and
  GenerationFailure on residual invalidity so the book engine retries
  instead of baking a broken figure/placeholder into the book.
- Delete the now-dead open-ended LLM review: pipeline.run_review and the
  review prompts (review_agent.yaml keeps only repair_system/
  repair_user_template). ReviewAgent's process() IS the repair pass now
  (BaseAgent.process is abstract, so repair was renamed, not stubbed).
- Prompts: drop the 'split into an overview plus a detail figure' wording
  that contradicted the single-<svg> policy; add a text vertical-centering
  rule (y = box center, host centers via CSS) and a visual_genre fallback
  line. en + zh kept in sync.
- svg-theme.css: dominant-baseline: central on .dt-svg-root text — the
  host guarantees vertical centering so the model never has to emit (or
  misspell) dominant-baseline itself.
- tests: replace the stale FakeReview/run_review fake with a valid-svg
  no-repair path in test_capabilities_runtime.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-11 00:15:58 +08:00

92 lines
2.5 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,
) -> str:
return await self.code_agent.process(
user_input=user_input,
history_context=history_context,
analysis=analysis,
)
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"]