We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 849f02c commit 6fd874cCopy full SHA for 6fd874c
tests/chat.py
@@ -0,0 +1,30 @@
1
+import anyio
2
+import httpx
3
+import orjson
4
+
5
+async def chat_with_endpoint():
6
+ async with httpx.AsyncClient() as client:
7
+ while True:
8
+ # Get user input
9
+ prompt = input("\nYou: ")
10
+ if prompt.lower() == "exit":
11
+ break
12
13
+ # Send request to the API
14
+ print("\nModel: ", end="", flush=True)
15
+ async with client.stream(
16
+ "POST",
17
+ "http://localhost:8000/chat/",
18
+ data={"prompt": prompt},
19
+ timeout=60
20
+ ) as response:
21
+ async for chunk in response.aiter_lines():
22
+ if chunk:
23
+ try:
24
+ data = orjson.loads(chunk)
25
+ print(data["content"], end="", flush=True)
26
+ except Exception as e:
27
+ print(f"\nError parsing chunk: {e}")
28
29
+if __name__ == "__main__":
30
+ anyio.run(chat_with_endpoint)
0 commit comments