Open avadon1 opened 2 weeks ago
This content should be updated to use the new Iterator API: https://github.com/anthropics/anthropic-sdk-python/pull/532
I believe this is the current way to do this:
from anthropic import AsyncAnthropic
client = AsyncAnthropic()
green = '\033[32m'
reset = '\033[0m'
async def streaming_events_demo():
async with client.messages.stream(
max_tokens=1024,
messages=[
{
"role": "user",
"content": "Generate a 5-word poem",
}
],
model="claude-3-opus-20240229",
) as stream:
async for event in stream:
if event.type == "text":
# This runs only on text delta stream messages
print(green + event.text + reset, flush=True)
else:
# This runs on any stream event
print("on_event fired:", event.type)
await streaming_events_demo()
Path to course in question: https://github.com/anthropics/courses/blob/master/anthropic_api_fundamentals/05_Streaming.ipynb In the Streaming helpers part of the 05.Streaming segment of the api_fundamentals courses when running the last piece of code I am getting the following error: I tried downgrading to an earlier version of anthropic (0.33.0) but the problem persists.