Spaces:
Sleeping
Sleeping
Update learning_platform.py
Browse files- learning_platform.py +20 -14
learning_platform.py
CHANGED
|
@@ -135,16 +135,17 @@ class CourseBuilder:
|
|
| 135 |
self.setup_graph()
|
| 136 |
|
| 137 |
async def plan_course(self, state: CourseState) -> CourseState:
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
|
|
|
| 141 |
# Use RAG to find similar course structures
|
| 142 |
similar_courses = self.vector_store.similarity_search(
|
| 143 |
f"{state['topic']} {state['difficulty']} course",
|
| 144 |
k=2
|
| 145 |
)
|
| 146 |
context = "\n".join([doc.page_content for doc in similar_courses])
|
| 147 |
-
|
| 148 |
prompt = self.prompts.course_planning_prompt()
|
| 149 |
response = await self.llm.apredict(
|
| 150 |
prompt.format(
|
|
@@ -153,23 +154,28 @@ class CourseBuilder:
|
|
| 153 |
context=context
|
| 154 |
)
|
| 155 |
)
|
| 156 |
-
|
| 157 |
# Index the course plan for future reference
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
except Exception as e:
|
| 165 |
-
st.session_state.agent_logs.append(f"⚠️ Warning: Couldn't index course plan: {str(e)}")
|
| 166 |
-
|
| 167 |
st.session_state.agent_logs.append("✅ Course structure planned")
|
| 168 |
return {
|
| 169 |
**state,
|
| 170 |
"messages": [AIMessage(content=response)],
|
| 171 |
"status": "planning_complete"
|
| 172 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
|
| 174 |
async def create_content(self, state: CourseState) -> CourseState:
|
| 175 |
"""Content creator agent using RAG"""
|
|
|
|
| 135 |
self.setup_graph()
|
| 136 |
|
| 137 |
async def plan_course(self, state: CourseState) -> CourseState:
|
| 138 |
+
"""Planner agent for course structure"""
|
| 139 |
+
st.session_state.agent_logs.append("📋 Planning course structure...")
|
| 140 |
+
|
| 141 |
+
try:
|
| 142 |
# Use RAG to find similar course structures
|
| 143 |
similar_courses = self.vector_store.similarity_search(
|
| 144 |
f"{state['topic']} {state['difficulty']} course",
|
| 145 |
k=2
|
| 146 |
)
|
| 147 |
context = "\n".join([doc.page_content for doc in similar_courses])
|
| 148 |
+
|
| 149 |
prompt = self.prompts.course_planning_prompt()
|
| 150 |
response = await self.llm.apredict(
|
| 151 |
prompt.format(
|
|
|
|
| 154 |
context=context
|
| 155 |
)
|
| 156 |
)
|
| 157 |
+
|
| 158 |
# Index the course plan for future reference
|
| 159 |
+
course_plan = json.loads(response)
|
| 160 |
+
self.vector_store.add_texts(
|
| 161 |
+
[json.dumps(course_plan)],
|
| 162 |
+
metadatas=[{"type": "course_plan", "topic": state["topic"]}]
|
| 163 |
+
)
|
| 164 |
+
|
|
|
|
|
|
|
|
|
|
| 165 |
st.session_state.agent_logs.append("✅ Course structure planned")
|
| 166 |
return {
|
| 167 |
**state,
|
| 168 |
"messages": [AIMessage(content=response)],
|
| 169 |
"status": "planning_complete"
|
| 170 |
}
|
| 171 |
+
except Exception as e:
|
| 172 |
+
error_message = f"Course creation error: {str(e)}"
|
| 173 |
+
st.session_state.agent_logs.append(error_message)
|
| 174 |
+
return {
|
| 175 |
+
**state,
|
| 176 |
+
"messages": [AIMessage(content=error_message)],
|
| 177 |
+
"status": "planning_failed"
|
| 178 |
+
}
|
| 179 |
|
| 180 |
async def create_content(self, state: CourseState) -> CourseState:
|
| 181 |
"""Content creator agent using RAG"""
|