From 6fd874c2ccc3206ba08baf1dad56eca8cdd16b31 Mon Sep 17 00:00:00 2001 From: grillazz Date: Sat, 3 May 2025 08:46:54 +0200 Subject: [PATCH] add chat testing client --- tests/chat.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/chat.py diff --git a/tests/chat.py b/tests/chat.py new file mode 100644 index 0000000..a231c6c --- /dev/null +++ b/tests/chat.py @@ -0,0 +1,30 @@ +import anyio +import httpx +import orjson + +async def chat_with_endpoint(): + async with httpx.AsyncClient() as client: + while True: + # Get user input + prompt = input("\nYou: ") + if prompt.lower() == "exit": + break + + # Send request to the API + print("\nModel: ", end="", flush=True) + async with client.stream( + "POST", + "http://localhost:8000/chat/", + data={"prompt": prompt}, + timeout=60 + ) as response: + async for chunk in response.aiter_lines(): + if chunk: + try: + data = orjson.loads(chunk) + print(data["content"], end="", flush=True) + except Exception as e: + print(f"\nError parsing chunk: {e}") + +if __name__ == "__main__": + anyio.run(chat_with_endpoint)