|
20 | 20 | }, |
21 | 21 | { |
22 | 22 | "cell_type": "code", |
23 | | - "execution_count": null, |
| 23 | + "execution_count": 1, |
24 | 24 | "metadata": {}, |
25 | | - "outputs": [], |
| 25 | + "outputs": [ |
| 26 | + { |
| 27 | + "name": "stdout", |
| 28 | + "output_type": "stream", |
| 29 | + "text": [ |
| 30 | + "Note: you may need to restart the kernel to use updated packages.\n", |
| 31 | + "Note: you may need to restart the kernel to use updated packages.\n" |
| 32 | + ] |
| 33 | + } |
| 34 | + ], |
26 | 35 | "source": [ |
27 | 36 | "%pip install openai --quiet\n", |
28 | 37 | "%pip install python-dotenv --quiet" |
|
41 | 50 | }, |
42 | 51 | { |
43 | 52 | "cell_type": "code", |
44 | | - "execution_count": null, |
| 53 | + "execution_count": 2, |
45 | 54 | "metadata": {}, |
46 | 55 | "outputs": [], |
47 | 56 | "source": [ |
|
75 | 84 | }, |
76 | 85 | { |
77 | 86 | "cell_type": "code", |
78 | | - "execution_count": null, |
| 87 | + "execution_count": 3, |
79 | 88 | "metadata": {}, |
80 | | - "outputs": [], |
| 89 | + "outputs": [ |
| 90 | + { |
| 91 | + "name": "stdout", |
| 92 | + "output_type": "stream", |
| 93 | + "text": [ |
| 94 | + "The capital of France is Paris.\n" |
| 95 | + ] |
| 96 | + } |
| 97 | + ], |
81 | 98 | "source": [ |
82 | 99 | "\n", |
83 | 100 | "response = client.chat.completions.create(\n", |
|
115 | 132 | }, |
116 | 133 | { |
117 | 134 | "cell_type": "code", |
118 | | - "execution_count": null, |
| 135 | + "execution_count": 4, |
119 | 136 | "metadata": {}, |
120 | | - "outputs": [], |
| 137 | + "outputs": [ |
| 138 | + { |
| 139 | + "name": "stdout", |
| 140 | + "output_type": "stream", |
| 141 | + "text": [ |
| 142 | + "The capital of Spain is Madrid.\n" |
| 143 | + ] |
| 144 | + } |
| 145 | + ], |
121 | 146 | "source": [ |
122 | 147 | "# Call the chat completion API\n", |
123 | 148 | "response = client.chat.completions.create(\n", |
|
162 | 187 | }, |
163 | 188 | { |
164 | 189 | "cell_type": "code", |
165 | | - "execution_count": null, |
| 190 | + "execution_count": 5, |
166 | 191 | "metadata": {}, |
167 | | - "outputs": [], |
| 192 | + "outputs": [ |
| 193 | + { |
| 194 | + "name": "stdout", |
| 195 | + "output_type": "stream", |
| 196 | + "text": [ |
| 197 | + "The image features a cute, fluffy puppy with a golden coat seated on a textured mat. In front of the puppy is a black and gray food bowl, which reflects the surroundings. The floor appears to be wooden, and there are elements of a cozy environment visible in the background, including a brick wall and wooden furniture. The overall atmosphere of the image is warm and inviting.\n" |
| 198 | + ] |
| 199 | + } |
| 200 | + ], |
168 | 201 | "source": [ |
169 | 202 | "import base64\n", |
170 | 203 | "model_name = \"gpt-4o-mini\"\n", |
|
237 | 270 | }, |
238 | 271 | { |
239 | 272 | "cell_type": "code", |
240 | | - "execution_count": null, |
| 273 | + "execution_count": 7, |
241 | 274 | "metadata": {}, |
242 | | - "outputs": [], |
| 275 | + "outputs": [ |
| 276 | + { |
| 277 | + "name": "stdout", |
| 278 | + "output_type": "stream", |
| 279 | + "text": [ |
| 280 | + "Exercising every day offers numerous benefits for both your physical and mental well-being. Here are five compelling reasons to make daily exercise a part of your routine:\n", |
| 281 | + "\n", |
| 282 | + "1. **Improved Physical Health**: Regular exercise strengthens your heart, improves circulation, boosts your immune system, and helps maintain a healthy weight. It can lower the risk of chronic diseases such as heart disease, type 2 diabetes, and certain cancers.\n", |
| 283 | + "\n", |
| 284 | + "2. **Enhanced Mental Well-being**: Physical activity releases endorphins, often referred to as \"feel-good\" hormones. This can reduce feelings of stress, anxiety, and depression while improving your mood and overall emotional health.\n", |
| 285 | + "\n", |
| 286 | + "3. **Increased Energy Levels**: Contrary to what one might expect, regular exercise can lead to increased energy levels. It improves your stamina and reduces fatigue, making daily tasks easier and more enjoyable.\n", |
| 287 | + "\n", |
| 288 | + "4. **Better Sleep Quality**: Engaging in physical activity can help you fall asleep faster and deepen your sleep. Exercise helps regulate your sleep patterns and can alleviate issues like insomnia.\n", |
| 289 | + "\n", |
| 290 | + "5. **Social Connections and Routine**: Exercising daily can provide opportunities for social interaction, whether through group classes, team sports, or simply exercising with friends. Additionally, establishing a regular exercise routine can enhance your sense of discipline and structure in your daily life.\n", |
| 291 | + "\n", |
| 292 | + "Incorporating daily exercise can have a profound impact on multiple dimensions of your health and well-being." |
| 293 | + ] |
| 294 | + } |
| 295 | + ], |
243 | 296 | "source": [ |
244 | 297 | "# Call the chat completion API\n", |
245 | 298 | "response = client.chat.completions.create(\n", |
|
259 | 312 | "\n", |
260 | 313 | "# Print the streamed response\n", |
261 | 314 | "for update in response:\n", |
262 | | - " if update.choices[0].delta.content:\n", |
263 | | - " print(update.choices[0].delta.content, end=\"\")\n" |
| 315 | + " if update.choices:\n", |
| 316 | + " content = update.choices[0].delta.content\n", |
| 317 | + " if content:\n", |
| 318 | + " print(content, end=\"\")\n" |
264 | 319 | ] |
265 | 320 | }, |
266 | 321 | { |
|
276 | 331 | }, |
277 | 332 | { |
278 | 333 | "cell_type": "code", |
279 | | - "execution_count": null, |
| 334 | + "execution_count": 8, |
280 | 335 | "metadata": {}, |
281 | | - "outputs": [], |
| 336 | + "outputs": [ |
| 337 | + { |
| 338 | + "name": "stdout", |
| 339 | + "output_type": "stream", |
| 340 | + "text": [ |
| 341 | + "Calling function `get_flight_info` with arguments {'origin_city': 'Seattle', 'destination_city': 'Miami'}\n", |
| 342 | + "Function returned = {\"airline\": \"Delta\", \"flight_number\": \"DL123\", \"flight_date\": \"May 7th, 2024\", \"flight_time\": \"10:00AM\"}\n", |
| 343 | + "Model response = The next flight from Seattle to Miami is with Delta Airlines. Here are the details:\n", |
| 344 | + "\n", |
| 345 | + "- **Flight Number**: DL123\n", |
| 346 | + "- **Date**: May 7th, 2024\n", |
| 347 | + "- **Time**: 10:00 AM\n" |
| 348 | + ] |
| 349 | + } |
| 350 | + ], |
282 | 351 | "source": [ |
283 | 352 | "import json\n", |
284 | 353 | "\n", |
|
404 | 473 | ], |
405 | 474 | "metadata": { |
406 | 475 | "kernelspec": { |
407 | | - "display_name": "gh-cookbook", |
| 476 | + "display_name": "Python 3", |
408 | 477 | "language": "python", |
409 | 478 | "name": "python3" |
410 | 479 | }, |
|
0 commit comments