Spaces:
Sleeping
Sleeping
Update learning_platform.py
Browse files- learning_platform.py +33 -21
learning_platform.py
CHANGED
|
@@ -45,6 +45,8 @@ Requirements:
|
|
| 45 |
3. Practical applications
|
| 46 |
4. Real-world examples
|
| 47 |
5. A compelling description that excites the learner about the journey ahead
|
|
|
|
|
|
|
| 48 |
"""
|
| 49 |
|
| 50 |
@staticmethod
|
|
@@ -59,6 +61,7 @@ Include:
|
|
| 59 |
3. Key points that summarize each section concisely
|
| 60 |
4. A set of 3-5 quiz questions for each section, with answers and explanations
|
| 61 |
5. Encourage learners to think critically and ask questions related to '{title}'
|
|
|
|
| 62 |
"""
|
| 63 |
|
| 64 |
@staticmethod
|
|
@@ -85,7 +88,7 @@ class CourseBuilder:
|
|
| 85 |
)
|
| 86 |
self.prompts = CoursePrompts()
|
| 87 |
|
| 88 |
-
async def plan_course(self, topic: str, difficulty: str) ->
|
| 89 |
prompt = self.prompts.course_planning_prompt().format(topic=topic, difficulty=difficulty)
|
| 90 |
response = await self.llm.apredict(prompt)
|
| 91 |
|
|
@@ -100,13 +103,39 @@ class CourseBuilder:
|
|
| 100 |
except json.JSONDecodeError as e:
|
| 101 |
raise ValueError(f"Invalid JSON response from API: {str(e)}\nResponse: {response}")
|
| 102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
# Store embeddings for course plan for future reference
|
| 104 |
self.vector_store.add_texts(
|
| 105 |
[json.dumps(course_plan)],
|
| 106 |
metadatas=[{"type": "course_plan", "topic": topic}]
|
| 107 |
)
|
| 108 |
|
| 109 |
-
return
|
| 110 |
|
| 111 |
async def create_module_content(self, module: CourseModule) -> List[Section]:
|
| 112 |
prompt = self.prompts.module_content_prompt().format(
|
|
@@ -154,25 +183,8 @@ class LearningPlatform:
|
|
| 154 |
|
| 155 |
async def create_course(self, topic: str, difficulty: str) -> LearningPath:
|
| 156 |
try:
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
modules = [
|
| 160 |
-
CourseModule(
|
| 161 |
-
title=module["title"],
|
| 162 |
-
objectives=module["objectives"],
|
| 163 |
-
prerequisites=module.get("prerequisites", [])
|
| 164 |
-
) for module in course_plan.get("modules", [])
|
| 165 |
-
]
|
| 166 |
-
|
| 167 |
-
return LearningPath(
|
| 168 |
-
topic=topic,
|
| 169 |
-
description=course_plan.get("description", ""),
|
| 170 |
-
modules=modules,
|
| 171 |
-
difficulty_level=difficulty,
|
| 172 |
-
created_at=datetime.now(),
|
| 173 |
-
is_generating=False
|
| 174 |
-
)
|
| 175 |
-
|
| 176 |
except Exception as e:
|
| 177 |
raise Exception(f"Course creation error: {str(e)}")
|
| 178 |
|
|
|
|
| 45 |
3. Practical applications
|
| 46 |
4. Real-world examples
|
| 47 |
5. A compelling description that excites the learner about the journey ahead
|
| 48 |
+
6. Each module should contain content, quiz questions, and be designed to progressively enhance understanding.
|
| 49 |
+
Return a structured JSON with detailed content for each module.
|
| 50 |
"""
|
| 51 |
|
| 52 |
@staticmethod
|
|
|
|
| 61 |
3. Key points that summarize each section concisely
|
| 62 |
4. A set of 3-5 quiz questions for each section, with answers and explanations
|
| 63 |
5. Encourage learners to think critically and ask questions related to '{title}'
|
| 64 |
+
Return a structured JSON with detailed content for each section.
|
| 65 |
"""
|
| 66 |
|
| 67 |
@staticmethod
|
|
|
|
| 88 |
)
|
| 89 |
self.prompts = CoursePrompts()
|
| 90 |
|
| 91 |
+
async def plan_course(self, topic: str, difficulty: str) -> LearningPath:
|
| 92 |
prompt = self.prompts.course_planning_prompt().format(topic=topic, difficulty=difficulty)
|
| 93 |
response = await self.llm.apredict(prompt)
|
| 94 |
|
|
|
|
| 103 |
except json.JSONDecodeError as e:
|
| 104 |
raise ValueError(f"Invalid JSON response from API: {str(e)}\nResponse: {response}")
|
| 105 |
|
| 106 |
+
modules = [
|
| 107 |
+
CourseModule(
|
| 108 |
+
title=module["title"],
|
| 109 |
+
objectives=module["objectives"],
|
| 110 |
+
prerequisites=module.get("prerequisites", []),
|
| 111 |
+
sections=[
|
| 112 |
+
Section(
|
| 113 |
+
title=section["title"],
|
| 114 |
+
content=section["content"],
|
| 115 |
+
key_points=section.get("key_points", []),
|
| 116 |
+
examples=section.get("examples", []),
|
| 117 |
+
quiz_questions=section.get("quiz_questions", [])
|
| 118 |
+
) for section in module.get("sections", [])
|
| 119 |
+
]
|
| 120 |
+
) for module in course_plan.get("modules", [])
|
| 121 |
+
]
|
| 122 |
+
|
| 123 |
+
learning_path = LearningPath(
|
| 124 |
+
topic=topic,
|
| 125 |
+
description=course_plan.get("description", ""),
|
| 126 |
+
modules=modules,
|
| 127 |
+
difficulty_level=difficulty,
|
| 128 |
+
created_at=datetime.now(),
|
| 129 |
+
is_generating=False
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
# Store embeddings for course plan for future reference
|
| 133 |
self.vector_store.add_texts(
|
| 134 |
[json.dumps(course_plan)],
|
| 135 |
metadatas=[{"type": "course_plan", "topic": topic}]
|
| 136 |
)
|
| 137 |
|
| 138 |
+
return learning_path
|
| 139 |
|
| 140 |
async def create_module_content(self, module: CourseModule) -> List[Section]:
|
| 141 |
prompt = self.prompts.module_content_prompt().format(
|
|
|
|
| 183 |
|
| 184 |
async def create_course(self, topic: str, difficulty: str) -> LearningPath:
|
| 185 |
try:
|
| 186 |
+
learning_path = await self.course_builder.plan_course(topic, difficulty)
|
| 187 |
+
return learning_path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
except Exception as e:
|
| 189 |
raise Exception(f"Course creation error: {str(e)}")
|
| 190 |
|