rairo commited on
Commit
8b5827f
·
verified ·
1 Parent(s): c2c640c

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +9 -3
main.py CHANGED
@@ -674,6 +674,7 @@ def _generate_ai_questions(subject_name, topic_name, num_questions):
674
  AI fallback: generate questions on the fly when bank is empty.
675
  Returns list of question docs (not stored unless you decide to).
676
  """
 
677
  prompt = f"""
678
  You are a Zimbabwean exam coach preparing practice questions.
679
 
@@ -691,11 +692,16 @@ Each question must have:
691
  - difficulty: "easy", "medium", or "hard"
692
 
693
  Return a JSON object:
694
- {"questions": [ ... ]}
695
  """
696
- raw = send_gemini_text(prompt)
 
 
 
697
  try:
698
- data = json.loads(raw)
 
 
699
  return data.get("questions", [])
700
  except Exception:
701
  logger.error("Failed to parse AI-generated questions, raw response:")
 
674
  AI fallback: generate questions on the fly when bank is empty.
675
  Returns list of question docs (not stored unless you decide to).
676
  """
677
+ # FIX: Double curly braces {{ }} used for the JSON example so Python doesn't crash.
678
  prompt = f"""
679
  You are a Zimbabwean exam coach preparing practice questions.
680
 
 
692
  - difficulty: "easy", "medium", or "hard"
693
 
694
  Return a JSON object:
695
+ {{ "questions": [ ... ] }}
696
  """
697
+ # FIX: Added json_mode=True (if you implemented the helper in the previous step)
698
+ # OR simple text generation:
699
+ raw = send_gemini_text(prompt)
700
+
701
  try:
702
+ # FIX: Clean markdown before parsing
703
+ raw_clean = raw.replace("```json", "").replace("```", "").strip()
704
+ data = json.loads(raw_clean)
705
  return data.get("questions", [])
706
  except Exception:
707
  logger.error("Failed to parse AI-generated questions, raw response:")