-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_eval.py
72 lines (53 loc) · 1.72 KB
/
create_eval.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
import os
import sys
import subprocess
name = sys.argv[1]
category = sys.argv[2]
evals_dir = "evals"
categories = os.listdir(evals_dir)
assert category in categories
category_dir = os.path.join(evals_dir, category)
if not os.path.exists(category_dir):
os.makedirs(category_dir)
existing = [int(l.split("-")[0]) for l in os.listdir(category_dir)]
if existing:
next_id = max(existing) + 1
else:
next_id = 0
assert "-" not in name
testdir_name = f"{next_id:03d}-{name}"
testdir = os.path.join(category_dir, testdir_name)
os.makedirs(testdir)
with open(os.path.join(testdir, "PROMPT.txt"), "w") as f:
f.write(f"Create a backend for a {name} system.")
answer_dir = os.path.join(testdir, "answer")
os.makedirs(answer_dir)
package_json = """{
"name": "convexbot",
"version": "1.0.0",
"dependencies": {
"convex": "^1.17.4"
}
}""".strip()
with open(os.path.join(answer_dir, "package.json"), "w") as f:
f.write(package_json)
convex_dir = os.path.join(answer_dir, "convex")
os.makedirs(convex_dir)
with open(os.path.join(convex_dir, "index.ts"), "w") as f:
f.write('import { v } from "convex/values"\n')
f.write('import { query } from "./_generated/server"\n')
grader_ts = """
import { expect, test } from "vitest";
import { adminClient, client, compareSchema, compareFunctionSpec } from "../../../grader";
import { anyApi } from "convex/server"
test("compare schema", async () => {
await compareSchema();
})
test("compare function spec", async () => {
await compareFunctionSpec();
})
"""
with open(os.path.join(testdir, "grader.test.ts"), "w") as f:
f.write(grader_ts)
subprocess.run(["bun", "install"], cwd=answer_dir, check=True)
subprocess.run(["bunx", "convex", "codegen"], cwd=answer_dir, check=True)