File size: 2,972 Bytes
0805c5b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
"""
Planning Tools for Manim MCP Server

This module provides tools for concept planning and ideation for STEM animations.
"""

import json
import logging
from typing import Any, Dict, Optional

from mcp.types import CallToolResult, TextContent

from utils.hf_wrapper import HFInferenceWrapper, ModelConfig

logger = logging.getLogger(__name__)


async def plan_concept(
    hf_wrapper: HFInferenceWrapper, arguments: Dict[str, Any]
) -> CallToolResult:
    """
    Plan a STEM concept for animation.

    Uses a text LLM to create a structured animation plan including:
    - Learning objectives
    - Visual metaphors
    - Scene flow with timestamps
    - Educational value assessment

    Args:
        hf_wrapper: HuggingFace inference wrapper instance
        arguments: Dictionary containing:
            - topic (str): The STEM topic to create an animation for
            - target_audience (str): Target audience level (elementary, middle_school, high_school, college, general)
            - animation_length_minutes (float, optional): Desired animation length in minutes
            - model (str, optional): Hugging Face model to use

    Returns:
        CallToolResult with the structured animation plan
    """
    topic = arguments["topic"]
    target_audience = arguments["target_audience"]
    animation_length = arguments.get("animation_length_minutes", 2.0)
    model = arguments.get("model")

    try:
        model_config = ModelConfig()
        selected_model = model or model_config.text_models[0]

        prompt = f"""
You are a STEM Curriculum Designer. Create a structured animation plan.

Topic: {topic}
Audience: {target_audience}
Length: {animation_length} min

Return a valid JSON object with exactly these keys:
{{
    "learning_objectives": ["string", "string"],
    "visual_metaphors": ["string", "string"],
    "scene_flow": [
        {{
            "timestamp": "0:00-0:30",
            "action": "description of visual action",
            "voiceover": "key narration points"
        }}
    ],
    "estimated_educational_value": "string"
}}

Do not include markdown formatting like ```json. Return raw JSON only.
"""

        response = await hf_wrapper.text_generation(
            model=selected_model,
            prompt=prompt,
            max_new_tokens=1024,
            temperature=0.7,
        )

        logger.info(f"Successfully planned concept for topic: {topic}")

        return CallToolResult(
            content=[
                TextContent(
                    type="text",
                    text=f"Animation Concept Plan:\n\n{response}",
                )
            ]
        )

    except Exception as e:
        logger.error(f"Concept planning failed: {str(e)}")
        return CallToolResult(
            content=[
                TextContent(
                    type="text",
                    text=f"Concept planning failed: {str(e)}",
                )
            ],
            isError=True,
        )