| from typing import Any, List, Optional, Literal |
| from app.services.ai_provider import BaseAIProvider |
| from app.schemas.intelligence import ( |
| DiagnosticQuiz, |
| DiagnosticResultResponse, |
| WhatToStudyResponse, |
| StudyPathResponse, |
| ExamIntelligenceResponse, |
| VideoPlanResponse |
| ) |
|
|
| class ExamIntelligenceBrain: |
| def __init__(self, provider: BaseAIProvider): |
| self.provider = provider |
|
|
| def generate_diagnostic_quiz( |
| self, |
| context: str, |
| document_id: str, |
| language: str = "English" |
| ) -> dict[str, Any]: |
| task = ( |
| "Generate a diagnostic study quiz with 5-7 questions to assess a student's level. " |
| "Questions must cover: concept understanding, memory (definitions), diagram recall, " |
| "answer writing logic, and problem solving. Each question must have 4 options. " |
| "Assign a category to each question from: concept, memory, diagram, answer_writing, problem_solving." |
| ) |
| return self.provider.generate_json( |
| task=task, |
| context=context, |
| language=language, |
| metadata={"document_id": document_id}, |
| response_schema=DiagnosticQuiz, |
| ) |
|
|
| def analyze_diagnostic_results( |
| self, |
| results: dict[str, Any], |
| language: str = "English" |
| ) -> dict[str, Any]: |
| |
| |
| task = ( |
| "Analyze the following student diagnostic quiz results and classify their level. " |
| "Calculate their accuracy per category (concept, memory, etc.) and identify specific weaknesses. " |
| "Determine if they are 'beginner', 'intermediate', or 'advanced'. " |
| "Explain why in the 'analysis' field." |
| ) |
| return self.provider.generate_json( |
| task=task, |
| context=f"Results: {results}", |
| language=language, |
| response_schema=DiagnosticResultResponse, |
| ) |
|
|
| def generate_what_to_study( |
| self, |
| context: str, |
| student_level: str, |
| goal: str, |
| pyq_context: Optional[str] = None, |
| language: str = "English" |
| ) -> dict[str, Any]: |
| task = ( |
| f"As an Exam Intelligence Brain, determine what a {student_level} student aiming for '{goal}' should study. " |
| "Categorize topics into: must study, high weightage, repeated PYQ topics, low priority, and skip for now. " |
| "Identify 'easy marks' (simple but high value) and 'danger areas' (frequent mistake spots). " |
| "Provide a logical 'study_order'. " |
| "For every topic, include a 'reason' explaining if it is based on the source, syllabus, or PYQ. " |
| f"Available PYQ data: {pyq_context or 'Not available yet'}. " |
| "If PYQ data is missing, prioritize based on source structure and typical board patterns." |
| ) |
| return self.provider.generate_json( |
| task=task, |
| context=context, |
| language=language, |
| response_schema=WhatToStudyResponse, |
| ) |
|
|
| def generate_study_path( |
| self, |
| context: str, |
| plan_type: str, |
| student_level: str, |
| goal: str, |
| language: str = "English" |
| ) -> dict[str, Any]: |
| task = ( |
| f"Create a high-density personal study path for a {plan_type} timeframe. " |
| f"Target: {goal} for a {student_level} student. " |
| "Break the plan into logical time blocks. Each block must have: " |
| "time_block, topic, reason, task, output_expected, and revision_checkpoint. " |
| "The plan must be realistic for the given time (1h, 3h, 5h, 7d, or 30d)." |
| ) |
| return self.provider.generate_json( |
| task=task, |
| context=context, |
| language=language, |
| response_schema=StudyPathResponse, |
| ) |
|
|
| def generate_exam_intelligence( |
| self, |
| context: str, |
| chapter_name: str, |
| language: str = "English" |
| ) -> dict[str, Any]: |
| task = ( |
| f"Generate deep exam intelligence for the chapter: {chapter_name}. " |
| "Include topic importance, PYQ patterns, likely question types, and " |
| "mark-wise structured answers (1, 2, 4, 6 marks). " |
| "List common mistakes and keywords that must be underlined in the exam." |
| ) |
| return self.provider.generate_json( |
| task=task, |
| context=context, |
| language=language, |
| response_schema=ExamIntelligenceResponse, |
| ) |
|
|
| def generate_extended_video_plan( |
| self, |
| context: str, |
| title: str, |
| duration_type: str, |
| style: str, |
| language: str = "English" |
| ) -> dict[str, Any]: |
| task = ( |
| f"Create an extended video teaching plan for '{title}'. " |
| f"Duration category: {duration_type}. Style: {style}. " |
| "The plan must include: hook, real-life analogy, simple explanation, official terms, " |
| "visual suggestions for every scene, PYQ connection, exam answer format, common mistakes, " |
| "a 3-question mini-quiz, and a final recap." |
| ) |
| return self.provider.generate_json( |
| task=task, |
| context=context, |
| language=language, |
| response_schema=VideoPlanResponse, |
| ) |
|
|