4 ms·
If GPT thinks a function call is warranted based on the input, then it fills in a "function_call" parameter in its response and provides the arguments. You then
by ttul 3y ago
If GPT thinks a function call is warranted based on the input, then it fills in a "function_call" parameter in its response and provides the arguments. You then call the function using those arguments and in your next call to ChatCompletion, you pass in the response from your function.
message = response["choices"][0]["message"]
# Step 2, check if the model wants to call a function
if message.get("function_call"):
function_name = message["function_call"]["name"]
...
second_response = openai.ChatCompletion.create(
model="gpt-3.5-turbo-0613",
messages=[
{"role": "user", "content": "What is the weather like in boston?"},
message,
{
"role": "function",
"name": function_name,
"content": function_response,
},
],
)