Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In anthropic_api_fundamentals/05.Streaming.ipynb error: unexpecter keyword argument 'event_handler' #28

Open
avadon1 opened this issue Aug 28, 2024 · 2 comments

Comments

@avadon1
Copy link

avadon1 commented Aug 28, 2024

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:
image
I tried downgrading to an earlier version of anthropic (0.33.0) but the problem persists.

@antsant
Copy link

antsant commented Sep 2, 2024

This content should be updated to use the new Iterator API: anthropics/anthropic-sdk-python#532

@antsant
Copy link

antsant commented Sep 2, 2024

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()

eyefodder added a commit to eyefodder/courses that referenced this issue Sep 29, 2024
eyefodder added a commit to eyefodder/courses that referenced this issue Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants