|
12 | 12 |
|
13 | 13 | from sentry_sdk.utils import package_version |
14 | 14 |
|
| 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 | + |
15 | 23 | try: |
16 | 24 | # 0.27+ |
17 | | - from anthropic.types import InputJsonDelta |
18 | 25 | from anthropic.types.raw_message_delta_event import Delta |
19 | 26 | from anthropic.types.tool_use_block import ToolUseBlock |
20 | 27 | except ImportError: |
@@ -210,7 +217,7 @@ def test_streaming_create_message( |
210 | 217 |
|
211 | 218 | @pytest.mark.skipif( |
212 | 219 | 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.", |
214 | 221 | ) |
215 | 222 | @pytest.mark.parametrize( |
216 | 223 | "send_default_pii, include_prompts", |
@@ -248,32 +255,32 @@ def test_streaming_create_message_with_input_json_delta( |
248 | 255 | ), |
249 | 256 | ), |
250 | 257 | ContentBlockDeltaEvent( |
251 | | - delta=InputJsonDelta(partial_json="", type="input_json_delta"), |
| 258 | + delta=InputJSONDelta(partial_json="", type="input_json_delta"), |
252 | 259 | index=0, |
253 | 260 | type="content_block_delta", |
254 | 261 | ), |
255 | 262 | ContentBlockDeltaEvent( |
256 | | - delta=InputJsonDelta(partial_json="{'location':", type="input_json_delta"), |
| 263 | + delta=InputJSONDelta(partial_json="{'location':", type="input_json_delta"), |
257 | 264 | index=0, |
258 | 265 | type="content_block_delta", |
259 | 266 | ), |
260 | 267 | ContentBlockDeltaEvent( |
261 | | - delta=InputJsonDelta(partial_json=" 'S", type="input_json_delta"), |
| 268 | + delta=InputJSONDelta(partial_json=" 'S", type="input_json_delta"), |
262 | 269 | index=0, |
263 | 270 | type="content_block_delta", |
264 | 271 | ), |
265 | 272 | ContentBlockDeltaEvent( |
266 | | - delta=InputJsonDelta(partial_json="an ", type="input_json_delta"), |
| 273 | + delta=InputJSONDelta(partial_json="an ", type="input_json_delta"), |
267 | 274 | index=0, |
268 | 275 | type="content_block_delta", |
269 | 276 | ), |
270 | 277 | ContentBlockDeltaEvent( |
271 | | - delta=InputJsonDelta(partial_json="Francisco, C", type="input_json_delta"), |
| 278 | + delta=InputJSONDelta(partial_json="Francisco, C", type="input_json_delta"), |
272 | 279 | index=0, |
273 | 280 | type="content_block_delta", |
274 | 281 | ), |
275 | 282 | ContentBlockDeltaEvent( |
276 | | - delta=InputJsonDelta(partial_json="A'}", type="input_json_delta"), |
| 283 | + delta=InputJSONDelta(partial_json="A'}", type="input_json_delta"), |
277 | 284 | index=0, |
278 | 285 | type="content_block_delta", |
279 | 286 | ), |
@@ -325,8 +332,8 @@ def test_streaming_create_message_with_input_json_delta( |
325 | 332 | if send_default_pii and include_prompts: |
326 | 333 | assert span["data"][SPANDATA.AI_INPUT_MESSAGES] == messages |
327 | 334 | 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 |
330 | 337 |
|
331 | 338 | else: |
332 | 339 | assert SPANDATA.AI_INPUT_MESSAGES not in span["data"] |
|
0 commit comments