Skip to content

Commit b79dd9b

Browse files
chore: remove OpenAI responses API tracing notebook and merge its content with existing OpenAI tracing example
1 parent 4857ace commit b79dd9b

File tree

2 files changed

+55
-151
lines changed

2 files changed

+55
-151
lines changed

examples/tracing/openai/openai_responses_api_tracing.ipynb

Lines changed: 0 additions & 147 deletions
This file was deleted.

examples/tracing/openai/openai_tracing.ipynb

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@
3939
"outputs": [],
4040
"source": [
4141
"import os\n",
42-
"\n",
4342
"import openai\n",
4443
"\n",
44+
"from pydantic import BaseModel\n",
45+
"\n",
4546
"# OpenAI env variables\n",
4647
"os.environ[\"OPENAI_API_KEY\"] = \"YOUR_OPENAI_API_KEY_HERE\"\n",
4748
"\n",
@@ -86,6 +87,14 @@
8687
"That's it! Now you can continue using the traced OpenAI client normally. The data is automatically published to Openlayer and you can start creating tests around it!"
8788
]
8889
},
90+
{
91+
"cell_type": "markdown",
92+
"id": "fb5ebdad",
93+
"metadata": {},
94+
"source": [
95+
"### 3.1 Chat Completions API"
96+
]
97+
},
8998
{
9099
"cell_type": "code",
91100
"execution_count": null,
@@ -104,12 +113,54 @@
104113
"id": "abaf6987-c257-4f0d-96e7-3739b24c7206",
105114
"metadata": {},
106115
"outputs": [],
107-
"source": []
116+
"source": [
117+
"class Person(BaseModel):\n",
118+
" name: str\n",
119+
" age: int\n",
120+
" occupation: str\n",
121+
"\n",
122+
"# Parse method automatically returns structured Pydantic object\n",
123+
"completion = openai_client.chat.completions.parse(\n",
124+
" model=\"gpt-4o\",\n",
125+
" messages=[\n",
126+
" {\"role\": \"user\", \"content\": \"Extract: John Doe is 30 years old and works as a software engineer\"}\n",
127+
" ],\n",
128+
" response_format=Person,\n",
129+
")\n",
130+
"\n",
131+
"completion.choices[0].message.parsed"
132+
]
133+
},
134+
{
135+
"cell_type": "markdown",
136+
"id": "4e6fb396",
137+
"metadata": {},
138+
"source": [
139+
"### 3.2 Responses API"
140+
]
141+
},
142+
{
143+
"cell_type": "code",
144+
"execution_count": null,
145+
"id": "21369c42",
146+
"metadata": {},
147+
"outputs": [],
148+
"source": [
149+
"# Responses API - new unified interface with enhanced metadata\n",
150+
"response = openai_client.responses.create(\n",
151+
" model=\"gpt-4o-mini\",\n",
152+
" input=\"What is 3 + 3?\",\n",
153+
" max_output_tokens=50\n",
154+
")\n",
155+
"\n",
156+
"# Response is automatically traced\n",
157+
"response"
158+
]
108159
}
109160
],
110161
"metadata": {
111162
"kernelspec": {
112-
"display_name": "Python 3 (ipykernel)",
163+
"display_name": "base",
113164
"language": "python",
114165
"name": "python3"
115166
},
@@ -123,7 +174,7 @@
123174
"name": "python",
124175
"nbconvert_exporter": "python",
125176
"pygments_lexer": "ipython3",
126-
"version": "3.9.18"
177+
"version": "3.12.7"
127178
}
128179
},
129180
"nbformat": 4,

0 commit comments

Comments
 (0)