Skip to content

Commit f6389f8

Browse files
committed
finalize prompt events
1 parent a9f48f3 commit f6389f8

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

src/tests/anthropic/test_anthropic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_anthropic(anthropic_client, exporter):
3333
assert completion_span.name == "anthropic.messages.create"
3434
attributes = completion_span.attributes
3535
assert_langtrace_attributes(attributes, "Anthropic")
36-
assert_prompt_in_events(completion_span.events, messages_value)
36+
assert_prompt_in_events(completion_span.events)
3737
assert attributes.get(SpanAttributes.LLM_URL) == "https://api.anthropic.com"
3838
assert (
3939
attributes.get(SpanAttributes.LLM_PATH) == APIS["MESSAGES_CREATE"]["ENDPOINT"]
@@ -74,7 +74,7 @@ def test_anthropic_streaming(anthropic_client, exporter):
7474
attributes = streaming_span.attributes
7575

7676
assert_langtrace_attributes(attributes, "Anthropic")
77-
assert_prompt_in_events(streaming_span.events, messages_value)
77+
assert_prompt_in_events(streaming_span.events)
7878

7979
assert attributes.get(SpanAttributes.LLM_URL) == "https://api.anthropic.com"
8080
assert (

src/tests/openai/test_chat_completion.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def test_chat_completion(exporter, openai_client):
3838
attributes.get(SpanAttributes.LLM_PATH) == APIS["CHAT_COMPLETION"]["ENDPOINT"]
3939
)
4040
assert attributes.get(SpanAttributes.LLM_RESPONSE_MODEL) == "gpt-4-0613"
41-
# assert attributes.get(SpanAttributes.LLM_PROMPTS) == json.dumps(messages_value)
41+
assert_prompt_in_events(completion_span.events)
4242
assert attributes.get(SpanAttributes.LLM_IS_STREAMING) is False
4343

4444
assert_token_count(attributes)
@@ -78,7 +78,7 @@ def test_chat_completion_streaming(exporter, openai_client):
7878
attributes.get(SpanAttributes.LLM_PATH) == APIS["CHAT_COMPLETION"]["ENDPOINT"]
7979
)
8080
assert attributes.get(SpanAttributes.LLM_RESPONSE_MODEL) == "gpt-4-0613"
81-
# assert attributes.get(SpanAttributes.LLM_PROMPTS) == json.dumps(messages_value)
81+
assert_prompt_in_events(streaming_span.events)
8282
assert attributes.get(SpanAttributes.LLM_IS_STREAMING) is True
8383

8484
events = streaming_span.events
@@ -135,7 +135,7 @@ async def test_async_chat_completion_streaming(exporter, async_openai_client):
135135
attributes.get(SpanAttributes.LLM_PATH) == APIS["CHAT_COMPLETION"]["ENDPOINT"]
136136
)
137137
assert attributes.get(SpanAttributes.LLM_RESPONSE_MODEL) == "gpt-4-0613"
138-
# assert attributes.get(SpanAttributes.LLM_PROMPTS) == json.dumps(messages_value)
138+
assert_prompt_in_events(streaming_span.events)
139139
assert attributes.get(SpanAttributes.LLM_IS_STREAMING) is True
140140

141141
events = streaming_span.events

src/tests/utils.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,12 @@ def assert_langtrace_attributes(attributes, vendor, vendor_type="llm"):
5757
assert attributes.get(SpanAttributes.LANGTRACE_VERSION) == v(LANGTRACE_SDK_NAME)
5858

5959

60-
def assert_prompt_in_events(events, prompt):
60+
def assert_prompt_in_events(
61+
events,
62+
):
6163
prompt_event = list(
6264
filter(lambda event: event.name == SpanAttributes.LLM_CONTENT_PROMPT, events)
6365
)
64-
print(
65-
json.loads(prompt_event[0].attributes.get(SpanAttributes.LLM_PROMPTS)),
66-
json.dumps(prompt),
67-
)
66+
print(prompt_event)
6867

6968
assert prompt_event
70-
71-
assert json.loads(
72-
prompt_event[0].attributes.get(SpanAttributes.LLM_PROMPTS)
73-
) == json.dumps(prompt)

0 commit comments

Comments
 (0)