Spaces:
Running
Running
github-actions[bot] commited on
Commit ·
4e17ba7
1
Parent(s): 8e2e5f4
🚀 Auto-deploy backend from GitHub (10a837d)
Browse files
routes/quiz_generation_routes.py
CHANGED
|
@@ -282,6 +282,12 @@ async def generate_quiz(request: QuizGenerationRequest):
|
|
| 282 |
detail=f"No curriculum content found for topic '{request.topic}'. Please ensure PDFs are ingested.",
|
| 283 |
)
|
| 284 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 285 |
# Format retrieved chunks for the prompt
|
| 286 |
formatted_context = "\n\n---\n\n".join(
|
| 287 |
f"[Source: {chunk.get('metadata', {}).get('source_file', 'Unknown')}, Page {chunk.get('metadata', {}).get('page', 'N/A')}]\n{chunk.get('document', '')}"
|
|
|
|
| 282 |
detail=f"No curriculum content found for topic '{request.topic}'. Please ensure PDFs are ingested.",
|
| 283 |
)
|
| 284 |
|
| 285 |
+
# Shuffle retrieved chunks for variance BEFORE formatting prompt context
|
| 286 |
+
# This ensures different lessons → different curriculum context → different generated questions
|
| 287 |
+
seed = request.varianceSeed if request.varianceSeed else hash(f"{request.topic}:{request.subject}:{request.lessonTitle or ''}:{request.userId or 'anon'}") % (2**32)
|
| 288 |
+
rng = random.Random(seed)
|
| 289 |
+
rng.shuffle(chunks) # In-place shuffle for deterministic variety per seed
|
| 290 |
+
|
| 291 |
# Format retrieved chunks for the prompt
|
| 292 |
formatted_context = "\n\n---\n\n".join(
|
| 293 |
f"[Source: {chunk.get('metadata', {}).get('source_file', 'Unknown')}, Page {chunk.get('metadata', {}).get('page', 'N/A')}]\n{chunk.get('document', '')}"
|
scripts/ingest_from_storage.py
CHANGED
|
@@ -15,7 +15,7 @@ logger = logging.getLogger("mathpulse.ingest")
|
|
| 15 |
|
| 16 |
sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
|
| 17 |
|
| 18 |
-
from
|
| 19 |
PDF_METADATA,
|
| 20 |
download_pdf_from_storage,
|
| 21 |
list_curriculum_blobs,
|
|
|
|
| 15 |
|
| 16 |
sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
|
| 17 |
|
| 18 |
+
from rag.firebase_storage_loader import (
|
| 19 |
PDF_METADATA,
|
| 20 |
download_pdf_from_storage,
|
| 21 |
list_curriculum_blobs,
|