Function calls
Large language models (LLMs) possess advanced function calling capabilities that enable them to interact with external tools and services to perform specific tasks. These capabilities allow them to extend their natural language processing skills to include functionalities such as generating images, executing code, or retrieving up-to-date information from the web.
With Sendbird, you can set up functions to call on Sendbird Dashboard and connect it to your AI chatbot. Leveraging such feature makes your AI chatbot useful for a variety of tasks, helping them give better and more interactive answers to your end-users.
This guide explains how function calls work, how to create a function, and how to incorporate it into your AI chatbot.
How function calls work
This section explains the interaction between the user interface, the server, and the API in handling function calls.
- User query: A user submits a question via the chat interface (e.g., "What's the weather in Seoul today?").
- Request processing: The server forwards this query along with potential function metadata to the OpenAI engine.
- Function selection: OpenAI analyzes the query's semantic content to select the most appropriate API function.
- Parameter extraction: Relevant parameters, like the city name from the query, are identified and formatted in JSON.
- API interaction: The server invokes the selected function with the extracted parameters. The function executes and returns data in JSON format.
- Response formulation: The JSON output is translated back into a natural, user-friendly response using the OpenAI engine.
The process ensures that user queries are processed efficiently and responses are generated in an understandable format.
How to create a function
-
On Sendbird Dashboard, go to Application > AI Chatbot > Manage bots > Function calls.
-
There are two ways to create a function:
- Creating a new function: Click on Create function+ to create a new function from scratch.
- Using a sample function: Click on the pre-made functions to use them. You can edit the details to tailor them to your needs.
- If you are creating a new function from scratch, click on Create function + and fill in the basic information.
Field | Description |
---|---|
Trigger type | Specifies how the function is activated. |
Function name | A name for the function. This name is only used for the dashboard. |
Function key | A key to filter or identify the function by. Only letters, numbers, and underscores can be used. |
Trigger prompt | A description for this function that allows the AI chatbot to determine when to trigger the function. |
Fallback message | A message to display when the function is not triggered successfully. |
3. Enter the request information for the API call.
Field | Description |
---|---|
HTTP method | The action you want to perform. |
URL | The web address where the request is sent, telling the API exactly what resource you're trying to interact with. |
Headers | Additional information sent along with the request, often used for authentication or specifying content type. |
Request body | The actual data you're sending in JSON format. Required for a |
4. Click on Send request and test your API call.
Connect to your AI chatbot
Using the function calls you created above, you can connect it directly into your AI chatbot. Note that you can only connect functions of the Automatic detection by AI trigger type.
-
On Sendbird Dashboard, go to Application > AI chatbot > Bot studio and either click on an existing bot or create a new bot. For more information on how to create a new bot, see this page.
-
In the bot detail page, you can select functions to connect under the Function calls tab as shown in the image below.
Add in your response workflow
Using the function call you created above, you can also use it in your response workflow. Note that you can only use functions of the Manual activation by Response workflow trigger type.
-
On Sendbird Dashboard, go to Application > AI chatbot > Response workflows and click Create a response workflow +. For more information on how to create a response workflow, see this page.
-
You can add a function call by clicking on a Custom response box, then Add response + > Function calls (using API) > Select a function.
To learn more, see Sendbird's AI chatbot product page.