Skip to content

Examples and guides for using the OpenAI API

Updated 'How to call functions with chat models' cookbook to use GPT-… (#2072)

Jordan Ellis30fba985b15b
diff --git a/examples/How_to_call_functions_with_chat_models.ipynb b/examples/How_to_call_functions_with_chat_models.ipynb
index 45102bdd..5732d5bf 100644
--- a/examples/How_to_call_functions_with_chat_models.ipynb
+++ b/examples/How_to_call_functions_with_chat_models.ipynb
@@ -51,7 +51,7 @@
},
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": null,
"id": "dab872c5",
"metadata": {
"ExecuteTime": {
@@ -66,7 +66,7 @@
"from tenacity import retry, wait_random_exponential, stop_after_attempt\n",
"from termcolor import colored \n",
"\n",
- "GPT_MODEL = \"gpt-4o\"\n",
+ "GPT_MODEL = \"gpt-5\"\n",
"client = OpenAI()"
]
},
@@ -515,7 +515,7 @@
"source": [
"### Parallel Function Calling\n",
"\n",
- "Newer models such as gpt-4o or gpt-3.5-turbo can call multiple functions in one turn."
+ "Newer models such as gpt-5, gpt-4.1 or gpt-4o can call multiple functions in one turn."
]
},
{
@@ -758,7 +758,7 @@
"source": [
"##### Steps to invoke a function call using Chat Completions API: \n",
"\n",
- "**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",
+ "**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",
" \n",
"**Step 2**: Check programmatically if model wanted to call a function. If true, proceed to step 3. <br> \n",
"**Step 3**: Extract the function name and parameters from response, call the function with parameters. Append the result to messages. <br> \n",
@@ -767,7 +767,7 @@
},
{
"cell_type": "code",
- "execution_count": 19,
+ "execution_count": null,
"id": "e8b7cb9cdc7a7616",
"metadata": {
"ExecuteTime": {
@@ -792,9 +792,9 @@
"}]\n",
"\n",
"response = client.chat.completions.create(\n",
- " model='gpt-4o', \n",
+ " model=GPT_MODEL, \n",
" messages=messages, \n",
- " tools= tools, \n",
+ " tools=tools, \n",
" tool_choice=\"auto\"\n",
")\n",
"\n",
@@ -807,7 +807,7 @@
},
{
"cell_type": "code",
- "execution_count": 20,
+ "execution_count": null,
"id": "351c39def3417776",
"metadata": {
"ExecuteTime": {
@@ -847,7 +847,7 @@
" # Step 4: Invoke the chat completions API with the function response appended to the messages list\n",
" # Note that messages with role 'tool' must be a response to a preceding message with 'tool_calls'\n",
" model_response_with_function_call = client.chat.completions.create(\n",
- " model=\"gpt-4o\",\n",
+ " model=GPT_MODEL,\n",
" messages=messages,\n",
" ) # get a new response from the model where it can see the function response\n",
" print(model_response_with_function_call.choices[0].message.content)\n",