-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathretest.py
66 lines (55 loc) · 1.84 KB
/
retest.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 json
import os
from run_tests import instructions # Import instructions from run_tests.py
from run_tests import process_prompts # Import the function from run_tests.py
def load_tests():
with open('tests.json', 'r') as f:
data = json.load(f)
return data['tests']
def get_test_key(tests):
print("Available tests:")
for index, test in enumerate(tests):
print(f"{index}: {test['title']}")
try:
test_index = int(input("Enter the index of the test you want to re-run: "))
if test_index < 0 or test_index >= len(tests):
raise ValueError
except ValueError:
print("Invalid test index.")
exit(1)
return tests[test_index]
def get_diff_files():
diff_files = []
while True:
diff_file = input("Enter the name of a .diff file to include (or press Enter to finish): ")
if not diff_file:
break
diff_path = os.path.join('diffs', diff_file)
if not os.path.isfile(diff_path):
print(f"{diff_file} does not exist.")
continue
with open(diff_path, 'r') as f:
diff_files.append(f.read())
return diff_files
def run_test(test, diffs):
system_prompt = instructions
system_prompt.append(
"In previous instances, I had to correct your code. Here are the diffs with comments as to what was incorrect:"
)
for diff in diffs:
system_prompt.append(diff)
execute_test(test, system_prompt)
def execute_test(test, system_prompt):
test_title = test['title']
test_folder = os.path.join('retest', test_title)
os.makedirs(test_folder, exist_ok=True)
prefix = test.get('prefix', '')
for prompt_index, prompt in enumerate(test['prompts'], start=1):
process_prompts(test_folder, system_prompt, prefix, prompt, prompt_index)
def main():
tests = load_tests()
test_key = get_test_key(tests)
diffs = get_diff_files()
run_test(test_key, diffs)
if __name__ == "__main__":
main()