feat: AI-powered quiz generation with caching

- Add Quiz model to store generated questions in DB
- Integrate OpenRouter API to generate quiz from lesson content
- Cache quiz results to avoid regenerating on every request
- Extract text from TipTap JSON and send to AI
- Fallback to default questions if AI fails or no API key

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
root
2026-02-06 10:58:15 +00:00
parent bed7e440c1
commit f39680d714
2 changed files with 136 additions and 25 deletions

View File

@ -241,6 +241,7 @@ model Lesson {
// Relations
chapter Chapter @relation(fields: [chapterId], references: [id], onDelete: Cascade)
homework Homework[]
quiz Quiz?
// Vector embedding for semantic search
embedding Unsupported("vector(1536)")?
@ -249,6 +250,18 @@ model Lesson {
@@map("lessons")
}
model Quiz {
id String @id @default(uuid())
lessonId String @unique @map("lesson_id")
questions Json // Array of {id, question, options, correctAnswer}
createdAt DateTime @default(now()) @map("created_at")
lesson Lesson @relation(fields: [lessonId], references: [id], onDelete: Cascade)
@@map("quizzes")
}
// ============================================
// AI Course Generation
// ============================================