A class for generating manim videos using AI models. This class coordinates the video generation pipeline by managing scene planning, code generation, and video rendering. It supports concurrent scene processing, visual code fixing, and RAG (Retrieval Augmented Generation). Ar
| 37 | load_dotenv(override=True) |
| 38 | |
| 39 | class VideoGenerator: |
| 40 | """ |
| 41 | A class for generating manim videos using AI models. |
| 42 | |
| 43 | This class coordinates the video generation pipeline by managing scene planning, |
| 44 | code generation, and video rendering. It supports concurrent scene processing, |
| 45 | visual code fixing, and RAG (Retrieval Augmented Generation). |
| 46 | |
| 47 | Args: |
| 48 | planner_model: Model used for scene planning and high-level decisions |
| 49 | scene_model: Model used specifically for scene generation (defaults to planner_model) |
| 50 | helper_model: Helper model for additional tasks (defaults to planner_model) |
| 51 | output_dir (str): Directory to store generated files and videos |
| 52 | verbose (bool): Whether to print detailed output |
| 53 | use_rag (bool): Whether to use Retrieval Augmented Generation |
| 54 | use_context_learning (bool): Whether to use context learning with example code |
| 55 | context_learning_path (str): Path to context learning examples |
| 56 | chroma_db_path (str): Path to ChromaDB for RAG |
| 57 | manim_docs_path (str): Path to Manim documentation for RAG |
| 58 | embedding_model (str): Model to use for embeddings |
| 59 | use_visual_fix_code (bool): Whether to use visual feedback for code fixing |
| 60 | use_langfuse (bool): Whether to enable Langfuse logging |
| 61 | trace_id (str, optional): Trace ID for logging |
| 62 | max_scene_concurrency (int): Maximum number of scenes to process concurrently |
| 63 | |
| 64 | Attributes: |
| 65 | output_dir (str): Directory for output files |
| 66 | verbose (bool): Verbosity flag |
| 67 | use_visual_fix_code (bool): Visual code fixing flag |
| 68 | session_id (str): Unique session identifier |
| 69 | scene_semaphore (asyncio.Semaphore): Controls concurrent scene processing |
| 70 | banned_reasonings (list): List of banned reasoning patterns |
| 71 | planner (VideoPlanner): Handles scene planning |
| 72 | code_generator (CodeGenerator): Handles code generation |
| 73 | video_renderer (VideoRenderer): Handles video rendering |
| 74 | """ |
| 75 | |
| 76 | def __init__(self, |
| 77 | planner_model, |
| 78 | scene_model=None, |
| 79 | helper_model=None, |
| 80 | output_dir="output", |
| 81 | verbose=False, |
| 82 | use_rag=False, |
| 83 | use_context_learning=False, |
| 84 | context_learning_path="data/context_learning", |
| 85 | chroma_db_path="data/rag/chroma_db", |
| 86 | manim_docs_path="data/rag/manim_docs", |
| 87 | embedding_model="azure/text-embedding-3-large", |
| 88 | use_visual_fix_code=False, |
| 89 | use_langfuse=True, |
| 90 | trace_id=None, |
| 91 | max_scene_concurrency: int = 5): |
| 92 | self.output_dir = output_dir |
| 93 | self.verbose = verbose |
| 94 | self.use_visual_fix_code = use_visual_fix_code |
| 95 | self.session_id = self._load_or_create_session_id() # Modified to load existing or create new |
| 96 | self.scene_semaphore = asyncio.Semaphore(max_scene_concurrency) |