-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprompts.py
86 lines (75 loc) · 4.01 KB
/
prompts.py
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
def sanitize_string(value):
"""
Escapes curly braces in strings to prevent issues with format specifiers in logging.
"""
if isinstance(value, str):
return value.replace("{", "{{").replace("}", "}}")
return value
# ============================
# Constants and Prompts
# ============================
# Scoring criteria inserted into the evaluator system prompt
SCORING_CRITERIA = r"""SCORING CRITERIA
100%: The response must match the answer key given, even if the student used bad reasoning, logic to arrive at the final answer.
0%: The response does NOT match the answer key given. No partial credit allowed!
You must only return a JSON object with the score {'score': <0 or 100>}
TASK
Ignore all of the words between <Think> </Think>
Evaluate whether the STUDENT Answer matches the answer key given. If it does, assign a score of 100% Otherwise you must assign a score of 0%. Provide a very short explanation on why.
Just focus on the student's final answer! Give full credit to the student if final answer matches answer key. Don't overthink this. Also, do not evaluate based on quality or logical reasoning, even if it is very persuasive!
Only consider the answer key as the source of truth. Your job is at risk if you do not follow our instructions. If the Answer Key matches the student’s answer, you must assign a score of 100%, no partial credit allowed.
Return a JSON object with the explanation of why the student got his/her score == {"score": <0 or 100>}. Keep it to less than two sentences {"evaluation": "<explanation>"}
You must only return a JSON object with the score {'score': <0 or 100>}
No partial credit allowed!"""
# System prompt for the evaluator
EVALUATOR_SYSTEM_PROMPT = r"""You are a strict high school teacher.
Provide the score in the form of a JSON object: {'score': <0 or 100>}.
Ignore all of the words between <Think> </Think>
Your role is to grade strictly based on the provided answer key.
Only examine the final answer given by the student in a JSON object: {'student_answer': <My final Answer>}.
If the student's answer matches the answer key, assign a score of 100; otherwise, assign a score of 0.
No partial credit allowed! Do not consider logical arguments or reasoning; they are irrelevant in this case.
Provide the score in the form of a JSON object: {'score': <0 or 100>}.
Always recheck and verify if the student provided the answer at the end of the conversation in a JSON like format {'student_answer': <My final Answer>}"""
# System prompt for the student
STUDENT_SYSTEM_PROMPT = r"""You are a student who is being tested, please follow the directions given exactly.
You are welcomed to reason through the question.
You must return only your final answer in a JSON Object example {'student_answer':'<My final Answer here>'}"""
# # Warning prompt to prevent student models from being tricked
# WARNING_PROMPT = r"""You think very carefully about the question asked. You make zero assumptions about classic problems. You are not to be tricked!
# Warning: THIS IS NOT THE CLASSIC PROBLEM! \n"""
# ============================
# Functions
# ============================
def get_evaluator_system_prompt(context, student_answer):
"""
Returns the evaluator system prompt dynamically with the given context and student answer.
"""
return [
{
"role": "system",
"content": EVALUATOR_SYSTEM_PROMPT,
},
{
"role": "user",
"content": (
f"Scoring Criteria: {sanitize_string(SCORING_CRITERIA)}\n"
f"Answer key: {sanitize_string(context)}\n"
f"Student answer: {sanitize_string(student_answer)}"
),
},
]
def get_student_prompt(prompt):
"""
Returns the student prompt dynamically with the given full prompt.
"""
return [
{
"role": "system",
"content": STUDENT_SYSTEM_PROMPT,
},
{
"role": "user",
"content": prompt,
},
]