#Function calling on a tool that takes no parameters

1 messages · Page 1 of 1 (latest)

spare hare
#

I have a tool that should not take in any parameters, how can I use function calling to call that tool?

woven sphinxBOT
#

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

#

To call a function that doesn't require any parameters, you can still define the function in your tool schema but leave the parameters field empty. However, when you attempt to call this function, you may encounter errors if you leave the parameters key blank or don't pass it at all.

A workaround suggested in the OpenAI community forum (https://community.openai.com/t/516876) is to allow the function to accept a parameter, but ignore it during execution. This parameter can be considered a "dummy" parameter and doesn't affect the function's operation. Here's an example of how you might define such a function:

const tools = [
  {
    type: "function",
    function: {
      name: "my_function",
      description: "My function that doesn't require parameters",
      parameters: {
        type: "object",
        properties: {
          dummy: {
            type: "string",
            description: "Dummy parameter to be ignored",
          },
        },
        required: ["dummy"],
      },
    },
  },
];

When calling the function, you can pass in any value for the dummy parameter:

const functionResponse = functionToCall(
  functionArgs.dummy
)

Remember to validate the arguments in your code before calling your function, as mentioned in the OpenAI API documentation (https://platform.openai.com/docs/api-reference).

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

#

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