-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de1718b
commit a8a2a34
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from openai import OpenAI | ||
import numpy as np | ||
import time | ||
|
||
# API key | ||
file = open("openai.secret") | ||
key = file.readline().strip() | ||
client = OpenAI(api_key=key) | ||
file.close() | ||
|
||
# Load the .npy training file | ||
file_path = 'WP-train.npy' | ||
data = np.load(file_path, allow_pickle=True) | ||
|
||
# | ||
count = 0 | ||
correct = 0 | ||
for item in data: | ||
count += 1 | ||
# API is rate limited - batch mode could be used | ||
time.sleep(0.1) | ||
response = client.chat.completions.create( | ||
model="gpt-4o-mini", | ||
messages=[ | ||
{"role": "system", "content": "Answer the multiple choice question by returning only the correct answer by itself. The answer is almost never None of the above."}, | ||
{ | ||
"role": "user", | ||
"content": item["question"] + " Select One: " + str(item["choice_list"]) | ||
} | ||
] | ||
) | ||
guess = response.choices[0].message.content | ||
print("GUESS:",guess,"ANSWER:",item["answer"]) | ||
if guess == item["answer"]: | ||
correct += 1 | ||
|
||
print(correct/count) | ||
|