Skip to content

Commit

Permalink
fix(tests): Adapt to new Anthropic version (getsentry#3119)
Browse files Browse the repository at this point in the history
  • Loading branch information
sentrivana authored Jun 3, 2024
1 parent 84775a0 commit 4e2af01
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions tests/integrations/anthropic/test_anthropic.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
import pytest
from unittest import mock
from anthropic import Anthropic, Stream, AnthropicError
from anthropic.types import Usage, ContentBlock, MessageDeltaUsage, TextDelta
from anthropic.types import Usage, MessageDeltaUsage, TextDelta
from anthropic.types.message import Message
from anthropic.types.message_delta_event import MessageDeltaEvent
from anthropic.types.message_start_event import MessageStartEvent
from anthropic.types.content_block_start_event import ContentBlockStartEvent
from anthropic.types.content_block_delta_event import ContentBlockDeltaEvent
from anthropic.types.content_block_stop_event import ContentBlockStopEvent
from anthropic.types.message_delta_event import MessageDeltaEvent, Delta

try:
# 0.27+
from anthropic.types.raw_message_delta_event import Delta
except ImportError:
# pre 0.27
from anthropic.types.message_delta_event import Delta

try:
from anthropic.types.text_block import TextBlock
except ImportError:
from anthropic.types.content_block import ContentBlock as TextBlock

from sentry_sdk import start_transaction
from sentry_sdk.consts import OP, SPANDATA
Expand All @@ -18,7 +30,7 @@
id="id",
model="model",
role="assistant",
content=[ContentBlock(type="text", text="Hi, I'm Claude.")],
content=[TextBlock(type="text", text="Hi, I'm Claude.")],
type="message",
usage=Usage(input_tokens=10, output_tokens=20),
)
Expand Down Expand Up @@ -113,7 +125,7 @@ def test_streaming_create_message(
ContentBlockStartEvent(
type="content_block_start",
index=0,
content_block=ContentBlock(type="text", text=""),
content_block=TextBlock(type="text", text=""),
),
ContentBlockDeltaEvent(
delta=TextDelta(text="Hi", type="text_delta"),
Expand Down

0 comments on commit 4e2af01

Please sign in to comment.