Skip to content

Commit 4dd0e5b

Browse files
Adjusting to accommodate the retesting architecture
1 parent 85c70fc commit 4dd0e5b

File tree

2 files changed

+85
-14
lines changed

2 files changed

+85
-14
lines changed

retest.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import json
2+
import os
3+
4+
from run_tests import instructions # Import instructions from run_tests.py
5+
from run_tests import process_prompts # Import the function from run_tests.py
6+
7+
def load_tests():
8+
with open('tests.json', 'r') as f:
9+
data = json.load(f)
10+
return data['tests']
11+
12+
def get_test_key(tests):
13+
print("Available tests:")
14+
for index, test in enumerate(tests):
15+
print(f"{index}: {test['title']}")
16+
try:
17+
test_index = int(input("Enter the index of the test you want to re-run: "))
18+
if test_index < 0 or test_index >= len(tests):
19+
raise ValueError
20+
except ValueError:
21+
print("Invalid test index.")
22+
exit(1)
23+
return tests[test_index]
24+
25+
def get_diff_files():
26+
diff_files = []
27+
while True:
28+
diff_file = input("Enter the name of a .diff file to include (or press Enter to finish): ")
29+
if not diff_file:
30+
break
31+
diff_path = os.path.join('diffs', diff_file)
32+
if not os.path.isfile(diff_path):
33+
print(f"{diff_file} does not exist.")
34+
continue
35+
with open(diff_path, 'r') as f:
36+
diff_files.append(f.read())
37+
return diff_files
38+
39+
def run_test(test, diffs):
40+
system_prompt = instructions
41+
system_prompt.append(
42+
"In previous instances, I had to correct your code. Here are the diffs with comments as to what was incorrect:"
43+
)
44+
for diff in diffs:
45+
system_prompt.append(diff)
46+
execute_test(test, system_prompt)
47+
48+
49+
def execute_test(test, system_prompt):
50+
test_title = test['title']
51+
test_folder = os.path.join('retest', test_title)
52+
os.makedirs(test_folder, exist_ok=True)
53+
54+
prefix = test.get('prefix', '')
55+
56+
for prompt_index, prompt in enumerate(test['prompts'], start=1):
57+
process_prompts(test_folder, system_prompt, prefix, prompt, prompt_index)
58+
59+
def main():
60+
tests = load_tests()
61+
test_key = get_test_key(tests)
62+
diffs = get_diff_files()
63+
run_test(test_key, diffs)
64+
65+
if __name__ == "__main__":
66+
main()

run_tests.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,24 @@ def get_code_response(prompt):
6868
print(f"Response: {code}")
6969
return code
7070

71+
def process_prompts(test_folder, system_prompt, prefix, prompt, prompt_index):
72+
prompt_folder = os.path.join(test_folder, str(prompt_index))
73+
os.makedirs(prompt_folder, exist_ok=True)
74+
75+
unique_responses = set()
76+
77+
for _ in range(ITERATIONS):
78+
full_prompt = f"{prefix} {prompt}".strip()
79+
response = get_code_response(system_prompt, full_prompt)
80+
if response not in unique_responses:
81+
unique_responses.add(response)
82+
filename = os.path.join(prompt_folder, f"{uuid.uuid4()}.html")
83+
with open(filename, 'w') as response_file:
84+
response_file.write(response)
85+
time.sleep(SLEEP) # To avoid hitting rate limits
86+
87+
88+
7189
def main():
7290
# Load the JSON file
7391
with open('tests.json', 'r') as file:
@@ -81,20 +99,7 @@ def main():
8199
prefix = test.get('prefix', '')
82100

83101
for prompt_index, prompt in enumerate(test['prompts'], start=1):
84-
prompt_folder = os.path.join(test_folder, str(prompt_index))
85-
os.makedirs(prompt_folder, exist_ok=True)
86-
87-
unique_responses = set()
88-
89-
for _ in range(ITERATIONS):
90-
full_prompt = f"{prefix} {prompt}".strip()
91-
response = get_code_response(full_prompt)
92-
if response not in unique_responses:
93-
unique_responses.add(response)
94-
filename = os.path.join(prompt_folder, f"{uuid.uuid4()}{EXTENSION}")
95-
with open(filename, 'w') as response_file:
96-
response_file.write(response)
97-
time.sleep(SLEEP) # To avoid hitting rate limits
102+
process_prompts(test_folder, instructions, prefix, prompt, prompt_index)
98103

99104
if __name__ == "__main__":
100105
main()

0 commit comments

Comments
 (0)