-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathclient.py
More file actions
33 lines (26 loc) · 1009 Bytes
/
client.py
File metadata and controls
33 lines (26 loc) · 1009 Bytes
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
# client.py
import requests
import json
import argparse
import time
# replace this URL with your exposed URL from the API builder. The URL looks like this
SERVER_URL = 'http://0.0.0.0:8000'
def main():
parser = argparse.ArgumentParser(description="Send a query to the LitServe server.")
parser.add_argument("--query", type=str, required=True, help="The query text to send to the server.")
args = parser.parse_args()
payload = {
"query": args.query
}
try:
response = requests.post(f"{SERVER_URL}/predict", json=payload)
response.raise_for_status() # Raise an exception for bad status codes
result = response.json()['output']['raw']
for token in result.split():
print(token, end=" ", flush=True)
time.sleep(0.05)
# print(json.dumps(result, indent=2))
except requests.exceptions.RequestException as e:
print(f"Error sending request: {e}")
if __name__ == "__main__":
main()