forked from AntonOsika/gpt-engineer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.py
78 lines (63 loc) · 1.96 KB
/
benchmark.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
67
68
69
70
71
72
73
74
75
76
77
78
# list all folders in benchmark folder
# for each folder, run the benchmark
import os
import subprocess
from itertools import islice
from pathlib import Path
from typing import Iterable
from typer import run
def main(
n_benchmarks: int | None = None,
):
path = Path("benchmark")
folders: Iterable[Path] = path.iterdir()
if n_benchmarks:
folders = islice(folders, n_benchmarks)
benchmarks = []
for bench_folder in folders:
if os.path.isdir(bench_folder):
print(f"Running benchmark for {bench_folder}")
log_path = bench_folder / "log.txt"
log_file = open(log_path, "w")
process = subprocess.Popen(
[
"python",
"-u", # Unbuffered output
"-m",
"gpt_engineer.main",
bench_folder,
"--steps",
"benchmark",
],
stdout=log_file,
stderr=log_file,
bufsize=0,
)
benchmarks.append((bench_folder, process, log_file))
print("You can stream the log file by running:")
print(f"tail -f {log_path}")
print()
for bench_folder, process, file in benchmarks:
process.wait()
file.close()
print("process", bench_folder.name, "finished with code", process.returncode)
print("Running it. Original benchmark prompt:")
print()
with open(bench_folder / "main_prompt") as f:
print(f.read())
print()
try:
subprocess.run(
[
"python",
"-m",
"gpt_engineer.main",
bench_folder,
"--steps",
"execute_only",
],
)
except KeyboardInterrupt:
pass
if __name__ == "__main__":
run(main)