Skip to content

Commit e0f1713

Browse files
committed
fix: if no response, return output to avoid crash
1 parent 51074bc commit e0f1713

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

llm_observability_examples.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def main_sync():
3131
try:
3232
basic_openai_call(distinct_id, trace_id, properties)
3333
# streaming_openai_call(distinct_id, trace_id, properties)
34-
non_instrumented_openai_call()
34+
# non_instrumented_openai_call()
3535
except Exception as e:
3636
print("Error during OpenAI call:", str(e))
3737

@@ -62,6 +62,7 @@ def basic_openai_call(distinct_id, trace_id, properties):
6262
posthog_trace_id=trace_id,
6363
posthog_properties=properties,
6464
)
65+
print(response)
6566
if response and response.choices:
6667
print("OpenAI response:", response.choices[0].message.content)
6768
else:

posthog/ai/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ def format_response(response):
3030
Format a regular (non-streaming) response.
3131
"""
3232
output = {"choices": []}
33+
if response is None:
34+
return output
3335
for choice in response.choices:
3436
if choice.message.content:
3537
output["choices"].append(

0 commit comments

Comments
 (0)