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

refactor(streaming): move to an iterator pattern #528

Merged
merged 3 commits into from
May 30, 2024

Conversation

RobertCraigie
Copy link
Collaborator

Now instead of requiring you to define a subclass and pass it as an argument, we yield special SDK constructed events, e.g.

from anthropic import AsyncAnthropic

client = AsyncAnthropic()

async with client.messages.stream(
    max_tokens=1024,
    messages=[
        {
            "role": "user",
            "content": "Say hello there!",
        }
    ],
    model="claude-3-opus-20240229",
) as stream:
    async for event in stream:
        if event.type == "text":
            print(event.text, end="", flush=True)
        elif event.type == 'content_block_stop':
            print('\n\ncontent block finished accumulating:', event.content_block)

    print()

@RobertCraigie RobertCraigie requested a review from a team as a code owner May 29, 2024 18:21
stainless-bot added a commit to anthropics/anthropic-sdk-typescript that referenced this pull request May 30, 2024
this change is mainly for consistency with the Python SDK as there is a
distinct difference between `Raw` and non-`Raw` types, see this PR for
more details: anthropics/anthropic-sdk-python#528
stainless-bot added a commit to anthropics/anthropic-sdk-typescript that referenced this pull request May 30, 2024
this change is mainly for consistency with the Python SDK as there is a
distinct difference between `Raw` and non-`Raw` types, see this PR for
more details: anthropics/anthropic-sdk-python#528
stainless-bot added a commit to anthropics/anthropic-sdk-typescript that referenced this pull request May 30, 2024
this change is mainly for consistency with the Python SDK as there is a
distinct difference between `Raw` and non-`Raw` types, see this PR for
more details: anthropics/anthropic-sdk-python#528
@stainless-bot stainless-bot force-pushed the robert/streaming-helpers-refactors branch from a580a47 to 26f9533 Compare May 30, 2024 11:08
@RobertCraigie RobertCraigie merged commit 7526bf0 into next May 30, 2024
@RobertCraigie RobertCraigie deleted the robert/streaming-helpers-refactors branch May 30, 2024 11:15
stainless-app bot pushed a commit to anthropics/anthropic-sdk-typescript that referenced this pull request May 30, 2024
this change is mainly for consistency with the Python SDK as there is a
distinct difference between `Raw` and non-`Raw` types, see this PR for
more details: anthropics/anthropic-sdk-python#528
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

Successfully merging this pull request may close these issues.

1 participant