Skip to content

Commit

Permalink
feat(streaming/tools): refactor to event iterator structure
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertCraigie committed May 30, 2024
1 parent 997af69 commit bdcc283
Show file tree
Hide file tree
Showing 5 changed files with 281 additions and 87 deletions.
5 changes: 4 additions & 1 deletion examples/tools_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ async def main() -> None:
messages=[{"role": "user", "content": "What is the weather in SF?"}],
event_handler=MyHandler,
) as stream:
await stream.until_done()
async for event in stream:
if event.type == "input_json":
print(f"delta: {repr(event.partial_json)}")
print(f"snapshot: {event.snapshot}")

print()

Expand Down
6 changes: 6 additions & 0 deletions src/anthropic/lib/streaming/beta/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@
ToolsBetaMessageStreamManager as ToolsBetaMessageStreamManager,
AsyncToolsBetaMessageStreamManager as AsyncToolsBetaMessageStreamManager,
)
from ._types import (
ToolsBetaInputJsonEvent as ToolsBetaInputJsonEvent,
ToolsBetaMessageStopEvent as ToolsBetaMessageStopEvent,
ToolsBetaMessageStreamEvent as ToolsBetaMessageStreamEvent,
ToolsBetaContentBlockStopEvent as ToolsBetaContentBlockStopEvent,
)
Loading

0 comments on commit bdcc283

Please sign in to comment.