mgbam commited on
Commit
d2ebfdc
·
verified ·
1 Parent(s): 96005ed

Update agents/topic_agent.py

Browse files
Files changed (1) hide show
  1. agents/topic_agent.py +42 -16
agents/topic_agent.py CHANGED
@@ -1,6 +1,5 @@
1
- # agents/topic_agent.py
2
- import openai
3
  import json
 
4
 
5
  class TopicAgent:
6
  def __init__(self, api_key=None):
@@ -11,24 +10,51 @@ class TopicAgent:
11
  if not openai.api_key:
12
  return self._mock_outline(topic, duration, difficulty)
13
 
14
- response = openai.ChatCompletion.create(
15
- model="gpt-4",
16
- messages=[
17
- {"role": "system", "content": "You're an expert corporate trainer creating AI workshop outlines"},
18
- {"role": "user", "content": (
19
- f"Create a {duration}-hour {difficulty} workshop outline on {topic}. "
20
- "Include: 1) Key learning goals, 2) 4 modules with titles and durations, "
21
- "3) Hands-on exercises per module. Output as JSON."
22
- )}
23
- ]
24
- )
25
- return json.loads(response.choices[0].message.content)
 
 
 
26
 
27
  def _mock_outline(self, topic, duration, difficulty):
28
  return {
29
  "topic": topic,
30
  "duration": f"{duration} hours",
31
  "difficulty": difficulty,
32
- "goals": ["Goal 1", "Goal 2"],
33
- "modules": [{"title": "Module 1", "duration": "30 min"}]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  }
 
 
 
1
  import json
2
+ import openai
3
 
4
  class TopicAgent:
5
  def __init__(self, api_key=None):
 
10
  if not openai.api_key:
11
  return self._mock_outline(topic, duration, difficulty)
12
 
13
+ try:
14
+ response = openai.ChatCompletion.create(
15
+ model="gpt-4",
16
+ messages=[
17
+ {"role": "system", "content": "You're an expert corporate trainer creating AI workshop outlines"},
18
+ {"role": "user", "content": (
19
+ f"Create a {duration}-hour {difficulty} workshop outline on {topic}. "
20
+ "Include: 1) Key learning goals, 2) 4 modules with titles and durations, "
21
+ "3) Hands-on exercises per module. Output as JSON."
22
+ )}
23
+ ]
24
+ )
25
+ return json.loads(response.choices[0].message.content)
26
+ except:
27
+ return self._mock_outline(topic, duration, difficulty)
28
 
29
  def _mock_outline(self, topic, duration, difficulty):
30
  return {
31
  "topic": topic,
32
  "duration": f"{duration} hours",
33
  "difficulty": difficulty,
34
+ "goals": [
35
+ f"Master advanced {topic} techniques",
36
+ "Develop industry-specific applications",
37
+ "Build and evaluate complex AI workflows",
38
+ "Implement best practices for production"
39
+ ],
40
+ "modules": [
41
+ {
42
+ "title": f"Fundamentals of {topic}",
43
+ "duration": "30 min",
44
+ "learning_points": [
45
+ "Core principles and terminology",
46
+ "Patterns and anti-patterns",
47
+ "Evaluation frameworks"
48
+ ]
49
+ },
50
+ {
51
+ "title": f"{topic} for Enterprise Applications",
52
+ "duration": "45 min",
53
+ "learning_points": [
54
+ "Industry-specific use cases",
55
+ "Integration with existing systems",
56
+ "Scalability considerations"
57
+ ]
58
+ }
59
+ ]
60
  }