By Admin on Tuesday, 27 May 2025
Category: All

OpenAI Function Calling

 Similar to the Chat Completions API, the Assistants API supports function calling. Function calling allows you to describe functions to the Assistants API and have it intelligently return the functions that need to be called along with their arguments.

In this example, we'll create a weather assistant and define two functions, get_current_temperature and get_rain_probability, as tools that the Assistant can call. In our example that uses parallel function calling, we will ask the Assistant what the weather in San Francisco is like today and the chances of rain. We also show how to output the Assistant's response with streaming.

When creating your assistant, you will first define the functions under the tools param of the assistant. 

​Step 2: Create a Thread and add Messages

Create a Thread when a user starts a conversation and add Messages to the Thread as the user asks questions. 

Step 3: Handle OnFunctionCall Event

When the component detects that a function parameter value is required, the event OnFunctionCall is called. Use the Request._Function parameter to know the request details and use the Response.Output to send the response. 

This browser does not support the video element.

Delphi Demo

Find below the delphi demo compiled for windows.