""" One-off script: clear AI trio for COMP2711H paper and regenerate with LaTeX-enforced prompt. Run inside the backend Docker container or locally with .env loaded. """ import asyncio import json import sys import os sys.path.insert(0, os.path.dirname(__file__)) from dotenv import load_dotenv load_dotenv(os.path.join(os.path.dirname(__file__), "..", ".env")) from app.services.supabase_client import get_supabase from app.services.paper_processor import _resume_ai_trio PAPER_ID = "5ee87a62-65bf-4952-be40-fcdf9ba7ca63" # COMP2711H 2025 fall final async def main(): sb = get_supabase() # 1. Clear existing AI trio fields so _resume_ai_trio will regenerate them questions = sb.table("paper_questions").select("id, question_number, solution").eq("paper_id", PAPER_ID).execute().data print(f"Found {len(questions)} questions for paper {PAPER_ID[:8]}") cleared = 0 for q in questions: if q.get("solution"): sb.table("paper_questions").update({ "knowledge_reminder": "", "ai_hint": "", "solution": "", }).eq("id", q["id"]).execute() cleared += 1 q["solution"] = None # so _resume_ai_trio picks it up print(f"Cleared AI trio for {cleared} questions. Regenerating...") # 2. Regenerate await _resume_ai_trio(sb, PAPER_ID, questions) print("Done! AI trio regenerated with LaTeX-enforced prompt.") if __name__ == "__main__": asyncio.run(main())