|
import json |
|
import openai |
|
|
|
class TopicAgent: |
|
def __init__(self, api_key=None): |
|
if api_key: |
|
openai.api_key = api_key |
|
|
|
def generate_outline(self, topic, duration, difficulty): |
|
if not openai.api_key: |
|
return self._mock_outline(topic, duration, difficulty) |
|
|
|
try: |
|
response = openai.ChatCompletion.create( |
|
model="gpt-4", |
|
messages=[ |
|
{"role": "system", "content": "You're an expert corporate trainer creating AI workshop outlines"}, |
|
{"role": "user", "content": ( |
|
f"Create a {duration}-hour {difficulty} workshop outline on {topic}. " |
|
"Include: 1) Key learning goals, 2) 4 modules with titles and durations, " |
|
"3) Hands-on exercises per module. Output as JSON." |
|
)} |
|
] |
|
) |
|
return json.loads(response.choices[0].message.content) |
|
except: |
|
return self._mock_outline(topic, duration, difficulty) |
|
|
|
def _mock_outline(self, topic, duration, difficulty): |
|
return { |
|
"topic": topic, |
|
"duration": f"{duration} hours", |
|
"difficulty": difficulty, |
|
"goals": [ |
|
f"Master advanced {topic} techniques", |
|
"Develop industry-specific applications", |
|
"Build and evaluate complex AI workflows", |
|
"Implement best practices for production" |
|
], |
|
"modules": [ |
|
{ |
|
"title": f"Fundamentals of {topic}", |
|
"duration": "30 min", |
|
"learning_points": [ |
|
"Core principles and terminology", |
|
"Patterns and anti-patterns", |
|
"Evaluation frameworks" |
|
] |
|
}, |
|
{ |
|
"title": f"{topic} for Enterprise Applications", |
|
"duration": "45 min", |
|
"learning_points": [ |
|
"Industry-specific use cases", |
|
"Integration with existing systems", |
|
"Scalability considerations" |
|
] |
|
} |
|
] |
|
} |