Enhanced debug and fix code method
(self, section_id: str, max_fix_attempts: int = 3)
| 354 | return code |
| 355 | |
| 356 | def debug_and_fix_code(self, section_id: str, max_fix_attempts: int = 3) -> bool: |
| 357 | """Enhanced debug and fix code method""" |
| 358 | if section_id not in self.section_codes: |
| 359 | return False |
| 360 | |
| 361 | for fix_attempt in range(max_fix_attempts): |
| 362 | print(f"🔧 {self.learning_topic} Debugging {section_id} (attempt {fix_attempt + 1}/{max_fix_attempts})") |
| 363 | |
| 364 | try: |
| 365 | scene_name = f"{section_id.title().replace('_', '')}Scene" |
| 366 | code_file = f"{section_id}.py" |
| 367 | cmd = ["manim", "-ql", str(code_file), scene_name] |
| 368 | |
| 369 | result = subprocess.run(cmd, capture_output=True, text=True, cwd=self.output_dir, timeout=180) |
| 370 | |
| 371 | if result.returncode == 0: |
| 372 | video_patterns = [ |
| 373 | self.output_dir / "media" / "videos" / f"{code_file.replace('.py', '')}" / "480p15" / f"{scene_name}.mp4", |
| 374 | self.output_dir / "media" / "videos" / "480p15" / f"{scene_name}.mp4", |
| 375 | ] |
| 376 | |
| 377 | for video_path in video_patterns: |
| 378 | if video_path.exists(): |
| 379 | self.section_videos[section_id] = str(video_path) |
| 380 | print(f"✅ {self.learning_topic} {section_id} finished") |
| 381 | return True |
| 382 | |
| 383 | current_code = self.section_codes[section_id] |
| 384 | fixed_code = self.scope_refine_fixer.fix_code_smart(section_id, current_code, result.stderr, self.output_dir) |
| 385 | |
| 386 | if fixed_code: |
| 387 | self.section_codes[section_id] = fixed_code |
| 388 | with open(self.output_dir / code_file, "w", encoding="utf-8") as f: |
| 389 | f.write(fixed_code) |
| 390 | else: |
| 391 | break |
| 392 | |
| 393 | except subprocess.TimeoutExpired: |
| 394 | print(f"❌ {self.learning_topic} {section_id} timed out") |
| 395 | break |
| 396 | except Exception as e: |
| 397 | print(f"❌ {self.learning_topic} {section_id} failed with exception: {e}") |
| 398 | break |
| 399 | |
| 400 | return False |
| 401 | |
| 402 | def get_mllm_feedback(self, section: Section, video_path: str, round_number: int = 1) -> VideoFeedback: |
| 403 | print(f"🤖 {self.learning_topic} Using MLLM to analyze video ({round_number}/{self.feedback_rounds}): {section.id}") |
no test coverage detected