forked from JoshuaC215/agent-service-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_client.py
More file actions
39 lines (31 loc) · 1.08 KB
/
run_client.py
File metadata and controls
39 lines (31 loc) · 1.08 KB
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
from client import AgentClient
from schema import ChatMessage
#### ASYNC ####
import asyncio
async def amain():
client = AgentClient()
print("Chat example:")
response = await client.ainvoke("Tell me a brief joke?", model="llama-3.1-70b")
response.pretty_print()
print("\nStream example:")
async for message in client.astream("Share a quick fun fact?"):
if isinstance(message, str):
print(message, flush=True, end="|")
elif isinstance(message, ChatMessage):
message.pretty_print()
else:
print(f"ERROR: Unknown type - {type(message)}")
asyncio.run(amain())
#### SYNC ####
client = AgentClient()
print("Chat example:")
response = client.invoke("Tell me a brief joke?", model="llama-3.1-70b")
response.pretty_print()
print("\nStream example:")
for message in client.stream("Share a quick fun fact?"):
if isinstance(message, str):
print(message, flush=True, end="|")
elif isinstance(message, ChatMessage):
message.pretty_print()
else:
print(f"ERROR: Unknown type - {type(message)}")