|
23 | 23 | }, |
24 | 24 | { |
25 | 25 | "cell_type": "code", |
26 | | - "execution_count": 99, |
| 26 | + "execution_count": 1, |
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": 17, |
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": 18, |
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": 19, |
122 | 122 | "metadata": {}, |
123 | 123 | "outputs": [ |
124 | 124 | { |
|
127 | 127 | "text": [ |
128 | 128 | "Let the model decide what function to call:\n", |
129 | 129 | "{\n", |
130 | | - " \"id\": \"chatcmpl-7e9QCkcvCtXbyiZwm3eKVHHQ2waXE\",\n", |
| 130 | + " \"id\": \"chatcmpl-7e9d5AFNbVuiil0l0IWCKSX0luNPV\",\n", |
131 | 131 | " \"object\": \"chat.completion\",\n", |
132 | | - " \"created\": 1689803692,\n", |
| 132 | + " \"created\": 1689804491,\n", |
133 | 133 | " \"model\": \"gpt-4\",\n", |
134 | 134 | " \"prompt_annotations\": [\n", |
135 | 135 | " {\n", |
|
176 | 176 | "}\n", |
177 | 177 | "Don't call any function:\n", |
178 | 178 | "{\n", |
179 | | - " \"id\": \"chatcmpl-7e9QDkseJ33uGMacx6X4MEmS12BuT\",\n", |
| 179 | + " \"id\": \"chatcmpl-7e9d6AQAqykfQ8cnGlrkJM5zEZGSl\",\n", |
180 | 180 | " \"object\": \"chat.completion\",\n", |
181 | | - " \"created\": 1689803693,\n", |
| 181 | + " \"created\": 1689804492,\n", |
182 | 182 | " \"model\": \"gpt-4\",\n", |
183 | 183 | " \"prompt_annotations\": [\n", |
184 | 184 | " {\n", |
|
209 | 209 | " \"finish_reason\": \"stop\",\n", |
210 | 210 | " \"message\": {\n", |
211 | 211 | " \"role\": \"assistant\",\n", |
212 | | - " \"content\": \"Sure, let me just find that information for you.\"\n", |
| 212 | + " \"content\": \"Sure, let me check that for you.\\n\\nI am using the function `get_current_weather` for this purpose.\"\n", |
213 | 213 | " },\n", |
214 | 214 | " \"content_filter_results\": {\n", |
215 | 215 | " \"hate\": {\n", |
|
232 | 232 | " }\n", |
233 | 233 | " ],\n", |
234 | 234 | " \"usage\": {\n", |
235 | | - " \"completion_tokens\": 11,\n", |
| 235 | + " \"completion_tokens\": 23,\n", |
236 | 236 | " \"prompt_tokens\": 84,\n", |
237 | | - " \"total_tokens\": 95\n", |
| 237 | + " \"total_tokens\": 107\n", |
238 | 238 | " }\n", |
239 | 239 | "}\n", |
240 | 240 | "Force a specific function call:\n", |
241 | 241 | "{\n", |
242 | | - " \"id\": \"chatcmpl-7e9QEsAAhn44pwg7ty9osRltgwXPb\",\n", |
| 242 | + " \"id\": \"chatcmpl-7e9d7bOcTyEe3mA9rBhAPflFEqYX3\",\n", |
243 | 243 | " \"object\": \"chat.completion\",\n", |
244 | | - " \"created\": 1689803694,\n", |
| 244 | + " \"created\": 1689804493,\n", |
245 | 245 | " \"model\": \"gpt-4\",\n", |
246 | 246 | " \"prompt_annotations\": [\n", |
247 | 247 | " {\n", |
|
274 | 274 | " \"role\": \"assistant\",\n", |
275 | 275 | " \"function_call\": {\n", |
276 | 276 | " \"name\": \"get_current_weather\",\n", |
277 | | - " \"arguments\": \"{\\n \\\"location\\\": \\\"San Francisco\\\"\\n}\"\n", |
| 277 | + " \"arguments\": \"{\\n \\\"location\\\": \\\"San Francisco, CA\\\"\\n}\"\n", |
278 | 278 | " }\n", |
279 | 279 | " },\n", |
280 | 280 | " \"content_filter_results\": {}\n", |
281 | 281 | " }\n", |
282 | 282 | " ],\n", |
283 | 283 | " \"usage\": {\n", |
284 | | - " \"completion_tokens\": 10,\n", |
| 284 | + " \"completion_tokens\": 12,\n", |
285 | 285 | " \"prompt_tokens\": 90,\n", |
286 | | - " \"total_tokens\": 100\n", |
| 286 | + " \"total_tokens\": 102\n", |
287 | 287 | " }\n", |
288 | 288 | "}\n" |
289 | 289 | ] |
|
295 | 295 | "print(\"Let the model decide what function to call:\")\n", |
296 | 296 | "print (get_function_call(first_message, \"auto\"))\n", |
297 | 297 | "\n", |
298 | | - "\n", |
299 | 298 | "# 'none' : Don't call any function \n", |
300 | 299 | "print(\"Don't call any function:\")\n", |
301 | 300 | "print (get_function_call(first_message, \"none\"))\n", |
|
324 | 323 | }, |
325 | 324 | { |
326 | 325 | "cell_type": "code", |
327 | | - "execution_count": 103, |
| 326 | + "execution_count": 20, |
328 | 327 | "metadata": {}, |
329 | 328 | "outputs": [], |
330 | 329 | "source": [ |
|
347 | 346 | }, |
348 | 347 | { |
349 | 348 | "cell_type": "code", |
350 | | - "execution_count": 104, |
| 349 | + "execution_count": 6, |
351 | 350 | "metadata": {}, |
352 | 351 | "outputs": [ |
353 | 352 | { |
354 | 353 | "data": { |
355 | 354 | "text/plain": [ |
356 | | - "'05:54:54 PM'" |
| 355 | + "'06:07:59 PM'" |
357 | 356 | ] |
358 | 357 | }, |
359 | | - "execution_count": 104, |
| 358 | + "execution_count": 6, |
360 | 359 | "metadata": {}, |
361 | 360 | "output_type": "execute_result" |
362 | 361 | } |
|
375 | 374 | }, |
376 | 375 | { |
377 | 376 | "cell_type": "code", |
378 | | - "execution_count": 105, |
| 377 | + "execution_count": 7, |
379 | 378 | "metadata": {}, |
380 | 379 | "outputs": [], |
381 | 380 | "source": [ |
|
408 | 407 | }, |
409 | 408 | { |
410 | 409 | "cell_type": "code", |
411 | | - "execution_count": 106, |
| 410 | + "execution_count": 8, |
412 | 411 | "metadata": {}, |
413 | 412 | "outputs": [ |
414 | 413 | { |
|
432 | 431 | }, |
433 | 432 | { |
434 | 433 | "cell_type": "code", |
435 | | - "execution_count": 107, |
| 434 | + "execution_count": 9, |
436 | 435 | "metadata": {}, |
437 | 436 | "outputs": [], |
438 | 437 | "source": [ |
|
457 | 456 | }, |
458 | 457 | { |
459 | 458 | "cell_type": "code", |
460 | | - "execution_count": 115, |
| 459 | + "execution_count": 10, |
461 | 460 | "metadata": {}, |
462 | 461 | "outputs": [ |
463 | 462 | { |
|
477 | 476 | "cell_type": "markdown", |
478 | 477 | "metadata": {}, |
479 | 478 | "source": [ |
480 | | - "## 3.0 Calling a Function using GPT\n", |
| 479 | + "## 3.0 Calling a function using GPT\n", |
481 | 480 | "\n", |
482 | 481 | "Steps for Function Calling: \n", |
483 | 482 | "\n", |
|
491 | 490 | }, |
492 | 491 | { |
493 | 492 | "cell_type": "code", |
494 | | - "execution_count": 116, |
| 493 | + "execution_count": 11, |
495 | 494 | "metadata": {}, |
496 | 495 | "outputs": [], |
497 | 496 | "source": [ |
|
555 | 554 | }, |
556 | 555 | { |
557 | 556 | "cell_type": "code", |
558 | | - "execution_count": 117, |
| 557 | + "execution_count": 12, |
559 | 558 | "metadata": {}, |
560 | 559 | "outputs": [], |
561 | 560 | "source": [ |
|
580 | 579 | }, |
581 | 580 | { |
582 | 581 | "cell_type": "code", |
583 | | - "execution_count": 118, |
| 582 | + "execution_count": 13, |
584 | 583 | "metadata": {}, |
585 | 584 | "outputs": [], |
586 | 585 | "source": [ |
|
657 | 656 | }, |
658 | 657 | { |
659 | 658 | "cell_type": "code", |
660 | | - "execution_count": 119, |
| 659 | + "execution_count": 14, |
661 | 660 | "metadata": {}, |
662 | 661 | "outputs": [ |
663 | 662 | { |
|
671 | 670 | "}\n", |
672 | 671 | "\n", |
673 | 672 | "Output of function call:\n", |
674 | | - "05:55:08 PM\n", |
| 673 | + "06:08:07 PM\n", |
675 | 674 | "\n", |
676 | 675 | "Messages in second request:\n", |
677 | 676 | "{'role': 'user', 'content': 'What time is it in New York?'}\n", |
678 | 677 | "{'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", |
| 678 | + "{'role': 'function', 'name': 'get_current_time', 'content': '06:08:07 PM'}\n", |
680 | 679 | "\n", |
681 | 680 | "{\n", |
682 | 681 | " \"role\": \"assistant\",\n", |
683 | | - " \"content\": \"The current time in New York is 05:55:08 PM.\"\n", |
| 682 | + " \"content\": \"The current time in New York is 06:08 PM.\"\n", |
684 | 683 | "}\n" |
685 | 684 | ] |
686 | 685 | } |
|
701 | 700 | }, |
702 | 701 | { |
703 | 702 | "cell_type": "code", |
704 | | - "execution_count": 120, |
| 703 | + "execution_count": 15, |
705 | 704 | "metadata": {}, |
706 | 705 | "outputs": [], |
707 | 706 | "source": [ |
|
781 | 780 | }, |
782 | 781 | { |
783 | 782 | "cell_type": "code", |
784 | | - "execution_count": 121, |
| 783 | + "execution_count": 16, |
785 | 784 | "metadata": {}, |
786 | 785 | "outputs": [ |
787 | 786 | { |
|
0 commit comments