-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_socket.py
34 lines (29 loc) · 762 Bytes
/
test_socket.py
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
import sys
import json
import socket
assert len(sys.argv) == 2
SOCKET_PATH = sys.argv[1]
unix_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
unix_socket.connect(SOCKET_PATH)
CODE = """
function sum_list(l: _hole_) {
let sum = 0;
for (let i = 0; i < l.length; i++) {
sum += l[i];
}
return sum;
}
"""
payload = {
"code": CODE,
"num_samples": 3,
"temperature": 1.0,
}
unix_socket.sendall(json.dumps(payload).encode("utf-8") + b"??END??")
response = unix_socket.recv(1024).decode("utf-8")
# print("response: {}".format(response))
response_decoded = json.loads(response)
for i, sample in enumerate(response_decoded["type_annotations"]):
print(f"#### Completion {i} ####")
print(sample)
unix_socket.close()