Skip to content

Commit 6fd874c

Browse files
committed
add chat testing client
1 parent 849f02c commit 6fd874c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/chat.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)