File size: 7,596 Bytes
833dac3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
"""
Prompt Template Module - Stores functions for generating LLM prompts
"""

from typing import Tuple

import few_shots_examples


def generate_decomposition_prompt(question: str, grade: str, subject: str, learning_needs: str) -> Tuple[str, str]:
    """
    Generate prompts for concept decomposition based on user background
    
    Args:
        question: User's question
        grade: Educational grade level
        subject: Subject area
        learning_needs: Specific learning needs/goals
        
    Returns:
        Tuple of (system_prompt, user_prompt)
    """
    system_prompt = """You are an expert educational AI tutor. Your task is to break down complex questions into fundamental concepts that are appropriate for the student's grade level and background knowledge.

Please analyze the question and create a knowledge graph that shows:
1. The main concept being asked about
2. Essential sub-concepts needed to understand the main concept
3. The relationships between these concepts (prerequisite or related)

Consider the student's grade level and subject background when determining:
- Which concepts to include
- How detailed the explanations should be
- The appropriate terminology to use
- The complexity level of relationships

Your response must be in the following JSON format:
{
  "main_concept": "Core concept name",
  "Explanation": "Brief, grade-appropriate explanation of the main concept",
  "sub_concepts": [
    {
      "id": "unique_id",
      "name": "Concept name",
      "description": "Brief, grade-appropriate description",
      "difficulty": "basic|intermediate|advanced"
    }
  ],
  "relationships": [
    {
      "source": "concept_id",
      "target": "concept_id",
      "type": "prerequisite|related",
      "explanation": "Why this relationship exists"
    }
  ]
}"""

    user_prompt = f"""
Break down the concepts needed to understand this question, considering:
1. The student's current grade level and subject knowledge
2. Any specific learning needs mentioned
3. The logical progression of concepts needed
4. Appropriate difficulty levels for each concept

Please ensure all explanations and terminology are appropriate for a {grade} level student.


Here is an example:
Input: "What is Algebra"
OUTPUT: {str(few_shots_examples.CONCEPT_DECOMPOSITION_EXAMPLES_1)}

Input: "What is the relationship between the mean and variance of a normal distribution."
OUTPUT: {str(few_shots_examples.CONCEPT_DECOMPOSITION_EXAMPLES_2)},

Please analyze this question for a {grade} level student studying {subject}.

Question: {question}

Student Background:
- Grade Level: {grade}
- Subject: {subject}
- Learning Needs: {learning_needs if learning_needs else 'Not specified'}

"""

    return system_prompt, user_prompt


def generate_explanation_prompt(concept_name, concept_description, question, grade, subject, learning_needs):
    """
    Generate prompt for concept explanation
    
    Args:
        concept_name: Concept name
        concept_description: Concept description
        question: Original question
        grade: Grade level
        subject: Subject
        learning_needs: Learning needs
        
    Returns:
        Tuple of system prompt and user prompt
    """
    system_prompt = """You are an AI assistant in the educational field, specializing in explaining academic concepts and providing constructive learning resources.
Your task is to deeply explain the specified concept, providing examples, resources, and practice questions.
Your answer must be in valid JSON format, including the following fields:
{
  "explanation": "Detailed concept explanation",
  "examples": [
    {
      "problem": "Example problem",
      "solution": "Step-by-step solution",
      "difficulty": "Difficulty level (Easy/Medium/Hard)"
    },
    ...
  ],
  "resources": [
    {
      "type": "Resource type (Video/Article/Interactive/Book)",
      "title": "Resource title",
      "description": "Resource description",
      "link": "Link (optional)"
    },
    ...
  ],
  "practice_questions": [
    {
      "question": "Practice question",
      "answer": "Answer",
      "difficulty": "Difficulty level (Easy/Medium/Hard)"
    },
    ...
  ]
}
The explanation should be clear, comprehensive, and appropriate for a {grade} level {subject} student's language and difficulty level.
Examples should include 1-3 items, ranging from simple to complex, with step-by-step solutions.
Resources should be diverse, including videos, articles, interactive tools, etc.
Practice questions should include 2-4 items of varying difficulty to help students solidify the concept."""

    user_prompt = f"""Please explain the following concept in detail, considering the student's grade, subject background, and learning needs:

Concept: {concept_name}
Description: {concept_description}
Original Question: {question}
Grade: {grade}
Subject: {subject}
Learning Needs: {learning_needs if learning_needs else "Not specified"}

Please provide a detailed explanation, relevant examples, learning resources, and practice questions, and return JSON in the specified format."""

    return system_prompt, user_prompt


# Prompt template for decomposing concepts
CONCEPT_DECOMPOSITION_PROMPT = """
Based on the user's question and profile information, please break down the question into multiple essential basic concepts, and output the relationships between these concepts in JSON format.

User Profile:
- Grade: {grade}
- Subject: {subject}
- Needs: {needs}

User Question: {question}

Please follow the format below for your response:
```json
{
  "main_concept": "Main concept name",
  "sub_concepts": [
    {
      "id": "concept_1",
      "name": "Concept 1 name", 
      "description": "Brief description of concept 1"
    },
    {
      "id": "concept_2",
      "name": "Concept 2 name",
      "description": "Brief description of concept 2"
    }
    // More concepts...
  ],
  "relationships": [
    {
      "source": "concept_1",
      "target": "concept_2",
      "type": "prerequisite" // Can be "prerequisite" or "related"
    }
    // More relationships...
  ]
}
```

Please ensure the generated JSON is correctly formatted, each concept has a unique ID, and the relationships clearly express the dependencies between concepts.
"""

# Prompt template for generating concept explanations and learning resources
CONCEPT_EXPLANATION_PROMPT = """
Please generate detailed explanations, examples, and learning resource suggestions for the following concept based on the user's profile information.

User Profile:
- Grade: {grade}
- Subject: {subject}
- Needs: {needs}

Selected Concept: {concept_name}
Concept Description: {concept_description}

Please provide your answer in the following format:
```json
{
  "explanation": "Detailed explanation of the concept, appropriate for the user's grade level...",
  "examples": [
    {
      "problem": "Example 1...",
      "solution": "Solution process and answer...",
      "difficulty": "Easy/Medium/Hard"
    },
    // More examples...
  ],
  "resources": [
    {
      "type": "Video/Book/Website",
      "title": "Resource title",
      "description": "Resource description",
      "link": "Link (optional)"
    },
    // More resources...
  ],
  "practice_questions": [
    {
      "question": "Practice question 1...",
      "answer": "Answer...",
      "difficulty": "Easy/Medium/Hard"
    },
    // More practice questions...
  ]
}
```

Please ensure the content is appropriate for the user's grade level, the explanations are easy to understand, and provide valuable learning resources and examples.
"""