-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_wrapper_server.py
More file actions
61 lines (52 loc) · 2.58 KB
/
test_wrapper_server.py
File metadata and controls
61 lines (52 loc) · 2.58 KB
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
import os, sys, json, math
import requests
from wrapper_server import server
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
def process_jsonl_file(path, n_samples) -> list:
payloads = []
with open(path, "r", encoding="utf-8") as f:
for line_num, line in enumerate(f, 1):
try:
raw = json.loads(line)
ground_truth = raw["extra_info"]["ground_truth"]
if ground_truth is None:
continue
payload_dict = {
"problem_id": raw["extra_info"]["example_name"],
"solution": ground_truth,
}
payload = server.Payload(**payload_dict)
payloads.append(payload)
if len(payloads) >= n_samples:
break
except Exception as e:
print(f"[Line {line_num}] Error: {e}")
continue
return payloads
def test_single_examples(payloads, url="http://localhost:8007/check_problem_solution"):
for payload in payloads:
try:
response = requests.post(url, json=payload.model_dump(), timeout=15000)
response.raise_for_status()
resp_json = response.json()
print(f"Response for example {payload.problem_id}: {resp_json['return_code']}, Score: {resp_json['score']}")
except Exception as e:
print(f"Request failed for example {payload.problem_id}: {e}, returning -1")
def test_batch_examples(payloads, url="http://localhost:8007/batch_check_problem_solution"):
try:
response = requests.post(url, json=[payload.model_dump() for payload in payloads], timeout=15000)
response.raise_for_status()
resp_json = response.json()
for payload, result in zip(payloads, resp_json):
print(f"Response for example {payload.problem_id}: {result['return_code']}, Score: {result['score']}")
except Exception as e:
print(f"Request failed for batch: {e}, returning -1")
if __name__ == "__main__":
# uncomment the file you want to test on. these are the splits that have ground truths, which is necessary to simulate testing
# jsonl_path = os.path.join(CURRENT_DIR, "wrapper_server/lean-test-data-Verina.jsonl")
# jsonl_path = os.path.join(CURRENT_DIR, "wrapper_server/lean-train-rl-data-Lean-Workbook.jsonl")
jsonl_path = os.path.join(CURRENT_DIR, "wrapper_server/lean-val-rl-data-Lean-Workbook.jsonl")
num_examples = 50
payloads = process_jsonl_file(jsonl_path, num_examples)
test_single_examples(payloads)
# test_batch_examples(payloads)