-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgenerate_theorems.py
66 lines (63 loc) · 2.45 KB
/
generate_theorems.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
import openai
from time import sleep
import csv
import json
import os
import tqdm
def run_prompt(theorem_name: str):
SYSTEMQ = f"Can you describe {theorem_name}?"
got_result = False
while not got_result:
try:
result = openai.ChatCompletion.create(
model='gpt-4-0314',
messages=[{"role": "system", "content": ""},
{"role": "user", "content": SYSTEMQ}],
max_tokens=1028,
temperature=0.0,
top_p=1,
n=1,
)
got_result = True
except Exception as e:
sleep(3)
result = result['choices'][0]['message']['content']
return result
if __name__ == "__main__":
openai.api_key = os.getenv('OPENAI_KEY')
writer = open('theorems.jsonl', 'w')
"""
with open('Math_Theorem.csv', newline='') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
for i, row in tqdm.tqdm(enumerate(reader)):
if i > 0:
theorem_name = row[0].split('(')[0].strip()
output = run_prompt(row[0])
tmp = {'theorem': theorem_name, 'output': output}
writer.write(json.dumps(tmp) + '\n')
"""
with open('EECS_Theorem.csv', newline='') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
for i, row in tqdm.tqdm(enumerate(reader)):
if i > 0:
theorem_name = row[0].split('(')[0].strip()
output = run_prompt(row[0])
tmp = {'theorem': theorem_name, 'output': output}
writer.write(json.dumps(tmp) + '\n')
with open('Physics_Theorem.csv', newline='') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
for i, row in tqdm.tqdm(enumerate(reader)):
if i > 0:
theorem_name = row[0].split('(')[0].strip()
output = run_prompt(row[0])
tmp = {'theorem': theorem_name, 'output': output}
writer.write(json.dumps(tmp) + '\n')
with open('Finance_Theorem.csv', newline='') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
for i, row in tqdm.tqdm(enumerate(reader)):
if i > 0:
theorem_name = row[0].split('(')[0].strip()
output = run_prompt(row[0])
tmp = {'theorem': theorem_name, 'output': output}
writer.write(json.dumps(tmp) + '\n')
writer.close()