Skip to content

Commit 6d8368d

Browse files
andrewm4894claude
andcommitted
Add \$ai_lib_metadata to sync/async paths and tests
- Added \$ai_lib_metadata to call_llm_and_track_usage (sync) - Added \$ai_lib_metadata to call_llm_and_track_usage_async (async) - Added test assertion in test_basic_completion - Placed metadata at end of properties for consistency All tests pass successfully. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 77a64f3 commit 6d8368d

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

posthog/ai/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@ def call_llm_and_track_usage(
320320
ph_client, posthog_privacy_mode, kwargs.get("instructions")
321321
)
322322

323+
event_properties["$ai_lib_metadata"] = {"schema": "v1", "frameworks": [{"name": provider}]}
324+
323325
# send the event to posthog
324326
if hasattr(ph_client, "capture") and callable(ph_client.capture):
325327
ph_client.capture(
@@ -423,6 +425,8 @@ async def call_llm_and_track_usage_async(
423425
ph_client, posthog_privacy_mode, kwargs.get("instructions")
424426
)
425427

428+
event_properties["$ai_lib_metadata"] = {"schema": "v1", "frameworks": [{"name": provider}]}
429+
426430
# send the event to posthog
427431
if hasattr(ph_client, "capture") and callable(ph_client.capture):
428432
ph_client.capture(

posthog/test/ai/openai/test_openai.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,10 @@ def test_basic_completion(mock_client, mock_openai_response):
482482

483483
assert call_args["distinct_id"] == "test-id"
484484
assert call_args["event"] == "$ai_generation"
485+
assert props["$ai_lib_metadata"] == {
486+
"schema": "v1",
487+
"frameworks": [{"name": "openai"}],
488+
}
485489
assert props["$ai_provider"] == "openai"
486490
assert props["$ai_model"] == "gpt-4"
487491
assert props["$ai_input"] == [{"role": "user", "content": "Hello"}]

0 commit comments

Comments
 (0)