From the course: Build a JavaScript AI App with React and the OpenAI API

Unlock the full course today

Join today to access over 24,500 courses taught by industry experts.

Add a function call to the request

Add a function call to the request

- [Instructor] Now that we know our call to the OpenAI API works, we can refine our requests so we get exactly the information we want, structured exactly the way we want. And for that we'll use function calling. You'll remember from the previous chapter, we can call in whatever functions we want and they automatically kick in. So I'm going to use this same setup here but since this is formatted in JSON, I can't simply copy and paste it in. So instead I'll just write it out from scratch so you can follow along. The function calls happen after the messages property. So in data here I'll set up functions. This will be an array of functions. And before I fill functions out, I'll also add this parameter, function_call and set it to auto. This is just to tell the OpenAI API that, hey, if functions are called, you can choose to use them or not. You can change this to a different property if you want to. Alright, let's…

Contents