-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent_streaming.py
More file actions
30 lines (22 loc) 路 851 Bytes
/
Copy pathagent_streaming.py
File metadata and controls
30 lines (22 loc) 路 851 Bytes
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
# Optional: If you're using a .env file for API keys, uncomment these lines
from dotenv import load_dotenv
load_dotenv()
import asyncio
import weave
from tyler import Agent, Thread, Message, EventType
weave.init("wandb-designers/slide-examples")
agent = Agent(
name="streaming-assistant",
model_name="gpt-4o",
purpose="To provide real-time responses"
)
async def stream_response():
thread = Thread()
message = Message(role="user", content="Tell me a story about space exploration")
thread.add_message(message)
print("馃 Assistant: ", end="", flush=True)
async for event in agent.go(thread, stream=True):
if event.type == EventType.LLM_STREAM_CHUNK:
print(event.data.get("content_chunk", ""), end="", flush=True)
print() # New line at the end
asyncio.run(stream_response())