Skip to content

Commit 4e2af01

Browse files
authored
fix(tests): Adapt to new Anthropic version (#3119)
1 parent 84775a0 commit 4e2af01

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

tests/integrations/anthropic/test_anthropic.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
import pytest
22
from unittest import mock
33
from anthropic import Anthropic, Stream, AnthropicError
4-
from anthropic.types import Usage, ContentBlock, MessageDeltaUsage, TextDelta
4+
from anthropic.types import Usage, MessageDeltaUsage, TextDelta
55
from anthropic.types.message import Message
6+
from anthropic.types.message_delta_event import MessageDeltaEvent
67
from anthropic.types.message_start_event import MessageStartEvent
78
from anthropic.types.content_block_start_event import ContentBlockStartEvent
89
from anthropic.types.content_block_delta_event import ContentBlockDeltaEvent
910
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
1123

1224
from sentry_sdk import start_transaction
1325
from sentry_sdk.consts import OP, SPANDATA
@@ -18,7 +30,7 @@
1830
id="id",
1931
model="model",
2032
role="assistant",
21-
content=[ContentBlock(type="text", text="Hi, I'm Claude.")],
33+
content=[TextBlock(type="text", text="Hi, I'm Claude.")],
2234
type="message",
2335
usage=Usage(input_tokens=10, output_tokens=20),
2436
)
@@ -113,7 +125,7 @@ def test_streaming_create_message(
113125
ContentBlockStartEvent(
114126
type="content_block_start",
115127
index=0,
116-
content_block=ContentBlock(type="text", text=""),
128+
content_block=TextBlock(type="text", text=""),
117129
),
118130
ContentBlockDeltaEvent(
119131
delta=TextDelta(text="Hi", type="text_delta"),

0 commit comments

Comments
 (0)