ChadAlpaca-Flask / client.py
PawinChan
Several bugfixes, as well as added Vicuna.
88be9f7
import time, requests
ENDPOINT = "https://pawinc-chadalpaca-flask.hf.space/chat"
serverIsPreparing = True
print("Checking server status")
while serverIsPreparing:
try:
with requests.get(ENDPOINT) as r:
print("Status Check: " + r.text)
if r.text == 'Ready':
break
else:
time.sleep(5)
except requests.exceptions.ConnectionError:
print("Connection Refused. Retrying in 5 seconds.")
time.sleep(5)
print("Server is ready. Starting client.")
headers = {"Content-type": "application/json", "Authorization": "test:test"}
messages = [
{"role": "user", "content": "Hello, how are you feeling today?"},
{"role": "assistant", "content": "I'm feeling great. How about you?"},
{"role": "user", "content": "I'm fine, thanks for asking."}
]
print("Sending Request...")
try:
with requests.post(ENDPOINT, headers=headers, json=messages) as r:
print(r.json()["content"])
except requests.exceptions.JSONDecodeError:
print(f"Something went wrong: {r.status_code}- {r.text}")