DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
Fix Windows compatibility for Math Animator renderer
kevin7b55f11c7e85
diff --git a/deeptutor/agents/math_animator/prompts/en/code_generator_agent.yaml b/deeptutor/agents/math_animator/prompts/en/code_generator_agent.yamlindex 0f8b6dd1d..9d039bddd 100644--- a/deeptutor/agents/math_animator/prompts/en/code_generator_agent.yaml+++ b/deeptutor/agents/math_animator/prompts/en/code_generator_agent.yaml@@ -19,8 +19,10 @@ generate_system: |- After the final important conclusion appears, keep a stable hold of roughly 1.5-3 seconds so the viewer can actually read it.- If the resulting code would likely feel shorter than about 10 seconds, extend the pacing unless the user explicitly requested a short clip.- If the user gives an explicit target duration (for example, 10 seconds), this requirement has highest priority: explicitly budget enough `run_time` and `self.wait(...)` in code so total runtime stays close to target (recommended >= 90% of target).- - Assume local LaTeX may be unavailable. By default, do NOT use `Tex`, `MathTex`, `SingleStringMathTex`, or any LaTeX-dependent rendering path.+ - Assume local LaTeX may be unavailable. By default, do NOT use `Tex`, `MathTex`, `SingleStringMathTex`, `MarkupText`, or any LaTeX-dependent rendering path.- Prefer non-LaTeX math presentation with `Text`, `DecimalNumber`, tables, labels, and geometric visualization; avoid requiring a local `latex` executable.+ - Do NOT use the `stroke_dash_pattern` parameter (not supported in Manim v0.20.1); use alternative approaches for dashed lines.+ - Do NOT use `self.save_state()` (not supported in MovingCameraScene); use alternative state management.- Camera movement rule: only use `self.camera.frame` when the scene class inherits `MovingCameraScene`. If the class is plain `Scene`, `self.camera.frame` must not appear.- If camera capability is uncertain, skip camera pan/zoom code and prioritize render stability.@@ -51,7 +53,9 @@ retry_system: |While repairing, do not shorten the animation just to make it run. Preserve complete teaching pacing and the necessary pauses whenever possible.If the original animation is obviously too short, you may also add the necessary waits, extra beats, or ending hold while repairing.If the user gave an explicit duration target, the repaired code should remain close to that target instead of becoming shorter.- Also avoid introducing `Tex` / `MathTex` by default unless LaTeX is explicitly required and available.+ Also avoid introducing `Tex` / `MathTex` / `MarkupText` by default unless LaTeX is explicitly required and available.+ If the error mentions `stroke_dash_pattern`, remove that parameter immediately.+ If the error mentions `save_state`, remove that method call immediately.If the error mentions `self.camera.frame`, repair by either:1) changing the scene base class to `MovingCameraScene`, or2) removing camera-frame animation while keeping the teaching flow.diff --git a/deeptutor/agents/math_animator/prompts/zh/code_generator_agent.yaml b/deeptutor/agents/math_animator/prompts/zh/code_generator_agent.yamlindex e5e0b6e19..f763c2ea5 100644--- a/deeptutor/agents/math_animator/prompts/zh/code_generator_agent.yaml+++ b/deeptutor/agents/math_animator/prompts/zh/code_generator_agent.yaml@@ -19,8 +19,10 @@ generate_system: |- 最后一个关键结论出现后,默认再保留约 1.5-3 秒稳定停留,避免观众还没看清动画就结束。- 如果最终代码的体感时长可能低于约 10 秒,除非用户明确要求短视频,否则必须继续补充步骤、停顿或收尾。- 如果用户明确给出了目标时长(例如 10 秒),这条约束优先级最高:请在代码中显式安排足够的 `run_time` 与 `self.wait(...)`,让总时长尽量贴近目标(建议不低于目标的 90%)。- - 当前运行环境可能没有本地 LaTeX。默认禁止使用 `Tex`、`MathTex`、`SingleStringMathTex` 与任何 LaTeX 依赖渲染链。+ - 当前运行环境可能没有本地 LaTeX。默认禁止使用 `Tex`、`MathTex`、`SingleStringMathTex`、`MarkupText` 与任何 LaTeX 依赖渲染链。- 数学表达优先用 `Text`、`DecimalNumber`、`MathTable`(非 LaTeX 方案)或直接几何可视化来表达;不要依赖 `latex` 可执行程序。+ - 禁止使用 `stroke_dash_pattern` 参数(Manim v0.20.1 不支持),如需虚线效果请改用其他方式实现。+ - 禁止使用 `self.save_state()` 方法(MovingCameraScene 不支持),改用其他状态管理方式。- 相机移动规则:只有在类继承 `MovingCameraScene` 时,才允许使用 `self.camera.frame`。若类是普通 `Scene`,严禁出现 `self.camera.frame`。- 若不确定相机能力,默认不要写相机缩放/平移代码,优先保证可渲染稳定性。@@ -52,7 +54,9 @@ retry_system: |修复时不要为了“快点能跑”而把动画压缩得更短;尽量保留完整讲解节奏和必要停顿。若原代码明显过短,也允许在修复时顺手补足必要的等待、展开步骤和结尾停留。若用户给了明确时长,修复后也必须保持接近该时长,不要因为修错而把视频缩短。- 默认也禁止引入 `Tex` / `MathTex`,除非用户明确要求 LaTeX 且环境已具备 LaTeX。+ 默认禁止引入 `Tex` / `MathTex` / `MarkupText`,除非用户明确要求 LaTeX 且环境已具备 LaTeX。+ 若报错包含 `stroke_dash_pattern`,立即移除该参数。+ 若报错包含 `save_state`,立即删除该方法调用。若报错与 `self.camera.frame` 相关,必须二选一修复:1) 把场景类改为 `MovingCameraScene`;或2) 删除相机动画语句并保留原教学逻辑。diff --git a/deeptutor/agents/math_animator/renderer.py b/deeptutor/agents/math_animator/renderer.pyindex 32c06dd22..797064abe 100644--- a/deeptutor/agents/math_animator/renderer.py+++ b/deeptutor/agents/math_animator/renderer.py@@ -4,6 +4,7 @@ from __future__ import annotationsimport asyncioimport re+import subprocessimport sysfrom pathlib import Pathfrom typing import Awaitable, Callable@@ -145,43 +146,32 @@ class ManimRenderService:else:command.extend(["--format", "mp4"])- process = await asyncio.create_subprocess_exec(- *command,- stdout=asyncio.subprocess.PIPE,- stderr=asyncio.subprocess.PIPE,- )await self._emit_progress(f"Started Manim process for `{scene_name}` with command: {' '.join(command)}",raw=True,)- stdout_lines: list[str] = []- stderr_lines: list[str] = []-- async def _drain_stream(- stream: asyncio.StreamReader | None,- sink: list[str],- *,- prefix: str,- ) -> None:- if stream is None:- return- while True:- raw_line = await stream.readline()- if not raw_line:- break- line = raw_line.decode(errors="ignore").strip()- if not line:- continue- sink.append(line)- await self._emit_progress(f"[{prefix}] {line}", raw=True)-- await asyncio.gather(- _drain_stream(process.stdout, stdout_lines, prefix="stdout"),- _drain_stream(process.stderr, stderr_lines, prefix="stderr"),- )- await process.wait()- await self._emit_progress(f"Manim process finished with exit code {process.returncode}.", raw=True)- if process.returncode != 0:++ # Use subprocess.run in a thread to avoid asyncio event loop+ # compatibility issues on Windows (SelectorEventLoop does not+ # support create_subprocess_exec).+ def _run_sync() -> subprocess.CompletedProcess:+ return subprocess.run(+ command,+ capture_output=True,+ text=True,+ )++ result = await asyncio.to_thread(_run_sync)++ stdout_lines = [l for l in (result.stdout or "").splitlines() if l.strip()]+ stderr_lines = [l for l in (result.stderr or "").splitlines() if l.strip()]+ for line in stdout_lines:+ await self._emit_progress(f"[stdout] {line}", raw=True)+ for line in stderr_lines:+ await self._emit_progress(f"[stderr] {line}", raw=True)++ await self._emit_progress(f"Manim process finished with exit code {result.returncode}.", raw=True)+ if result.returncode != 0:raise ManimRenderError(trim_error_message("\n".join(part for part in ["\n".join(stdout_lines), "\n".join(stderr_lines)] if part)diff --git a/web/components/chat/home/ChatComposer.tsx b/web/components/chat/home/ChatComposer.tsxindex 4e0163a2c..a0693b492 100644--- a/web/components/chat/home/ChatComposer.tsx+++ b/web/components/chat/home/ChatComposer.tsx@@ -289,6 +289,7 @@ export default function ChatComposer({onClick={onTextareaClick}onPaste={onPaste}rows={1}+ suppressHydrationWarningplaceholder={isMathAnimatorMode? t("Describe the math animation or storyboard you want...")