How I can force gpt-4-0613 to always use functions

I’m using gpt-4-0613 and there I have 3 function, but I want it to only use functions, sometimes it is just returns normal message. what should I add at the end to force it to use always the functions

1 Like

nah required is not working, you have to do like this if you want always to use particular function :
function_call={“name”: “some_function”}

but I dont know how to force to use always some of the function

This from the cookbook

and finally you can set it to seek parameters for a specific function by doing something like function_call={"name": "get_current_weather"} <

So set that parameter to the function you need to be called.

1 Like

So first add an instruction to your system prompt and tell it to “always call one of the provided functions”. Then add a loop to your calling code. If you see that it fails to call a function, reply to the model with a user message that says “call one of the provided functions instead”. This should reliably get it to always call one of your function’s. I’d give it two chances to call a function before aborting but odds are it will typically call one of your functions on the very next try.


Another possibility is to divide the task into two different API calls:

  • The first determines the function to call
  • The second one has the name of the function from the previous step in the function_call parameter.

For the first request I created a select_action function that takes an enum argument with the names of the functions.

I created a Medium post called “How to force GPT models to always use functions” with more details.

Hi and welcome to the developer community.

Here is the link. You are new, I guess you couldn’t post that yet. But that’s some quality stuff, that deserves a link: