|
51 | 51 | }, |
52 | 52 | { |
53 | 53 | "cell_type": "code", |
54 | | - "execution_count": 2, |
| 54 | + "execution_count": null, |
55 | 55 | "id": "dab872c5", |
56 | 56 | "metadata": { |
57 | 57 | "ExecuteTime": { |
|
66 | 66 | "from tenacity import retry, wait_random_exponential, stop_after_attempt\n", |
67 | 67 | "from termcolor import colored \n", |
68 | 68 | "\n", |
69 | | - "GPT_MODEL = \"gpt-4o\"\n", |
| 69 | + "GPT_MODEL = \"gpt-5\"\n", |
70 | 70 | "client = OpenAI()" |
71 | 71 | ] |
72 | 72 | }, |
|
515 | 515 | "source": [ |
516 | 516 | "### Parallel Function Calling\n", |
517 | 517 | "\n", |
518 | | - "Newer models such as gpt-4o or gpt-3.5-turbo can call multiple functions in one turn." |
| 518 | + "Newer models such as gpt-5, gpt-4.1 or gpt-4o can call multiple functions in one turn." |
519 | 519 | ] |
520 | 520 | }, |
521 | 521 | { |
|
758 | 758 | "source": [ |
759 | 759 | "##### Steps to invoke a function call using Chat Completions API: \n", |
760 | 760 | "\n", |
761 | | - "**Step 1**: Prompt the model with content that may result in model selecting a tool to use. The description of the tools such as a function names and signature is defined in the 'Tools' list and passed to the model in API call. If selected, the function name and parameters are included in the response.<br>\n", |
| 761 | + "**Step 1**: Prompt the model with content that may result in model selecting a tool to use. The description of the tools such as a function name and signature is defined in the 'Tools' list and passed to the model in API call. If selected, the function name and parameters are included in the response.<br>\n", |
762 | 762 | " \n", |
763 | 763 | "**Step 2**: Check programmatically if model wanted to call a function. If true, proceed to step 3. <br> \n", |
764 | 764 | "**Step 3**: Extract the function name and parameters from response, call the function with parameters. Append the result to messages. <br> \n", |
|
767 | 767 | }, |
768 | 768 | { |
769 | 769 | "cell_type": "code", |
770 | | - "execution_count": 19, |
| 770 | + "execution_count": null, |
771 | 771 | "id": "e8b7cb9cdc7a7616", |
772 | 772 | "metadata": { |
773 | 773 | "ExecuteTime": { |
|
792 | 792 | "}]\n", |
793 | 793 | "\n", |
794 | 794 | "response = client.chat.completions.create(\n", |
795 | | - " model='gpt-4o', \n", |
| 795 | + " model=GPT_MODEL, \n", |
796 | 796 | " messages=messages, \n", |
797 | | - " tools= tools, \n", |
| 797 | + " tools=tools, \n", |
798 | 798 | " tool_choice=\"auto\"\n", |
799 | 799 | ")\n", |
800 | 800 | "\n", |
|
807 | 807 | }, |
808 | 808 | { |
809 | 809 | "cell_type": "code", |
810 | | - "execution_count": 20, |
| 810 | + "execution_count": null, |
811 | 811 | "id": "351c39def3417776", |
812 | 812 | "metadata": { |
813 | 813 | "ExecuteTime": { |
|
847 | 847 | " # Step 4: Invoke the chat completions API with the function response appended to the messages list\n", |
848 | 848 | " # Note that messages with role 'tool' must be a response to a preceding message with 'tool_calls'\n", |
849 | 849 | " model_response_with_function_call = client.chat.completions.create(\n", |
850 | | - " model=\"gpt-4o\",\n", |
| 850 | + " model=GPT_MODEL,\n", |
851 | 851 | " messages=messages,\n", |
852 | 852 | " ) # get a new response from the model where it can see the function response\n", |
853 | 853 | " print(model_response_with_function_call.choices[0].message.content)\n", |
|
0 commit comments