-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathprompts.py
More file actions
305 lines (252 loc) · 13.1 KB
/
prompts.py
File metadata and controls
305 lines (252 loc) · 13.1 KB
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
from langchain.prompts import ChatPromptTemplate, PromptTemplate
from langchain.output_parsers import PydanticOutputParser
from models import *
# Derive
DERIVE_PROMPT = ChatPromptTemplate.from_messages([
("system", """You are an expert at creating Socratic questions that help students discover concepts through inductive reasoning."""),
("human", """Given this maximally diverse sample of problems from this unit:
{synthesis}
Create a sequence of 30 questions where each answer should naturally lead to
discovering an important concept. Each question's expected answer should be a clear,
concise statement that could be added to a study guide. Questions should lead to deriving key formulas, theorems, etc.
Do not ask sample questions, but instead ask questions that will help students
derive the concepts. Don't quiz the user on formulas either
All questions should fall into the same 6-8 categories, which signify the question type, spelled identically between questions in the same category.
Return in this exact format:
{{"questions": [
{{"question": "question text",
"expected_answer": "expected response",
"category": "category of the question"}}
]}}""")
])
DERIVE_EVAL_PROMPT = ChatPromptTemplate.from_messages([
("system", """You are an expert at evaluating student responses and guiding them toward understanding.
If their answer shows understanding, accept it as a study guide point.
If not, provide a simpler question to guide them to the concept."""),
("human", """Question: {question}
Expected Answer: {expected}
Student's Answer: {answer}
If the answer demonstrates understanding (even if worded differently), return:
{{"status": "correct",
"newLine": "concise study guide point (under 10 words)"}}
If not, return:
{{"status": "incorrect",
"simplifiedQuestion": "simpler follow-up question"}}""")
])
DERIVE_HELP_PROMPT = """You are an AI tutor guiding a student through a predefined concept derivation trajectory. Use this structured conversation flow:
{trajectory}
Follow these rules:
1. Match the trajectory's logical progression but adapt to student's actual responses
2. Surface key milestones from the trajectory within natural conversation
3. Identify and address deviations from the ideal path using Socratic questioning
4. Use Desmos state to reinforce graphical connections: {desmos_state}
5. Reference these prerequisites when needed: {prerequisites}
Response protocol:
- Begin each message with DERIVED=FALSE until concept mastery is demonstrated
- Final message must start with DERIVED=TRUE followed by concise concept summary
- Keep responses focused - 1-2 sentences maximum unless complex reasoning needed
Current phase requirements:
{concept}
Assessment criteria:
1. Student replicates trajectory's key logical steps
2. Demonstrates understanding of concept relationships
3. Identifies common error patterns
4. Articulates concept in multiple representations (verbal, symbolic, graphical)"""
# Explanation(GuideBuilder)
EXPLANATION_PROMPT = ChatPromptTemplate.from_messages([
("system", "You are an expert tutor trying to explain material in various ways that will reveal what sorts of explanations will make sense to the student. Return only valid JSON without markdown."),
("human", """Diverse sample of example problems from the unit:
{notebook_content}
Create three different explanations that:
1. Start with concepts towards the more challenging end of the material
2. Try both technical and intuitive explanations
3. Differ in style from each other, but are explaining the same concept
4. Use LaTeX for equations
Return in JSON format:
{{"explanations": [
{{"text": "first explanation here", "target": "To explain momentum in terms of force and acceleration"}},
{{"text": "second explanation here", "target": "To explain impulse in terms of momentum"}},
{{"text": "third explanation here", "target": "To explain conservation of momentum in terms of collisions"}}
]}}""")
])
ITERATIVE_EXPLANATION_PROMPT = ChatPromptTemplate.from_messages([
("system", "You are an expert tutor trying to understand how the student perceives the material and explaining in ways that will make sense to them. Return only valid JSON without markdown."),
("human", """explanations that resonate with the student (highlighted in green):
{green_highlights}
explanations that the student found confusing (highlighted in red):
{red_highlights}
Diverse sample of example problems from the unit:
{notebook_content}
Student's request/feedback:
{user_input}
Create three new explanations that build on what they understood and address their feedback.
Return in JSON format:
{{"explanations": [
{{"text": "first explanation here", "target": "Clarify the concept"}},
{{"text": "second explanation here", "target": "Build on related concepts"}},
{{"text": "third explanation here", "target": "Demonstrate applications"}}
]}}""")
])
# Unused
QUESTION_TYPE_PROMPT = ChatPromptTemplate.from_messages([
("system", """You are an expert at creating educational assessments.
Analyze the content and previous answers to determine the most effective
question type for testing understanding."""),
("human", """Content: {content}
Previous Q&A: {previous}
Choose the most appropriate question type from:
- fill_in_blank
- matching
- ordering
- multiple_choice
- equation
Return only the type as a single word.""")
])
# Notebooks
VISION_ANALYSIS_PROMPT = """Analyze this worksheet and provide insights in the following JSON format:
{
"topic": "Main topic of the worksheet (derived from content)",
"notes": ["Key point 1", "Key point 2", ...],
"practice_questions": [
{
"question": "Full question text",
"bloom_level": "Remember|Understand|Apply|Analyze|Create"
}
]
}
For practice questions:
1. Generate at least 10 questions similar to those on the worksheet
2. Vary the Bloom's Taxonomy levels:
- Remember: Recall facts and basic concepts
- Understand: Explain ideas or concepts
- Apply: Use information in new situations
- Analyze: Draw connections among ideas
- Create: Produce new or original work
3. Questions should represent the full range of cognitive levels as appropriate for the worksheet content"""
WORKSHEET_ANSWER_PROMPT = ChatPromptTemplate.from_messages([
("system", "You are an expert tutor helping students understand educational content. Number your steps and use LaTeX for equations."),
("user", """Please answer this question about the worksheet: {question}
data:{file_type};base64,{image_content}""")
])
PROBLEM_MAPPING_PROMPT = ChatPromptTemplate.from_messages([
("system", """You are an expert at analyzing mathematical problems and identifying the concepts they require to solve. You will be given a concept map with nodes containing concepts and their descriptions, and a list of problems. For each problem, identify which concepts from the map are required to solve it."""),
("human", """Given this concept map:
{concept_map}
And these problems:
{problems}
For each problem, identify the concept IDs required to solve it.
Return in this exact JSON format:
{{
"problem_mappings": [
{{
"problem_id": "the problem's ID",
"required_concepts": ["concept_id1", "concept_id2", ...]
}}
]
}}""")
])
# Levels
LEVELS_GENERATE_PROMPT = ChatPromptTemplate.from_messages([
("system", "You are an expert at creating practice questions of varying difficulty levels. Return only valid JSON without markdown."),
("human", """Here is a maximally diverse sample of questions from the unit: {content}
Create 3 {level} level questions ({level} = single step for Rookie, multi-step for Challenger, AP level for Scholar, hard AP level for Master, college level for Samurai).
Previous questions to avoid: {previous}
Return exactly this JSON structure:
{{
"questions": [
{{
"question": "Question text here (use \\\\( \\\\) for LaTeX math)",
"personalDifficulty": 3
}}
]
}}
Requirements:
1. Questions must match the difficulty level description
2. Vary difficulty within the level (1-5 scale)
3. Use LaTeX for math: \\\\(x^2\\\\)
4. Questions should be applied and practical, requiring reasoning and appropriate number of steps for the level""")
])
# Evaluation prompt for student responses
LEVELS_EVAL_PROMPT = PromptTemplate.from_template("""You are an expert tutor evaluating a student's understanding of physics concepts.
Context:
- Problem: {problem}
- Student's Answer: {answer}
- Student's Explanation: {explanation}
- Unit: {unit}
- Attempt Number: {attempt_number}
- Previous Steps: {previous_steps}
Break down the problem into logical steps and evaluate the student's response. For each step:
1. Identify what the student did
2. Determine if it was correct
3. Provide the correct approach if needed
Also identify any remaining steps the student needs to complete.
The score should be a float between 0 and 1 representing overall understanding.
Logical steps should include what the student has attempted, whether correct or not.
Remaining steps should include what they still need to do with helpful hints.
The can_resubmit flag should indicate whether the student should try again.
Format your response as a JSON object with the following structure (DO NOT include any comments in the JSON):
{
"score": 0.5,
"logical_steps": [
{
"step_number": 1,
"description": "What the student did in this step",
"is_correct": true,
"correct_approach": ""
}
],
"remaining_steps": [
{
"step_number": 1,
"description": "What needs to be done",
"hint": "Helpful hint for completing this step"
}
],
"can_resubmit": true
}
Response:""")
# Evaluate
EVALUATE_PROMPT = ChatPromptTemplate.from_messages([
("system", "You are an expert educational assessment designer."),
("human", """Generate {mcq_count} multiple-choice and {written_count} short-response questions
based on these topics: {topics} and examples: {examples}.""")
])
EVALUATE_FOLLOWUP_PROMPT = ChatPromptTemplate.from_messages([
("system", "You are an educational AI conducting a Socratic dialogue."),
("human", "Original question and answer: {qa_pair}\nGenerate a single follow-up question.")
])
EVALUATE_EVAL_PROMPT = ChatPromptTemplate.from_messages([
("system", "You are an expert at evaluating student understanding and providing detailed feedback."),
("human", """Analyze the following conversation history and provide a final evaluation:
{history}
Return this exact JSON structure:
{{
"question_evaluations": [
{{
"understanding_level": "Level of understanding",
"key_points": ["Key point 1", "Key point 2", "..."],
"misconceptions": ["Misconception 1", "Misconception 2", "..."],
"score": integer score
}}
],
"overall_understanding": "Overall understanding level",
"strengths": ["Strength 1", "Strength 2", "..."],
"weaknesses": ["Weakness 1", "Weakness 2", "..."],
"recommendations": ["Recommendation 1", "Recommendation 2", "..."],
"composite_score": integer score,
"predicted_success": "Predicted success level"
}}""")
])
CONCEPT_EXPLANATION_PROMPT = ChatPromptTemplate.from_messages([
("system", """You are an expert at explaining scientific concepts clearly and comprehensively.
Your goal is to provide a complete explanation that helps students deeply understand the concept."""),
("human", """Given this concept:
Concept: {concept_label} - {concept_description}
Provide a complete explanation that:
1. Explains both the what and the why
2. Uses clear examples and analogies
3. Connects to real-world applications
4. Includes historical context when relevant
Return in this exact JSON format:
{{"explanation": "Your complete explanation here"}}""")
])