Spaces:
Sleeping
Sleeping
github-actions[bot] commited on
Commit ·
dc8caa0
1
Parent(s): 5be0833
🚀 Auto-deploy backend from GitHub (cfdccea)
Browse files- routes/rag_routes.py +30 -7
routes/rag_routes.py
CHANGED
|
@@ -206,15 +206,33 @@ def _ensure_7_sections(lesson_data: dict, lesson_title: str) -> dict:
|
|
| 206 |
required = ["introduction", "key_concepts", "video", "worked_examples", "important_notes", "try_it_yourself", "summary"]
|
| 207 |
|
| 208 |
default_content = {
|
| 209 |
-
"introduction": {"type": "introduction", "title": "Introduction", "content": f"Welcome to the lesson on {lesson_title}."},
|
| 210 |
-
"key_concepts": {"type": "key_concepts", "title": "Key Concepts", "content": "
|
| 211 |
-
"video": {"type": "video", "title": "Video Lesson", "content": "Watch
|
| 212 |
-
"worked_examples": {"type": "worked_examples", "title": "Worked Examples", "examples": []},
|
| 213 |
-
"important_notes": {"type": "important_notes", "title": "Important Notes", "bulletPoints": []},
|
| 214 |
-
"try_it_yourself": {"type": "try_it_yourself", "title": "Try It Yourself", "practiceProblems": []},
|
| 215 |
-
"summary": {"type": "summary", "title": "Summary", "content": f"
|
| 216 |
}
|
| 217 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
filled = {}
|
| 219 |
for req_type in required:
|
| 220 |
for existing in sections:
|
|
@@ -224,6 +242,11 @@ def _ensure_7_sections(lesson_data: dict, lesson_title: str) -> dict:
|
|
| 224 |
else:
|
| 225 |
filled[req_type] = default_content[req_type]
|
| 226 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
ordered = [filled[t] for t in required]
|
| 228 |
|
| 229 |
for i, section in enumerate(ordered):
|
|
|
|
| 206 |
required = ["introduction", "key_concepts", "video", "worked_examples", "important_notes", "try_it_yourself", "summary"]
|
| 207 |
|
| 208 |
default_content = {
|
| 209 |
+
"introduction": {"type": "introduction", "title": "Introduction", "content": f"Welcome to the lesson on {lesson_title}. This topic builds foundational skills for your mathematics journey."},
|
| 210 |
+
"key_concepts": {"type": "key_concepts", "title": "Key Concepts", "content": f"The following key concepts are essential for mastering {lesson_title}:", "callouts": [{"type": "important", "text": "Review the curriculum PDF for detailed explanations of each concept."}]},
|
| 211 |
+
"video": {"type": "video", "title": "Video Lesson", "content": "Watch the video explanation below to understand the concepts visually.", "videoId": "", "videoTitle": "", "videoChannel": "", "embedUrl": "", "thumbnailUrl": ""},
|
| 212 |
+
"worked_examples": {"type": "worked_examples", "title": "Worked Examples", "examples": [{"problem": f"Sample problem for {lesson_title}", "steps": ["Step 1: Identify the given information.", "Step 2: Apply the appropriate formula or method.", "Step 3: Solve step-by-step.", "Step 4: Verify your answer."], "answer": "Solution will vary based on specific problem parameters."}]},
|
| 213 |
+
"important_notes": {"type": "important_notes", "title": "Important Notes", "bulletPoints": [f"Always read problems carefully before solving {lesson_title} questions.", "Check your units and ensure consistency throughout calculations.", "Practice regularly to build fluency with these concepts."]},
|
| 214 |
+
"try_it_yourself": {"type": "try_it_yourself", "title": "Try It Yourself", "practiceProblems": [{"question": f"Practice applying {lesson_title} concepts. Solve a similar problem from your textbook or worksheets.", "solution": "Compare your solution with the worked examples above. If stuck, re-read the key concepts section or ask your teacher for guidance."}]},
|
| 215 |
+
"summary": {"type": "summary", "title": "Summary", "content": f"In this lesson on {lesson_title}, you explored key concepts, worked through examples, and practiced problem-solving techniques. Continue reviewing these materials and seek additional practice to strengthen your understanding."},
|
| 216 |
}
|
| 217 |
|
| 218 |
+
def _is_section_blank(section: dict, s_type: str) -> bool:
|
| 219 |
+
"""Check if a section has effectively no content."""
|
| 220 |
+
if not section:
|
| 221 |
+
return True
|
| 222 |
+
text_content = (section.get("content") or "").strip()
|
| 223 |
+
if s_type in ("introduction", "key_concepts", "video", "summary"):
|
| 224 |
+
return len(text_content) < 10
|
| 225 |
+
if s_type == "worked_examples":
|
| 226 |
+
examples = section.get("examples") or []
|
| 227 |
+
return not examples or all(not (ex.get("problem") or "").strip() for ex in examples)
|
| 228 |
+
if s_type == "important_notes":
|
| 229 |
+
bullets = section.get("bulletPoints") or []
|
| 230 |
+
return not bullets or all(not (b or "").strip() for b in bullets)
|
| 231 |
+
if s_type == "try_it_yourself":
|
| 232 |
+
problems = section.get("practiceProblems") or []
|
| 233 |
+
return not problems or all(not (p.get("question") or "").strip() for p in problems)
|
| 234 |
+
return False
|
| 235 |
+
|
| 236 |
filled = {}
|
| 237 |
for req_type in required:
|
| 238 |
for existing in sections:
|
|
|
|
| 242 |
else:
|
| 243 |
filled[req_type] = default_content[req_type]
|
| 244 |
|
| 245 |
+
# Validate and replace blank sections with defaults
|
| 246 |
+
for req_type in required:
|
| 247 |
+
if _is_section_blank(filled[req_type], req_type):
|
| 248 |
+
filled[req_type] = default_content[req_type]
|
| 249 |
+
|
| 250 |
ordered = [filled[t] for t in required]
|
| 251 |
|
| 252 |
for i, section in enumerate(ordered):
|