You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: llm_observability_examples.py
+23-5Lines changed: 23 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -21,6 +21,7 @@
21
21
posthog_client=posthog,
22
22
)
23
23
24
+
24
25
defmain_sync():
25
26
trace_id=str(uuid.uuid4())
26
27
print("Trace ID:", trace_id)
@@ -31,6 +32,7 @@ def main_sync():
31
32
exceptExceptionase:
32
33
print("Error during OpenAI call:", str(e))
33
34
35
+
34
36
asyncdefmain_async():
35
37
try:
36
38
awaitbasic_async_openai_call()
@@ -42,7 +44,10 @@ async def main_async():
42
44
defbasic_openai_call():
43
45
response=openai_client.chat.completions.create(
44
46
model="gpt-4o-mini",
45
-
messages=[{"role": "system", "content": "You are a complex problem solver."}, {"role": "user", "content": "Explain quantum computing in simple terms."}],
47
+
messages=[
48
+
{"role": "system", "content": "You are a complex problem solver."},
49
+
{"role": "user", "content": "Explain quantum computing in simple terms."},
50
+
],
46
51
max_tokens=100,
47
52
temperature=0.7,
48
53
)
@@ -52,10 +57,14 @@ def basic_openai_call():
52
57
print("No response or unexpected format returned.")
messages=[{"role": "system", "content": "You are a complex problem solver."}, {"role": "user", "content": "Explain quantum computing in simple terms."}],
64
+
messages=[
65
+
{"role": "system", "content": "You are a complex problem solver."},
66
+
{"role": "user", "content": "Explain quantum computing in simple terms."},
print("No response or unexpected format returned.")
66
75
returnresponse
67
76
77
+
68
78
defstreaming_openai_call():
69
79
response=openai_client.chat.completions.create(
70
80
model="gpt-4o-mini",
71
-
messages=[{"role": "system", "content": "You are a complex problem solver."}, {"role": "user", "content": "Explain quantum computing in simple terms."}],
81
+
messages=[
82
+
{"role": "system", "content": "You are a complex problem solver."},
83
+
{"role": "user", "content": "Explain quantum computing in simple terms."},
messages=[{"role": "system", "content": "You are a complex problem solver."}, {"role": "user", "content": "Explain quantum computing in simple terms."}],
99
+
messages=[
100
+
{"role": "system", "content": "You are a complex problem solver."},
101
+
{"role": "user", "content": "Explain quantum computing in simple terms."},
0 commit comments