From the course: OpenAI API: Function Calling
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Controlling when function calls happen - OpenAI API Tutorial
From the course: OpenAI API: Function Calling
Controlling when function calls happen
When you send a create request with the tools array to the Responses API, you are relying on the language model to make the right choice about which tools and functions to call. And while this is useful in many circumstances, there are also circumstances where you want to control exactly which function or tool is called, or which function or tool is excluded, or whether the system is able to do sequential calling, or what parameters are passed in to a specific function. And all of this can be controlled either in the tools array or in the call itself. These additional configurations are well explained in the documentation for function calling. First off, you have the tool choice parameter, which is appended to your response create call. Tool choice is set to auto by default, meaning the LLM can choose which tool or function to call. If you set tool choice to required, you are requiring the model to call whatever tools or functions are specified in your tools array. This is usually…