forked from Sen-illion/DN
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_speed.py
More file actions
34 lines (31 loc) · 1.23 KB
/
test_speed.py
File metadata and controls
34 lines (31 loc) · 1.23 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
# -*- coding: utf-8 -*-
import json, time, urllib.request, urllib.error
def api_post(endpoint, payload, timeout=600):
url = f"http://127.0.0.1:5001/{endpoint}"
data = json.dumps(payload).encode("utf-8")
req = urllib.request.Request(url, data=data, headers={"Content-Type": "application/json"}, method="POST")
t0 = time.time()
try:
with urllib.request.urlopen(req, timeout=timeout) as resp:
result = json.loads(resp.read().decode("utf-8"))
elapsed = time.time() - t0
print(f"API call took {elapsed:.1f}s")
return result
except Exception as e:
elapsed = time.time() - t0
print(f"API call FAILED after {elapsed:.1f}s: {e}")
return {"error": str(e)}
print("Testing generate-worldview with 600s timeout...")
r = api_post("generate-worldview", {
"gameTheme": "高三同桌",
"imageStyle": "水彩风格",
"protagonistAttr": {"name": "林小雨", "personality": "内向温柔"},
"difficulty": "中等",
"toneKey": "romantic_ending"
}, timeout=600)
if "error" in r:
print(f"Error: {r['error']}")
else:
gid = r.get("globalState", {}).get("game_id", "NONE")
print(f"Success! game_id={gid}")
print(f"Top keys: {list(r.keys())}")