forked from LAION-AI/Open-Assistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__main__.py
44 lines (35 loc) · 1.18 KB
/
__main__.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
"""Simple REPL frontend."""
import time
import text_client_utils as utils
import typer
from loguru import logger
app = typer.Typer()
@app.command()
def main(backend_url: str = "http://127.0.0.1:8000", model_config_name="distilgpt2", username="test1"):
"""Simple REPL client."""
while True:
try:
# login
client = utils.DebugClient(backend_url)
client.login(username)
chat_id = client.create_chat()
typer.echo(f"Chat ID: {chat_id}")
while True:
message = typer.prompt("User").strip()
if not message:
continue
events = client.send_message(message, model_config_name)
print("Assistant: ", end="", flush=True)
for event in events:
print(event, end="", flush=True)
print()
except typer.Abort:
typer.echo("Exiting...")
break
except Exception as e:
logger.exception("Chat Error")
typer.echo(f"Error: {e}")
typer.echo("Error, restarting chat...")
time.sleep(1)
if __name__ == "__main__":
app()