naso / agents /content_agent.py
mgbam's picture
Create content_agent.py
1640066 verified
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"]
]
}