|
1 | 1 | import pytest
|
2 | 2 | from unittest import mock
|
3 | 3 | from anthropic import Anthropic, Stream, AnthropicError
|
4 |
| -from anthropic.types import Usage, ContentBlock, MessageDeltaUsage, TextDelta |
| 4 | +from anthropic.types import Usage, MessageDeltaUsage, TextDelta |
5 | 5 | from anthropic.types.message import Message
|
| 6 | +from anthropic.types.message_delta_event import MessageDeltaEvent |
6 | 7 | from anthropic.types.message_start_event import MessageStartEvent
|
7 | 8 | from anthropic.types.content_block_start_event import ContentBlockStartEvent
|
8 | 9 | from anthropic.types.content_block_delta_event import ContentBlockDeltaEvent
|
9 | 10 | from anthropic.types.content_block_stop_event import ContentBlockStopEvent
|
10 |
| -from anthropic.types.message_delta_event import MessageDeltaEvent, Delta |
| 11 | + |
| 12 | +try: |
| 13 | + # 0.27+ |
| 14 | + from anthropic.types.raw_message_delta_event import Delta |
| 15 | +except ImportError: |
| 16 | + # pre 0.27 |
| 17 | + from anthropic.types.message_delta_event import Delta |
| 18 | + |
| 19 | +try: |
| 20 | + from anthropic.types.text_block import TextBlock |
| 21 | +except ImportError: |
| 22 | + from anthropic.types.content_block import ContentBlock as TextBlock |
11 | 23 |
|
12 | 24 | from sentry_sdk import start_transaction
|
13 | 25 | from sentry_sdk.consts import OP, SPANDATA
|
|
18 | 30 | id="id",
|
19 | 31 | model="model",
|
20 | 32 | role="assistant",
|
21 |
| - content=[ContentBlock(type="text", text="Hi, I'm Claude.")], |
| 33 | + content=[TextBlock(type="text", text="Hi, I'm Claude.")], |
22 | 34 | type="message",
|
23 | 35 | usage=Usage(input_tokens=10, output_tokens=20),
|
24 | 36 | )
|
@@ -113,7 +125,7 @@ def test_streaming_create_message(
|
113 | 125 | ContentBlockStartEvent(
|
114 | 126 | type="content_block_start",
|
115 | 127 | index=0,
|
116 |
| - content_block=ContentBlock(type="text", text=""), |
| 128 | + content_block=TextBlock(type="text", text=""), |
117 | 129 | ),
|
118 | 130 | ContentBlockDeltaEvent(
|
119 | 131 | delta=TextDelta(text="Hi", type="text_delta"),
|
|
0 commit comments