Skip to content

Commit

Permalink
chore(streaming): add runtime type check for better error messages (#826
Browse files Browse the repository at this point in the history
)
  • Loading branch information
RobertCraigie authored and stainless-app[bot] committed Jan 17, 2025
1 parent 9182431 commit f5b5cb1
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/anthropic/lib/streaming/_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing_extensions import Self, Iterator, Awaitable, AsyncIterator, assert_never

import httpx
from pydantic import BaseModel

from ._types import (
TextEvent,
Expand Down Expand Up @@ -346,6 +347,9 @@ def accumulate_event(
event: RawMessageStreamEvent,
current_snapshot: Message | None,
) -> Message:
if not isinstance(event, BaseModel): # pyright: ignore[reportUnnecessaryIsInstance]
raise TypeError(f'Unexpected event runtime type - {event}')

if current_snapshot is None:
if event.type == "message_start":
return Message.construct(**cast(Any, event.message.to_dict()))
Expand Down

0 comments on commit f5b5cb1

Please sign in to comment.