This repository has been archived by the owner on Oct 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 114
/
server_request.py
79 lines (57 loc) · 1.9 KB
/
server_request.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import argparse
import requests
def get_args() -> argparse.Namespace:
parser = argparse.ArgumentParser()
group = parser.add_argument_group(title="launch config")
group.add_argument("--host", type=str, required=True, help="host address")
group.add_argument("--port", type=int, required=True, help="port number")
return parser.parse_args()
def generate(url: str) -> None:
url = url + "/generate/"
request_body = {
"text": [
"DeepSpeed",
"DeepSpeed is a",
"DeepSpeed is a machine",
"DeepSpeed is a machine learning framework",
],
"max_new_tokens": 40,
}
response = requests.post(url=url, json=request_body, verify=False)
print(response.json(), "\n")
def tokenize(url: str) -> None:
url = url + "/tokenize/"
request_body = {"text": ["DeepSpeed is a", "DeepSpeed is a machine learning framework"]}
response = requests.post(url=url, json=request_body, verify=False)
print(response.json(), "\n")
def forward(url: str) -> None:
url = url + "/forward/"
request_body = {
"conditioning_text": [
"DeepSpeed",
"DeepSpeed is a",
"DeepSpeed is a machine",
"DeepSpeed is a machine learning framework",
],
"response": [
"DeepSpeed",
"DeepSpeed is a",
"DeepSpeed is a machine",
"DeepSpeed is a machine learning framework",
],
}
response = requests.post(url=url, json=request_body, verify=False)
print(response.json(), "\n")
def query_id(url: str) -> None:
url = url + "/query_id/"
response = requests.get(url=url, verify=False)
print(response.json(), "\n")
def main():
args = get_args()
url = "http://{}:{}".format(args.host, args.port)
generate(url)
tokenize(url)
forward(url)
query_id(url)
if __name__ == "__main__":
main()