From the course: Developing with Nondeterministic APIs

Unlock this course with a free trial

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

Using function calling

Using function calling

- There's one more strategy I want to cover here that takes an entirely different approach to dealing with nondeterminism and AI APIs, using function calling to control the response. Function calling was originally introduced to do exactly what it sounds like, get the AI to respond with a call to a function and the necessary data to pass to that function. But it didn't take long for developers to realize you can use this feature to force the system to return structured data, even when you're not using it to call a function directly. Here's why this approach is often superior to the others we've covered. If you're prompting an AI API to return complex data in a specific format, there's a nonzero chance the system will return malformed data or not perform all the tasks you wanted to perform. With function calling, you can specify not only the output format of the response, but also exactly what data you want for each data…

Contents