File size: 5,488 Bytes
7c6ffa6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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]:
        # This one might be a simple logic if we want to save tokens, 
        # but let's use the Brain for deeper analysis.
        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,
        )