Skip to content

Commit 0808182

Browse files
committed
Fixed cohere tests
1 parent e7218da commit 0808182

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

sentry_sdk/ai/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import Any
55

66
from sentry_sdk.tracing import Span
7-
from sentry_sdk.utils import logger
7+
from sentry_sdk.utils import _serialize_span_attribute, logger
88

99

1010
def _normalize_data(data):
@@ -29,4 +29,4 @@ def _normalize_data(data):
2929
def set_data_normalized(span, key, value):
3030
# type: (Span, str, Any) -> None
3131
normalized = _normalize_data(value)
32-
span.set_data(key, normalized)
32+
span.set_data(key, _serialize_span_attribute(normalized))

tests/integrations/cohere/test_cohere.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ def test_nonstreaming_chat(
5656
assert span["data"]["ai.model_id"] == "some-model"
5757

5858
if send_default_pii and include_prompts:
59-
assert "some context" in span["data"]["ai.input_messages"][0]["content"]
60-
assert "hello" in span["data"]["ai.input_messages"][1]["content"]
59+
input_messages = json.loads(span["data"]["ai.input_messages"])
60+
assert "some context" in input_messages[0]["content"]
61+
assert "hello" in input_messages[1]["content"]
6162
assert "the model response" in span["data"]["ai.responses"]
6263
else:
6364
assert "ai.input_messages" not in span["data"]
@@ -127,8 +128,9 @@ def test_streaming_chat(sentry_init, capture_events, send_default_pii, include_p
127128
assert span["data"]["ai.model_id"] == "some-model"
128129

129130
if send_default_pii and include_prompts:
130-
assert "some context" in span["data"]["ai.input_messages"][0]["content"]
131-
assert "hello" in span["data"]["ai.input_messages"][1]["content"]
131+
input_messages = json.loads(span["data"]["ai.input_messages"])
132+
assert "some context" in input_messages[0]["content"]
133+
assert "hello" in input_messages[1]["content"]
132134
assert "the model response" in span["data"]["ai.responses"]
133135
else:
134136
assert "ai.input_messages" not in span["data"]
@@ -150,7 +152,7 @@ def test_bad_chat(sentry_init, capture_events):
150152
with pytest.raises(httpx.HTTPError):
151153
client.chat(model="some-model", message="hello")
152154

153-
(event,) = events
155+
(event, _) = events
154156
assert event["level"] == "error"
155157

156158

0 commit comments

Comments
 (0)