Initial implementation of the inference system (#869)

* very primitive implementation of inference

* re-worked with security in mind

* removed polling from clients

* switched workers to websockets

* implemented back and forth chats
This commit is contained in:
Yannic Kilcher
2023-01-21 22:38:18 +01:00
committed by GitHub
parent cec49614c2
commit 1709dc0324
10 changed files with 405 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
"""Simple REPL frontend."""
import json
import requests
import sseclient
import typer
app = typer.Typer()
@app.command()
def main(backend_url: str = "http://127.0.0.1:8000"):
"""Simple REPL client."""
chat_id = requests.post(f"{backend_url}/chat", json={}).json()["id"]
while True:
message = typer.prompt("User").strip()
# wait for stream to be ready
# could implement a queue position indicator
# could be implemented with long polling
# but server load needs to be considered
response = requests.post(
f"{backend_url}/chat/{chat_id}/message",
json={"message": message},
stream=True,
headers={"Accept": "text/event-stream"},
)
response.raise_for_status()
client = sseclient.SSEClient(response)
print("Assistant: ", end="", flush=True)
for event in client.events():
data = json.loads(event.data)
print(data["token"], end="", flush=True)
print()
if __name__ == "__main__":
app()
+3
View File
@@ -0,0 +1,3 @@
requests
sseclient-py
typer