Skip to content

Commit f020976

Browse files
refactor: improve OpenAI responses API tracing in notebook example
1 parent 82f5365 commit f020976

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

examples/tracing/openai/openai_responses_api_tracing.ipynb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"outputs": [],
4040
"source": [
4141
"import os\n",
42+
"\n",
4243
"import openai\n",
4344
"\n",
4445
"# OpenAI API key\n",
@@ -92,7 +93,7 @@
9293
" max_tokens=50\n",
9394
")\n",
9495
"\n",
95-
"print(\"Chat Completions:\", response.choices[0].message.content)"
96+
"response.choices[0].message.content"
9697
]
9798
},
9899
{
@@ -118,12 +119,10 @@
118119
" max_output_tokens=50\n",
119120
" )\n",
120121
" \n",
121-
" # Extract response text\n",
122-
" if response.output and len(response.output) > 0:\n",
123-
" result = response.output[0].content[0].text\n",
124-
" print(\"Responses API:\", result)\n",
125-
" print(f\"Response ID: {response.id}\")\nelse:\n",
126-
" print(\"Responses API not available in this OpenAI version\")"
122+
" # Response is automatically traced\n",
123+
" response\n",
124+
"else:\n",
125+
" \"Responses API not available in this OpenAI version\""
127126
]
128127
},
129128
{
@@ -148,10 +147,12 @@
148147
" stream=True\n",
149148
")\n",
150149
"\n",
151-
"print(\"Streaming response: \", end=\"\")\n",
150+
"# Consume the stream - automatically traced\n",
152151
"for chunk in stream:\n",
153152
" if chunk.choices[0].delta.content:\n",
154-
" print(chunk.choices[0].delta.content, end=\"\")\nprint(\"\\n✓ All requests automatically traced to Openlayer!\")"
153+
" pass # Process chunks as needed\n",
154+
"\n",
155+
"# ✓ All requests automatically traced to Openlayer!"
155156
]
156157
},
157158
{
@@ -194,4 +195,4 @@
194195
},
195196
"nbformat": 4,
196197
"nbformat_minor": 5
197-
}
198+
}

0 commit comments

Comments
 (0)