|
112 | 112 | "outputs": [], |
113 | 113 | "source": [ |
114 | 114 | "# Responses API - new unified interface with enhanced metadata\n", |
115 | | - "if hasattr(client, 'responses'):\n", |
116 | | - " response = client.responses.create(\n", |
117 | | - " model=\"gpt-4o-mini\",\n", |
118 | | - " input=\"What is 3 + 3?\",\n", |
119 | | - " max_output_tokens=50\n", |
120 | | - " )\n", |
121 | | - " \n", |
122 | | - " # Response is automatically traced\n", |
123 | | - " response\n", |
124 | | - "else:\n", |
125 | | - " \"Responses API not available in this OpenAI version\"" |
126 | | - ] |
127 | | - }, |
128 | | - { |
129 | | - "cell_type": "markdown", |
130 | | - "id": "streaming-example", |
131 | | - "metadata": {}, |
132 | | - "source": [ |
133 | | - "## 5. Streaming example" |
134 | | - ] |
135 | | - }, |
136 | | - { |
137 | | - "cell_type": "code", |
138 | | - "execution_count": null, |
139 | | - "id": "streaming-code", |
140 | | - "metadata": {}, |
141 | | - "outputs": [], |
142 | | - "source": [ |
143 | | - "# Streaming works with both APIs\n", |
144 | | - "stream = client.chat.completions.create(\n", |
| 115 | + "response = client.responses.create(\n", |
145 | 116 | " model=\"gpt-4o-mini\",\n", |
146 | | - " messages=[{\"role\": \"user\", \"content\": \"Count from 1 to 3\"}],\n", |
147 | | - " stream=True\n", |
| 117 | + " input=\"What is 3 + 3?\",\n", |
| 118 | + " max_output_tokens=50\n", |
148 | 119 | ")\n", |
149 | | - "response = ''\n", |
150 | 120 | "\n", |
151 | | - "# Consume the stream - automatically traced\n", |
152 | | - "for chunk in stream:\n", |
153 | | - " if chunk.choices[0].delta.content:\n", |
154 | | - " response += chunk.choices[0].delta.content\n", |
| 121 | + "# Response is automatically traced\n", |
155 | 122 | "response" |
156 | 123 | ] |
157 | | - }, |
158 | | - { |
159 | | - "cell_type": "markdown", |
160 | | - "id": "conclusion", |
161 | | - "metadata": {}, |
162 | | - "source": [ |
163 | | - "## Summary\n", |
164 | | - "\n", |
165 | | - "That's it! The same `trace_openai()` function now supports:\n", |
166 | | - "\n", |
167 | | - "- ✅ **Chat Completions API** - Full backward compatibility\n", |
168 | | - "- ✅ **Responses API** - New unified interface with enhanced metadata\n", |
169 | | - "- ✅ **Streaming** - Both APIs support streaming\n", |
170 | | - "- ✅ **Function calling** - Tool calls work with both APIs\n", |
171 | | - "- ✅ **Async support** - Use `trace_async_openai()` for async clients\n", |
172 | | - "\n", |
173 | | - "All traces are automatically sent to Openlayer with proper API type differentiation!" |
174 | | - ] |
175 | 124 | } |
176 | 125 | ], |
177 | 126 | "metadata": { |
|
0 commit comments