Spaces:
Running
Running
| # debug_response.py | |
| import urllib.request, json | |
| BASE = 'https://dev-crafterx-preference-lab.hf.space' | |
| def post(url, data): | |
| body = json.dumps(data).encode() | |
| req = urllib.request.Request(url, data=body, headers={'Content-Type': 'application/json'}) | |
| with urllib.request.urlopen(req, timeout=60) as r: | |
| return json.loads(r.read()) | |
| print("RESET response:") | |
| r = post(f'{BASE}/reset', {'task_type': 'pairwise', 'seed': 42}) | |
| print(json.dumps(r, indent=2)) | |
| print("\nSTEP response:") | |
| s = post(f'{BASE}/step', {'action': {'choice': 'A'}}) | |
| print(json.dumps(s, indent=2)) | |
| print("\nSTATE response:") | |
| import urllib.request as ur | |
| with ur.urlopen(f'{BASE}/state', timeout=60) as resp: | |
| print(json.dumps(json.loads(resp.read()), indent=2)) |