File size: 1,856 Bytes
1640066
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
import openai

class ContentAgent:
    def __init__(self, api_key=None):
        if api_key:
            openai.api_key = api_key

    def generate_content(self, outline):
        if not openai.api_key:
            return self._mock_content(outline)
            
        try:
            response = openai.ChatCompletion.create(
                model="gpt-4",
                messages=[
                    {"role": "system", "content": "You create detailed workshop content from outlines"},
                    {"role": "user", "content": (
                        f"Create workshop content from this outline: {json.dumps(outline)}. "
                        "Include: 1) Detailed scripts, 2) Speaker notes, 3) 3 quiz questions per module, "
                        "4) Hands-on exercises. Output as JSON."
                    )}
                ]
            )
            return json.loads(response.choices[0].message.content)
        except:
            return self._mock_content(outline)
    
    def _mock_content(self, outline):
        return {
            "workshop_title": f"Mastering {outline['topic']}",
            "modules": [
                {
                    "title": module["title"],
                    "script": f"Comprehensive script for {module['title']}...",
                    "speaker_notes": f"Key talking points: {', '.join(module['learning_points'])}",
                    "exercises": [f"Exercise about {point}" for point in module["learning_points"]],
                    "quiz": [
                        {
                            "question": f"Question about {module['title']}",
                            "options": ["A", "B", "C", "D"],
                            "answer": "A"
                        }
                    ]
                } for module in outline["modules"]
            ]
        }