Create content_agent.py
Browse files- agents/content_agent.py +47 -0
agents/content_agent.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import openai
|
3 |
+
|
4 |
+
class ContentAgent:
|
5 |
+
def __init__(self, api_key=None):
|
6 |
+
if api_key:
|
7 |
+
openai.api_key = api_key
|
8 |
+
|
9 |
+
def generate_content(self, outline):
|
10 |
+
if not openai.api_key:
|
11 |
+
return self._mock_content(outline)
|
12 |
+
|
13 |
+
try:
|
14 |
+
response = openai.ChatCompletion.create(
|
15 |
+
model="gpt-4",
|
16 |
+
messages=[
|
17 |
+
{"role": "system", "content": "You create detailed workshop content from outlines"},
|
18 |
+
{"role": "user", "content": (
|
19 |
+
f"Create workshop content from this outline: {json.dumps(outline)}. "
|
20 |
+
"Include: 1) Detailed scripts, 2) Speaker notes, 3) 3 quiz questions per module, "
|
21 |
+
"4) Hands-on exercises. Output as JSON."
|
22 |
+
)}
|
23 |
+
]
|
24 |
+
)
|
25 |
+
return json.loads(response.choices[0].message.content)
|
26 |
+
except:
|
27 |
+
return self._mock_content(outline)
|
28 |
+
|
29 |
+
def _mock_content(self, outline):
|
30 |
+
return {
|
31 |
+
"workshop_title": f"Mastering {outline['topic']}",
|
32 |
+
"modules": [
|
33 |
+
{
|
34 |
+
"title": module["title"],
|
35 |
+
"script": f"Comprehensive script for {module['title']}...",
|
36 |
+
"speaker_notes": f"Key talking points: {', '.join(module['learning_points'])}",
|
37 |
+
"exercises": [f"Exercise about {point}" for point in module["learning_points"]],
|
38 |
+
"quiz": [
|
39 |
+
{
|
40 |
+
"question": f"Question about {module['title']}",
|
41 |
+
"options": ["A", "B", "C", "D"],
|
42 |
+
"answer": "A"
|
43 |
+
}
|
44 |
+
]
|
45 |
+
} for module in outline["modules"]
|
46 |
+
]
|
47 |
+
}
|