|
23 | 23 | }, |
24 | 24 | { |
25 | 25 | "cell_type": "code", |
26 | | - "execution_count": 99, |
| 26 | + "execution_count": 21, |
27 | 27 | "metadata": {}, |
28 | 28 | "outputs": [], |
29 | 29 | "source": [ |
|
33 | 33 | }, |
34 | 34 | { |
35 | 35 | "cell_type": "code", |
36 | | - "execution_count": 100, |
| 36 | + "execution_count": 22, |
37 | 37 | "metadata": {}, |
38 | 38 | "outputs": [], |
39 | 39 | "source": [ |
|
73 | 73 | }, |
74 | 74 | { |
75 | 75 | "cell_type": "code", |
76 | | - "execution_count": 101, |
| 76 | + "execution_count": 23, |
77 | 77 | "metadata": {}, |
78 | 78 | "outputs": [], |
79 | 79 | "source": [ |
|
118 | 118 | }, |
119 | 119 | { |
120 | 120 | "cell_type": "code", |
121 | | - "execution_count": 102, |
| 121 | + "execution_count": 24, |
122 | 122 | "metadata": {}, |
123 | 123 | "outputs": [ |
124 | 124 | { |
125 | 125 | "name": "stdout", |
126 | 126 | "output_type": "stream", |
127 | 127 | "text": [ |
128 | | - "Let the model decide what function to call:\n", |
| 128 | + "Let the model decide what function to call:\n" |
| 129 | + ] |
| 130 | + }, |
| 131 | + { |
| 132 | + "name": "stdout", |
| 133 | + "output_type": "stream", |
| 134 | + "text": [ |
129 | 135 | "{\n", |
130 | | - " \"id\": \"chatcmpl-7e9QCkcvCtXbyiZwm3eKVHHQ2waXE\",\n", |
| 136 | + " \"id\": \"chatcmpl-7eT5XAUt5gGx6o3oEcdbrOHYD4HDp\",\n", |
131 | 137 | " \"object\": \"chat.completion\",\n", |
132 | | - " \"created\": 1689803692,\n", |
| 138 | + " \"created\": 1689879291,\n", |
133 | 139 | " \"model\": \"gpt-4\",\n", |
134 | 140 | " \"prompt_annotations\": [\n", |
135 | 141 | " {\n", |
|
162 | 168 | " \"role\": \"assistant\",\n", |
163 | 169 | " \"function_call\": {\n", |
164 | 170 | " \"name\": \"get_current_weather\",\n", |
165 | | - " \"arguments\": \"{\\n \\\"location\\\": \\\"San Francisco\\\"\\n}\"\n", |
| 171 | + " \"arguments\": \"{\\n \\\"location\\\": \\\"San Francisco, CA\\\"\\n}\"\n", |
166 | 172 | " }\n", |
167 | 173 | " },\n", |
168 | 174 | " \"content_filter_results\": {}\n", |
169 | 175 | " }\n", |
170 | 176 | " ],\n", |
171 | 177 | " \"usage\": {\n", |
172 | | - " \"completion_tokens\": 17,\n", |
| 178 | + " \"completion_tokens\": 19,\n", |
173 | 179 | " \"prompt_tokens\": 83,\n", |
174 | | - " \"total_tokens\": 100\n", |
| 180 | + " \"total_tokens\": 102\n", |
175 | 181 | " }\n", |
176 | 182 | "}\n", |
177 | 183 | "Don't call any function:\n", |
178 | 184 | "{\n", |
179 | | - " \"id\": \"chatcmpl-7e9QDkseJ33uGMacx6X4MEmS12BuT\",\n", |
| 185 | + " \"id\": \"chatcmpl-7eT5YoCPrCTz18wr8HyXruy7M9EPt\",\n", |
180 | 186 | " \"object\": \"chat.completion\",\n", |
181 | | - " \"created\": 1689803693,\n", |
| 187 | + " \"created\": 1689879292,\n", |
182 | 188 | " \"model\": \"gpt-4\",\n", |
183 | 189 | " \"prompt_annotations\": [\n", |
184 | 190 | " {\n", |
|
209 | 215 | " \"finish_reason\": \"stop\",\n", |
210 | 216 | " \"message\": {\n", |
211 | 217 | " \"role\": \"assistant\",\n", |
212 | | - " \"content\": \"Sure, let me just find that information for you.\"\n", |
| 218 | + " \"content\": \"Just one moment please, let me check the current weather in San Francisco for you.\"\n", |
213 | 219 | " },\n", |
214 | 220 | " \"content_filter_results\": {\n", |
215 | 221 | " \"hate\": {\n", |
|
232 | 238 | " }\n", |
233 | 239 | " ],\n", |
234 | 240 | " \"usage\": {\n", |
235 | | - " \"completion_tokens\": 11,\n", |
| 241 | + " \"completion_tokens\": 17,\n", |
236 | 242 | " \"prompt_tokens\": 84,\n", |
237 | | - " \"total_tokens\": 95\n", |
| 243 | + " \"total_tokens\": 101\n", |
238 | 244 | " }\n", |
239 | 245 | "}\n", |
240 | 246 | "Force a specific function call:\n", |
241 | 247 | "{\n", |
242 | | - " \"id\": \"chatcmpl-7e9QEsAAhn44pwg7ty9osRltgwXPb\",\n", |
| 248 | + " \"id\": \"chatcmpl-7eT5ZBn6q623O6nN2EOwjJTjtDWY3\",\n", |
243 | 249 | " \"object\": \"chat.completion\",\n", |
244 | | - " \"created\": 1689803694,\n", |
| 250 | + " \"created\": 1689879293,\n", |
245 | 251 | " \"model\": \"gpt-4\",\n", |
246 | 252 | " \"prompt_annotations\": [\n", |
247 | 253 | " {\n", |
|
274 | 280 | " \"role\": \"assistant\",\n", |
275 | 281 | " \"function_call\": {\n", |
276 | 282 | " \"name\": \"get_current_weather\",\n", |
277 | | - " \"arguments\": \"{\\n \\\"location\\\": \\\"San Francisco\\\"\\n}\"\n", |
| 283 | + " \"arguments\": \"{\\n \\\"location\\\": \\\"San Francisco, CA\\\"\\n}\"\n", |
278 | 284 | " }\n", |
279 | 285 | " },\n", |
280 | 286 | " \"content_filter_results\": {}\n", |
281 | 287 | " }\n", |
282 | 288 | " ],\n", |
283 | 289 | " \"usage\": {\n", |
284 | | - " \"completion_tokens\": 10,\n", |
| 290 | + " \"completion_tokens\": 12,\n", |
285 | 291 | " \"prompt_tokens\": 90,\n", |
286 | | - " \"total_tokens\": 100\n", |
| 292 | + " \"total_tokens\": 102\n", |
287 | 293 | " }\n", |
288 | 294 | "}\n" |
289 | 295 | ] |
|
295 | 301 | "print(\"Let the model decide what function to call:\")\n", |
296 | 302 | "print (get_function_call(first_message, \"auto\"))\n", |
297 | 303 | "\n", |
298 | | - "\n", |
299 | 304 | "# 'none' : Don't call any function \n", |
300 | 305 | "print(\"Don't call any function:\")\n", |
301 | 306 | "print (get_function_call(first_message, \"none\"))\n", |
|
324 | 329 | }, |
325 | 330 | { |
326 | 331 | "cell_type": "code", |
327 | | - "execution_count": 103, |
| 332 | + "execution_count": 25, |
328 | 333 | "metadata": {}, |
329 | 334 | "outputs": [], |
330 | 335 | "source": [ |
|
347 | 352 | }, |
348 | 353 | { |
349 | 354 | "cell_type": "code", |
350 | | - "execution_count": 104, |
| 355 | + "execution_count": 26, |
351 | 356 | "metadata": {}, |
352 | 357 | "outputs": [ |
353 | 358 | { |
354 | 359 | "data": { |
355 | 360 | "text/plain": [ |
356 | | - "'05:54:54 PM'" |
| 361 | + "'02:54:52 PM'" |
357 | 362 | ] |
358 | 363 | }, |
359 | | - "execution_count": 104, |
| 364 | + "execution_count": 26, |
360 | 365 | "metadata": {}, |
361 | 366 | "output_type": "execute_result" |
362 | 367 | } |
|
375 | 380 | }, |
376 | 381 | { |
377 | 382 | "cell_type": "code", |
378 | | - "execution_count": 105, |
| 383 | + "execution_count": 27, |
379 | 384 | "metadata": {}, |
380 | 385 | "outputs": [], |
381 | 386 | "source": [ |
|
408 | 413 | }, |
409 | 414 | { |
410 | 415 | "cell_type": "code", |
411 | | - "execution_count": 106, |
| 416 | + "execution_count": 28, |
412 | 417 | "metadata": {}, |
413 | 418 | "outputs": [ |
414 | 419 | { |
|
432 | 437 | }, |
433 | 438 | { |
434 | 439 | "cell_type": "code", |
435 | | - "execution_count": 107, |
| 440 | + "execution_count": 29, |
436 | 441 | "metadata": {}, |
437 | 442 | "outputs": [], |
438 | 443 | "source": [ |
|
457 | 462 | }, |
458 | 463 | { |
459 | 464 | "cell_type": "code", |
460 | | - "execution_count": 115, |
| 465 | + "execution_count": 30, |
461 | 466 | "metadata": {}, |
462 | 467 | "outputs": [ |
463 | 468 | { |
|
477 | 482 | "cell_type": "markdown", |
478 | 483 | "metadata": {}, |
479 | 484 | "source": [ |
480 | | - "## 3.0 Calling a Function using GPT\n", |
| 485 | + "## 3.0 Calling a function using GPT\n", |
481 | 486 | "\n", |
482 | 487 | "Steps for Function Calling: \n", |
483 | 488 | "\n", |
|
491 | 496 | }, |
492 | 497 | { |
493 | 498 | "cell_type": "code", |
494 | | - "execution_count": 116, |
| 499 | + "execution_count": 31, |
495 | 500 | "metadata": {}, |
496 | 501 | "outputs": [], |
497 | 502 | "source": [ |
|
555 | 560 | }, |
556 | 561 | { |
557 | 562 | "cell_type": "code", |
558 | | - "execution_count": 117, |
| 563 | + "execution_count": 32, |
559 | 564 | "metadata": {}, |
560 | 565 | "outputs": [], |
561 | 566 | "source": [ |
|
580 | 585 | }, |
581 | 586 | { |
582 | 587 | "cell_type": "code", |
583 | | - "execution_count": 118, |
| 588 | + "execution_count": 33, |
584 | 589 | "metadata": {}, |
585 | 590 | "outputs": [], |
586 | 591 | "source": [ |
|
657 | 662 | }, |
658 | 663 | { |
659 | 664 | "cell_type": "code", |
660 | | - "execution_count": 119, |
| 665 | + "execution_count": 34, |
661 | 666 | "metadata": {}, |
662 | 667 | "outputs": [ |
663 | 668 | { |
|
671 | 676 | "}\n", |
672 | 677 | "\n", |
673 | 678 | "Output of function call:\n", |
674 | | - "05:55:08 PM\n", |
| 679 | + "02:54:53 PM\n", |
675 | 680 | "\n", |
676 | 681 | "Messages in second request:\n", |
677 | 682 | "{'role': 'user', 'content': 'What time is it in New York?'}\n", |
678 | 683 | "{'role': 'assistant', 'name': 'get_current_time', 'content': '{\\n \"location\": \"America/New_York\"\\n}'}\n", |
679 | | - "{'role': 'function', 'name': 'get_current_time', 'content': '05:55:08 PM'}\n", |
| 684 | + "{'role': 'function', 'name': 'get_current_time', 'content': '02:54:53 PM'}\n", |
680 | 685 | "\n", |
681 | 686 | "{\n", |
682 | 687 | " \"role\": \"assistant\",\n", |
683 | | - " \"content\": \"The current time in New York is 05:55:08 PM.\"\n", |
| 688 | + " \"content\": \"It's 2:54 PM in New York.\"\n", |
684 | 689 | "}\n" |
685 | 690 | ] |
686 | 691 | } |
|
701 | 706 | }, |
702 | 707 | { |
703 | 708 | "cell_type": "code", |
704 | | - "execution_count": 120, |
| 709 | + "execution_count": 35, |
705 | 710 | "metadata": {}, |
706 | 711 | "outputs": [], |
707 | 712 | "source": [ |
|
781 | 786 | }, |
782 | 787 | { |
783 | 788 | "cell_type": "code", |
784 | | - "execution_count": 121, |
| 789 | + "execution_count": 36, |
785 | 790 | "metadata": {}, |
786 | 791 | "outputs": [ |
787 | 792 | { |
|
0 commit comments