Function Calling in the OpenAI API

What is function calling and how does it work in the OpenAI API?

Updated over a week ago

In an API call, you can describe functions and have the model intelligently choose to output a JSON object containing arguments to call one or many functions. The Chat Completions API does not call the function; instead, the model generates JSON that you can use to call the function in your code.

What’s new with Function calling V2?

We’ve made three updates to function calling in the API:

  • “JSON mode” now enables the model to output strings that parse to valid JSON

  • The ability to call multiple functions from a single message

  • Improved performance on matching the desired properties or schema, if provided

What is JSON mode?

By setting response_format: { type: "json_object" } when calling gpt-3.5-turbo-1106 , gpt-4-1106-preview, or newer versions, these models will constrain their output to generate strings that parse into valid JSON.

Did this answer your question?