I’m playing with functions and finding that in some cases, ChatGPT ALWAYS calls a function, if one is provided.
E.g. if the message is:
“”"
The current weather in Boston, MA is 55F with sunny skies.
What is the current weather in Boston?
“”"
and you provide the function (from the example):
get_current_weather …
It will respond with a function call to get the current weather.
I made this very obvious example for demonstration purposes. A “real” use case would be that ChatGPT is asked to answer a customer’s question, based on on order details that are already provided in the prompt, but it still decided to call the get_order_details function.
… adding example (I use Java):
OpenAiChatRequest request = new OpenAiChatRequest();
request.setSystemMessage(
"Try to write a response to the message by using the provided information. "
+ "Only call a function if the required data is not provided. "
+ "Don't make assumptions about what values to plug into functions.");
request.addUserMessage(
"Customer Question: When will my order (#12345) arrive? I ordered it several days ago. -Tom"
+ "Order Details: { \"order_id\":12345, \"arrival_date\":\"10/20/23\"}, today is 10/19/23");
// Using FunctionBuilder to create a Function
OaiFunctionDescription function = new FunctionBuilder()
.withName("get_order_details")
.withDescription("Get the order details for a given order number")
.withAvailableArg("order_id", "The ID of the order", true).buildForOai();
request.addFunction(function);
OpenAiChatResponse response = OaiApi.makeChatRequest(request, 30000);
System.out.println(response);
Response:
{
"model": "gpt-3.5-turbo-0613",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"function_call": {
"name": "get_order_details",
"arguments": "{\n \"order_id\": \"12345\"\n}"
}
},
"finish_reason": "function_call"
}
],
...
}