-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_request.py
More file actions
39 lines (32 loc) · 1.07 KB
/
test_request.py
File metadata and controls
39 lines (32 loc) · 1.07 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
import urllib.request
import json
"""
Send a test completion request to the local VDLM server
"""
def send_request():
url = "http://localhost:8000/completions"
payload = {
"model": "vdlm-v1",
"prompt": "How can I solve 2x=5?",
"max_tokens": 16,
"block_length": 4,
}
headers = {"Content-Type": "application/json"}
data = json.dumps(payload).encode("utf-8")
req = urllib.request.Request(url, data=data, headers=headers, method="POST")
try:
with urllib.request.urlopen(req) as response:
res_data = response.read().decode("utf-8")
print(f"Status Code: {response.getcode()}")
print(json.dumps(json.loads(res_data), indent=4))
except urllib.error.HTTPError as e:
print(f"HTTP Error: {e.code} {e.reason}")
error_body = e.read().decode("utf-8")
try:
print(json.dumps(json.loads(error_body), indent=4))
except:
print(error_body)
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
send_request()