-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevaluate.py
More file actions
99 lines (91 loc) · 3.34 KB
/
evaluate.py
File metadata and controls
99 lines (91 loc) · 3.34 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
from openai import OpenAI
with open("API_KEY", "r") as f:
API_KEY = f.read().strip()
client = OpenAI(api_key=API_KEY)
def grade_text(text, solution_text):
try:
prompt = (
"Grade the following assignment based on provided solution guidelines:\n\n"
f"Assignment Text:\n{text}\n\n"
f"Solution Text:\n{solution_text}\n\n"
"Has this student passed or failed the assignment?"
)
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{
"role": "system",
"content": [
{
"type": "text",
"text": "You will be grading assignments in the university course \"Introduction to Algorithms\". The students need to do an honest effort in order to pass the assignment. Their answers do not necessarily need to be correct. I will give you their submissions and the suggested solution, and you will reply with \"passed\" or \"failed\". "
}
]
},
{
"role": "user",
"content": [
{
"type": "text",
"text": prompt
}
]
}
],
temperature=0.2,
max_tokens=1000,
top_p=1,
frequency_penalty=0,
presence_penalty=0,
response_format={
"type": "text"
}
)
# print("Grading completed successfully.")
return response.choices[0].message.content.strip()
except Exception as e:
print(f"Error in grading submission: {e}")
return None
def grade_code(code, solution_code):
try:
prompt = (
"Grade the following assignment based on provided solution guidelines:\n\n"
f"Assignment Code:\n{code}\n\n"
f"Solution Code:\n{solution_code}\n\n"
"Has this student passed or failed the assignment?"
)
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{
"role": "system",
"content": [
{
"type": "text",
"text": "You will be grading assignments in the university course \"Introduction to Algorithms\". The students need to do an honest effort in order to pass the assignment. Their answers do not necessarily need to be correct. I will give you their submissions and the suggested solution, and you will reply with \"passed\" or \"failed\". "
}
]
},
{
"role": "user",
"content": [
{
"type": "text",
"text": prompt
}
]
}
],
temperature=0.2,
max_tokens=1000,
top_p=1,
frequency_penalty=0,
presence_penalty=0,
response_format={
"type": "text"
}
)
return response.choices[0].message.content.strip()
except Exception as e:
print(f"Error in grading submission: {e}")
return None