cryogenic22 commited on
Commit
1a1deca
·
verified ·
1 Parent(s): 80608d6

Update learning_platform.py

Browse files
Files changed (1) hide show
  1. learning_platform.py +69 -70
learning_platform.py CHANGED
@@ -125,76 +125,75 @@ class CoursePrompts:
125
  Return in the same JSON format."""
126
 
127
  class CourseBuilder:
128
- def __init__(self, api_key: str = None):
129
- self.api_key = api_key or os.getenv("OPENAI_API_KEY")
130
- self.setup_agents()
131
- self.setup_graph()
132
-
133
- def setup_agents(self):
134
- self.llm = ChatOpenAI(
135
- temperature=0.7,
136
- model="gpt-4",
137
- openai_api_key=self.api_key
138
- )
139
-
140
- def course_planner(self, state: CourseState) -> CourseState:
141
- """Course planning agent node"""
142
- print("---COURSE PLANNER---")
143
- prompt = PromptTemplate(
144
- template=CoursePrompts.planner_prompt(),
145
- input_variables=["topic", "difficulty"]
146
- )
147
-
148
- response = self.llm.predict(
149
- prompt.format(
150
- topic=state["current_topic"],
151
- difficulty=state["difficulty"]
152
- )
153
- )
154
- return {
155
- "messages": [AIMessage(content=response)],
156
- "status": "planning",
157
- "current_topic": state["current_topic"],
158
- "difficulty": state["difficulty"],
159
- "modules": []
160
- }
161
-
162
- async def generate_module_content(self, module: CourseModule) -> List[Section]:
163
- try:
164
- section = Section(
165
- title=f"Introduction to {module.title}",
166
- content=f"Basic concepts of {module.title}",
167
- key_points=["Key concept 1", "Key concept 2"],
168
- quiz_questions=[{
169
- "question": f"What is {module.title}?",
170
- "options": ["A", "B", "C", "D"],
171
- "correct_answer": "A",
172
- "explanation": "Basic explanation"
173
- }]
174
- )
175
- return [section]
176
- except Exception as e:
177
- print(f"Error generating content: {e}")
178
- return []
179
-
180
- def check_quality(self, state: CourseState) -> Literal["edit", "complete"]:
181
- messages = state["messages"]
182
- last_message = messages[-1]
183
-
184
- if len(last_message.content) > 1000 and "code example" in last_message.content.lower():
185
- return "complete"
186
- return "edit"
187
-
188
- def setup_graph(self):
189
- workflow = StateGraph(CourseState)
190
-
191
- workflow.add_node("planner", self.course_planner)
192
- workflow.add_edge(START, "planner")
193
- workflow.add_edge("planner", END)
194
-
195
- self.graph = workflow.compile()
196
-
197
-
198
  class LearningPlatform:
199
  def __init__(self, api_key: str = None):
200
  self.api_key = api_key or os.getenv("OPENAI_API_KEY")
 
125
  Return in the same JSON format."""
126
 
127
  class CourseBuilder:
128
+ def __init__(self, api_key: str = None):
129
+ self.api_key = api_key or os.getenv("OPENAI_API_KEY")
130
+ self.setup_agents()
131
+ self.setup_graph()
132
+
133
+ def setup_agents(self):
134
+ self.llm = ChatOpenAI(
135
+ temperature=0.7,
136
+ model="gpt-4",
137
+ openai_api_key=self.api_key
138
+ )
139
+
140
+ def course_planner(self, state: CourseState) -> CourseState:
141
+ """Course planning agent node"""
142
+ print("---COURSE PLANNER---")
143
+ prompt = PromptTemplate(
144
+ template=CoursePrompts.planner_prompt(),
145
+ input_variables=["topic", "difficulty"]
146
+ )
147
+
148
+ response = self.llm.predict(
149
+ prompt.format(
150
+ topic=state["current_topic"],
151
+ difficulty=state["difficulty"]
152
+ )
153
+ )
154
+ return {
155
+ "messages": [AIMessage(content=response)],
156
+ "status": "planning",
157
+ "current_topic": state["current_topic"],
158
+ "difficulty": state["difficulty"],
159
+ "modules": []
160
+ }
161
+
162
+ async def generate_module_content(self, module: CourseModule) -> List[Section]:
163
+ try:
164
+ section = Section(
165
+ title=f"Introduction to {module.title}",
166
+ content=f"Basic concepts of {module.title}",
167
+ key_points=["Key concept 1", "Key concept 2"],
168
+ quiz_questions=[{
169
+ "question": f"What is {module.title}?",
170
+ "options": ["A", "B", "C", "D"],
171
+ "correct_answer": "A",
172
+ "explanation": "Basic explanation"
173
+ }]
174
+ )
175
+ return [section]
176
+ except Exception as e:
177
+ print(f"Error generating content: {e}")
178
+ return []
179
+
180
+ def check_quality(self, state: CourseState) -> Literal["edit", "complete"]:
181
+ messages = state["messages"]
182
+ last_message = messages[-1]
183
+
184
+ if len(last_message.content) > 1000 and "code example" in last_message.content.lower():
185
+ return "complete"
186
+ return "edit"
187
+
188
+ def setup_graph(self):
189
+ workflow = StateGraph(CourseState)
190
+
191
+ workflow.add_node("planner", self.course_planner)
192
+ workflow.add_edge(START, "planner")
193
+ workflow.add_edge("planner", END)
194
+
195
+ self.graph = workflow.compile()
196
+
 
197
  class LearningPlatform:
198
  def __init__(self, api_key: str = None):
199
  self.api_key = api_key or os.getenv("OPENAI_API_KEY")