|
| 1 | +import json |
1 | 2 | from unittest import mock |
2 | 3 |
|
3 | 4 | try: |
@@ -115,10 +116,10 @@ def test_nonstreaming_create_message( |
115 | 116 | assert span["data"][SPANDATA.AI_MODEL_ID] == "model" |
116 | 117 |
|
117 | 118 | if send_default_pii and include_prompts: |
118 | | - assert span["data"][SPANDATA.AI_INPUT_MESSAGES] == messages |
119 | | - assert span["data"][SPANDATA.AI_RESPONSES] == [ |
120 | | - {"type": "text", "text": "Hi, I'm Claude."} |
121 | | - ] |
| 119 | + assert span["data"][SPANDATA.AI_INPUT_MESSAGES] == json.dumps(messages) |
| 120 | + assert span["data"][SPANDATA.AI_RESPONSES] == json.dumps( |
| 121 | + [{"type": "text", "text": "Hi, I'm Claude."}] |
| 122 | + ) |
122 | 123 | else: |
123 | 124 | assert SPANDATA.AI_INPUT_MESSAGES not in span["data"] |
124 | 125 | assert SPANDATA.AI_RESPONSES not in span["data"] |
@@ -183,10 +184,10 @@ async def test_nonstreaming_create_message_async( |
183 | 184 | assert span["data"][SPANDATA.AI_MODEL_ID] == "model" |
184 | 185 |
|
185 | 186 | if send_default_pii and include_prompts: |
186 | | - assert span["data"][SPANDATA.AI_INPUT_MESSAGES] == messages |
187 | | - assert span["data"][SPANDATA.AI_RESPONSES] == [ |
188 | | - {"type": "text", "text": "Hi, I'm Claude."} |
189 | | - ] |
| 187 | + assert span["data"][SPANDATA.AI_INPUT_MESSAGES] == json.dumps(messages) |
| 188 | + assert span["data"][SPANDATA.AI_RESPONSES] == json.dumps( |
| 189 | + [{"type": "text", "text": "Hi, I'm Claude."}] |
| 190 | + ) |
190 | 191 | else: |
191 | 192 | assert SPANDATA.AI_INPUT_MESSAGES not in span["data"] |
192 | 193 | assert SPANDATA.AI_RESPONSES not in span["data"] |
@@ -282,10 +283,10 @@ def test_streaming_create_message( |
282 | 283 | assert span["data"][SPANDATA.AI_MODEL_ID] == "model" |
283 | 284 |
|
284 | 285 | if send_default_pii and include_prompts: |
285 | | - assert span["data"][SPANDATA.AI_INPUT_MESSAGES] == messages |
286 | | - assert span["data"][SPANDATA.AI_RESPONSES] == [ |
287 | | - {"type": "text", "text": "Hi! I'm Claude!"} |
288 | | - ] |
| 286 | + assert span["data"][SPANDATA.AI_INPUT_MESSAGES] == json.dumps(messages) |
| 287 | + assert span["data"][SPANDATA.AI_RESPONSES] == json.dumps( |
| 288 | + [{"type": "text", "text": "Hi! I'm Claude!"}] |
| 289 | + ) |
289 | 290 |
|
290 | 291 | else: |
291 | 292 | assert SPANDATA.AI_INPUT_MESSAGES not in span["data"] |
@@ -385,10 +386,10 @@ async def test_streaming_create_message_async( |
385 | 386 | assert span["data"][SPANDATA.AI_MODEL_ID] == "model" |
386 | 387 |
|
387 | 388 | if send_default_pii and include_prompts: |
388 | | - assert span["data"][SPANDATA.AI_INPUT_MESSAGES] == messages |
389 | | - assert span["data"][SPANDATA.AI_RESPONSES] == [ |
390 | | - {"type": "text", "text": "Hi! I'm Claude!"} |
391 | | - ] |
| 389 | + assert span["data"][SPANDATA.AI_INPUT_MESSAGES] == json.dumps(messages) |
| 390 | + assert span["data"][SPANDATA.AI_RESPONSES] == json.dumps( |
| 391 | + [{"type": "text", "text": "Hi! I'm Claude!"}] |
| 392 | + ) |
392 | 393 |
|
393 | 394 | else: |
394 | 395 | assert SPANDATA.AI_INPUT_MESSAGES not in span["data"] |
@@ -515,10 +516,10 @@ def test_streaming_create_message_with_input_json_delta( |
515 | 516 | assert span["data"][SPANDATA.AI_MODEL_ID] == "model" |
516 | 517 |
|
517 | 518 | if send_default_pii and include_prompts: |
518 | | - assert span["data"][SPANDATA.AI_INPUT_MESSAGES] == messages |
519 | | - assert span["data"][SPANDATA.AI_RESPONSES] == [ |
520 | | - {"text": "", "type": "text"} |
521 | | - ] # we do not record InputJSONDelta because it could contain PII |
| 519 | + assert span["data"][SPANDATA.AI_INPUT_MESSAGES] == json.dumps(messages) |
| 520 | + assert span["data"][SPANDATA.AI_RESPONSES] == json.dumps( |
| 521 | + [{"type": "text", "text": ""}] |
| 522 | + ) # we do not record InputJSONDelta because it could contain PII |
522 | 523 |
|
523 | 524 | else: |
524 | 525 | assert SPANDATA.AI_INPUT_MESSAGES not in span["data"] |
@@ -652,10 +653,10 @@ async def test_streaming_create_message_with_input_json_delta_async( |
652 | 653 | assert span["data"][SPANDATA.AI_MODEL_ID] == "model" |
653 | 654 |
|
654 | 655 | if send_default_pii and include_prompts: |
655 | | - assert span["data"][SPANDATA.AI_INPUT_MESSAGES] == messages |
656 | | - assert span["data"][SPANDATA.AI_RESPONSES] == [ |
657 | | - {"text": "", "type": "text"} |
658 | | - ] # we do not record InputJSONDelta because it could contain PII |
| 656 | + assert span["data"][SPANDATA.AI_INPUT_MESSAGES] == json.dumps(messages) |
| 657 | + assert span["data"][SPANDATA.AI_RESPONSES] == json.dumps( |
| 658 | + [{"type": "text", "text": ""}] |
| 659 | + ) # we do not record InputJSONDelta because it could contain PII |
659 | 660 |
|
660 | 661 | else: |
661 | 662 | assert SPANDATA.AI_INPUT_MESSAGES not in span["data"] |
|
0 commit comments