#Function calling required parameters

1 messages · Page 1 of 1 (latest)

sick nova
cosmic geyserBOT
#

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

#

Function calling in the OpenAI API, as described in the extracts, allows you to define functions with parameters that the model can intelligently choose to call based on the user's input. The documentation specifies that you can define parameters within these functions, including setting certain parameters as required. This is evident from the example provided where the location parameter is marked as required in a function schema:

const tools = [
  {
    type: "function",
    function: {
      name: "get_current_weather",
      description: "Get the current weather in a given location",
      parameters: {
        type: "object",
        properties: {
          location: {
            type: "string",
            description: "The city and state, e.g. San Francisco, CA",
          },
          unit: { type: "string", enum: ["celsius", "fahrenheit"] },
        },
        required: ["location"],
      },
    },
  },
];

This indicates that the function calling feature is designed to recognize and process these required parameters based on the schema you provide. However, the documentation does not explicitly state how the system behaves if a required parameter is missing from the user's input or if it guarantees that the required parameters will always be respected in the sense that it will not proceed without them.

In practice, handling missing or null parameters seems to be left to the developer. As seen in another extract, if certain parameters (brand and amount in the example) are missing or null, the suggested approach is to assign default values within your application code after receiving the response from the API:

const response = /* the response from the API call */;
#

// Check if the fields are null or missing and assign default values
response.brand = response.brand || "default brand";
response.amount = response.amount || 1;


This workaround suggests that while you can specify parameters as required in your function schema, you may still need to implement additional logic in your application to handle cases where these parameters are not provided by the user or the model's output.

For more detailed information on function calling, including how to define and use parameters within your functions, you can refer to the **Function Calling Guide** (<https://platform.openai.com/docs/guides/function-calling>) on the OpenAI platform documentation.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
#

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