#Functions or tools in API?

1 messages · Page 1 of 1 (latest)

unborn galleon
#

Should i use the tools parameter or the functions parameter to add my functions to the chat completions API with gpt-4-turbo?

buoyant yewBOT
#

Hi @unborn galleon. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

You should use the tools parameter to add your functions to the Chat Completions API with gpt-4-turbo. The functions parameter has been deprecated in favor of tools as per the OpenAI Changelog (https://platform.openai.com/docs/changelog).

The tools parameter is used to provide function specifications to the API. The model will then generate function arguments that adhere to these specifications. However, the API will not execute any function calls. It's up to you to execute function calls using the model outputs.

Here's an example of how to define functions using the tools parameter:

tools = [
 {
 "type": "function",
 "function": {
 "name": "get_current_weather",
 "description": "Get the current weather",
 "parameters": {
 "type": "object",
 "properties": {
 "location": {
 "type": "string",
 "description": "The city and state, e.g. San Francisco, CA",
 },
 "format": {
 "type": "string",
 "enum": ["celsius", "fahrenheit"],
 "description": "The temperature unit to use. Infer this from the users location.",
 },
 },
 "required": ["location", "format"],
 },
 }
 },
 {
 "type": "function",
 "function": {
 "name": "get_n_day_weather_forecast",
 "description": "Get an N-day weather forecast",
 "parameters": {
 "type": "object",
 "properties": {
 "location": {
 "type": "string",
 "description": "The city and state, e.g. San Francisco, CA",
 },
 "format": {
 "type": "string",
 "enum": ["celsius", "fahrenheit"],
 "description": "The temperature unit to use. Infer this from the users location.",
 },
 "num_days": {
 "type": "integer",
 "description": "The number of days to forecast",
 }
 },
 "required": ["location", "format", "num_days"]
 },
 }
 },
]

This example is taken from the OpenAI Cookbook (https://cookbook.openai.com/examples/how_to_call_functions_with_chat_models#basic-concepts).

#

Remember, the model will decide when it is appropriate to use one of the functions. You can force the API to use a specific function by setting the tool_choice parameter. If a function is used, the output will contain "finish_reason": "tool_calls" in the response, as well as a tool_calls object that has the name of the function and the generated function arguments.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@unborn galleon kapa.ai is still learning and improving, please let us know how it did by reacting below

unborn galleon
#

@buoyant yew thanks, does this apply to gpt-3.5-turbo too?

buoyant yewBOT
#

Let me check the knowledge base for you. One moment! :books:

#

Yes, the use of the tools parameter applies to gpt-3.5-turbo as well. The functions parameter has been deprecated in favor of tools for all models that support function calls, including gpt-3.5-turbo.

As mentioned earlier, the tools parameter is used to provide function specifications to the API. The model will then generate function arguments that adhere to these specifications. However, the API will not execute any function calls. It's up to you to execute function calls using the model outputs.

You can refer to the same example provided earlier on how to define functions using the tools parameter.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: