-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
41 lines (32 loc) · 1.05 KB
/
client.py
File metadata and controls
41 lines (32 loc) · 1.05 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
40
41
import httpx
import asyncio
import json
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-q", "--query", default="who is the president of Korea?")
parser.add_argument("-p", "--platform", default="nim")
args = parser.parse_args()
QUERY = args.query
PLATFORM = args.platform
headers = {
'Content-Type': 'application/json; charset=utf-8',
'Accept': 'application/json'
}
data = {
"query": QUERY,
"platform": PLATFORM
}
async def main():
print("[PLATFORM]:", PLATFORM.upper())
print("[QUERY]:", QUERY)
async with httpx.AsyncClient() as client:
response = await client.post("http://127.0.0.1:8000/query", headers=headers, json=data)
print("[STATUS CODE]:", response.status_code)
print("[STREAMING RESPONSES]")
print(response.text)
full_text = response.text
print("[FULL RESPONSE]")
content = full_text.split('\n')
full_response = ''.join([json.loads(i)['data'] for i in content[:-2]])
print(full_response)
asyncio.run(main())