Skip to content

Commit 3a9b5c2

Browse files
committed
fix: callback test to support destructed porps
1 parent 4928de1 commit 3a9b5c2

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

posthog/test/ai/langchain/test_callbacks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def test_metadata(mock_client):
335335
first_call_props = first_call_args["properties"]
336336
assert first_call_args["event"] == "$ai_generation"
337337
assert first_call_props["$ai_trace_id"] == "test-trace-id"
338-
assert first_call_props["$ai_posthog_properties"] == {"foo": "bar"}
338+
assert first_call_props["$foo"] == "bar"
339339
assert first_call_props["$ai_input"] == [{"role": "user", "content": "Foo"}]
340340
assert first_call_props["$ai_output"] == {"choices": [{"role": "assistant", "content": "Bar"}]}
341341
assert first_call_props["$ai_http_status"] == 200
@@ -422,7 +422,7 @@ def test_openai_chain(mock_client):
422422
assert first_call_props["$ai_trace_id"] == "test-trace-id"
423423
assert first_call_props["$ai_provider"] == "openai"
424424
assert first_call_props["$ai_model"] == "gpt-4o-mini"
425-
assert first_call_props["$ai_posthog_properties"] == {"foo": "bar"}
425+
assert first_call_props["$foo"] == "bar"
426426

427427
# langchain-openai for langchain v3
428428
if "max_completion_tokens" in first_call_props["$ai_model_parameters"]:

posthog/test/ai/openai/test_openai.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,23 @@ def test_basic_completion(mock_client, mock_openai_response):
7373

7474
assert response == mock_openai_response
7575
assert mock_client.capture.call_count == 1
76-
76+
7777
call_args = mock_client.capture.call_args[1]
7878
props = call_args["properties"]
79-
79+
8080
assert call_args["distinct_id"] == "test-id"
8181
assert call_args["event"] == "$ai_generation"
8282
assert props["$ai_provider"] == "openai"
8383
assert props["$ai_model"] == "gpt-4"
8484
assert props["$ai_input"] == [{"role": "user", "content": "Hello"}]
85-
assert props["$ai_output"] == {
86-
"choices": [{"role": "assistant", "content": "Test response"}]
87-
}
85+
assert props["$ai_output"] == {"choices": [{"role": "assistant", "content": "Test response"}]}
8886
assert props["$ai_input_tokens"] == 20
8987
assert props["$ai_output_tokens"] == 10
9088
assert props["$ai_http_status"] == 200
9189
assert props["foo"] == "bar"
9290
assert isinstance(props["$ai_latency"], float)
9391

92+
9493
def test_embeddings(mock_client, mock_embedding_response):
9594
with patch("openai.resources.embeddings.Embeddings.create", return_value=mock_embedding_response):
9695
client = OpenAI(api_key="test-key", posthog_client=mock_client)
@@ -103,10 +102,10 @@ def test_embeddings(mock_client, mock_embedding_response):
103102

104103
assert response == mock_embedding_response
105104
assert mock_client.capture.call_count == 1
106-
105+
107106
call_args = mock_client.capture.call_args[1]
108107
props = call_args["properties"]
109-
108+
110109
assert call_args["distinct_id"] == "test-id"
111110
assert call_args["event"] == "$ai_embedding"
112111
assert props["$ai_provider"] == "openai"
@@ -115,4 +114,4 @@ def test_embeddings(mock_client, mock_embedding_response):
115114
assert props["$ai_input_tokens"] == 10
116115
assert props["$ai_http_status"] == 200
117116
assert props["foo"] == "bar"
118-
assert isinstance(props["$ai_latency"], float)
117+
assert isinstance(props["$ai_latency"], float)

0 commit comments

Comments
 (0)