Skip to content

Commit 8a9efcf

Browse files
committed
fix: missing code
1 parent 5aa9184 commit 8a9efcf

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

llm_observability_examples.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ def main_sync():
3030
try:
3131
basic_openai_call(distinct_id, trace_id, properties)
3232
streaming_openai_call(distinct_id, trace_id, properties)
33-
non_instrumented_openai_call()
33+
image_openai_call()
34+
embedding_openai_call()
3435
except Exception as e:
3536
print("Error during OpenAI call:", str(e))
3637

@@ -44,6 +45,8 @@ async def main_async():
4445
try:
4546
await basic_async_openai_call(distinct_id, trace_id, properties)
4647
await streaming_async_openai_call(distinct_id, trace_id, properties)
48+
await embedding_async_openai_call()
49+
await image_async_openai_call()
4750
except Exception as e:
4851
print("Error during OpenAI call:", str(e))
4952

@@ -134,11 +137,29 @@ async def streaming_async_openai_call(distinct_id, trace_id, properties):
134137
return response
135138

136139

137-
def non_instrumented_openai_call():
140+
# none instrumented
141+
def image_openai_call():
138142
response = openai_client.images.generate(model="dall-e-3", prompt="A cute baby hedgehog", n=1, size="1024x1024")
139143
print(response)
140144
return response
141145

146+
# none instrumented
147+
async def image_async_openai_call():
148+
response = await async_openai_client.images.generate(model="dall-e-3", prompt="A cute baby hedgehog", n=1, size="1024x1024")
149+
print(response)
150+
return response
151+
152+
153+
def embedding_openai_call():
154+
response = openai_client.embeddings.create(input="The hedgehog is cute", model="text-embedding-3-small")
155+
print(response)
156+
return response
157+
158+
async def embedding_async_openai_call():
159+
response = await async_openai_client.embeddings.create(input="The hedgehog is cute", model="text-embedding-3-small")
160+
print(response)
161+
return response
162+
142163

143164
# HOW TO RUN:
144165
# comment out one of these to run the other

posthog/ai/openai/openai.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,4 @@ def _capture_streaming_event(
167167
distinct_id=posthog_distinct_id or posthog_trace_id,
168168
event="$ai_generation",
169169
properties=event_properties,
170-
)
170+
)

posthog/ai/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def call_llm_and_track_usage(
103103
# send the event to posthog
104104
if hasattr(ph_client, "capture") and callable(ph_client.capture):
105105
ph_client.capture(
106-
distinct_id=distinct_id,
106+
distinct_id=posthog_distinct_id or posthog_trace_id,
107107
event="$ai_generation",
108108
properties=event_properties,
109109
)

0 commit comments

Comments
 (0)