Skip to content

Commit 8f0846b

Browse files
committed
Updated tests to work in latest Anthropic and also check for not recorded InputJsonDelta
1 parent 6bdacea commit 8f0846b

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

tests/integrations/anthropic/test_anthropic.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,16 @@
1212

1313
from sentry_sdk.utils import package_version
1414

15+
try:
16+
from anthropic.types import InputJSONDelta
17+
except ImportError:
18+
try:
19+
from anthropic.types import InputJsonDelta as InputJSONDelta
20+
except ImportError:
21+
pass
22+
1523
try:
1624
# 0.27+
17-
from anthropic.types import InputJsonDelta
1825
from anthropic.types.raw_message_delta_event import Delta
1926
from anthropic.types.tool_use_block import ToolUseBlock
2027
except ImportError:
@@ -210,7 +217,7 @@ def test_streaming_create_message(
210217

211218
@pytest.mark.skipif(
212219
ANTHROPIC_VERSION < (0, 27),
213-
reason="Versions <0.27.0 do not include InputJsonDelta, which was introduced in >=0.27.0 along with a new message delta type for tool calling.",
220+
reason="Versions <0.27.0 do not include InputJSONDelta, which was introduced in >=0.27.0 along with a new message delta type for tool calling.",
214221
)
215222
@pytest.mark.parametrize(
216223
"send_default_pii, include_prompts",
@@ -248,32 +255,32 @@ def test_streaming_create_message_with_input_json_delta(
248255
),
249256
),
250257
ContentBlockDeltaEvent(
251-
delta=InputJsonDelta(partial_json="", type="input_json_delta"),
258+
delta=InputJSONDelta(partial_json="", type="input_json_delta"),
252259
index=0,
253260
type="content_block_delta",
254261
),
255262
ContentBlockDeltaEvent(
256-
delta=InputJsonDelta(partial_json="{'location':", type="input_json_delta"),
263+
delta=InputJSONDelta(partial_json="{'location':", type="input_json_delta"),
257264
index=0,
258265
type="content_block_delta",
259266
),
260267
ContentBlockDeltaEvent(
261-
delta=InputJsonDelta(partial_json=" 'S", type="input_json_delta"),
268+
delta=InputJSONDelta(partial_json=" 'S", type="input_json_delta"),
262269
index=0,
263270
type="content_block_delta",
264271
),
265272
ContentBlockDeltaEvent(
266-
delta=InputJsonDelta(partial_json="an ", type="input_json_delta"),
273+
delta=InputJSONDelta(partial_json="an ", type="input_json_delta"),
267274
index=0,
268275
type="content_block_delta",
269276
),
270277
ContentBlockDeltaEvent(
271-
delta=InputJsonDelta(partial_json="Francisco, C", type="input_json_delta"),
278+
delta=InputJSONDelta(partial_json="Francisco, C", type="input_json_delta"),
272279
index=0,
273280
type="content_block_delta",
274281
),
275282
ContentBlockDeltaEvent(
276-
delta=InputJsonDelta(partial_json="A'}", type="input_json_delta"),
283+
delta=InputJSONDelta(partial_json="A'}", type="input_json_delta"),
277284
index=0,
278285
type="content_block_delta",
279286
),
@@ -325,8 +332,8 @@ def test_streaming_create_message_with_input_json_delta(
325332
if send_default_pii and include_prompts:
326333
assert span["data"][SPANDATA.AI_INPUT_MESSAGES] == messages
327334
assert span["data"][SPANDATA.AI_RESPONSES] == [
328-
{"text": "{'location': 'San Francisco, CA'}", "type": "text"}
329-
]
335+
{"text": "", "type": "text"}
336+
] # we do not record InputJSONDelta because it could contain PII
330337

331338
else:
332339
assert SPANDATA.AI_INPUT_MESSAGES not in span["data"]

0 commit comments

Comments
 (0)