Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tests): Adapt to new Anthropic version #3119

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading