File size: 748 Bytes
b9664a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 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))