AI Chatbot Guide v1
AI Chatbot
Version 1

Function calls

Copy link

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

Copy link

This section explains the interaction between the user interface, the server, and the API in handling function calls.

  1. User query: A user submits a question via the chat interface (e.g., "What's the weather in Seoul today?").
  2. Request processing: The server forwards this query along with potential function metadata to the OpenAI engine.
  3. Function selection: OpenAI analyzes the query's semantic content to select the most appropriate API function.
  4. Parameter extraction: Relevant parameters, like the city name from the query, are identified and formatted in JSON.
  5. API interaction: The server invokes the selected function with the extracted parameters. The function executes and returns data in JSON format.
  6. Response formulation: The JSON output is translated back into a natural, user-friendly response using the OpenAI engine.
{
"role": "assistant",
"content": null,
"function_call": {
    "name": "get_city_weather",
    "argument": "{\"city\": \"Seoul\"}"
    }
}

The process ensures that user queries are processed efficiently and responses are generated in an understandable format.


How to create a function

Copy link
  1. On Sendbird Dashboard, go to Application > AI chatbot > Function calls.

  2. 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.

  1. If you are creating a new function from scratch, click on Create function + and fill in the basic information.

FieldDescription

Trigger type

Specifies how the function is activated.
- Automatic detection by AI: Automatically executes in response to user queries that involve certain topics or keywords. Integrate this trigger by adding it to your bot in the Bot studio page.
- Manual activation by Response workflow: Executes only when included in a specific sequence of responses predefined in your response workflow. Link this function to an appropriate response within your Response workflow.

Note: This trigger type cannot be changed once the function is set up.

Function name

A name for the function. This name is only used for the dashboard.
Example: Get supplement recommendations

Function key

A key to filter or identify the function by. Only letters, numbers, and underscores can be used.
Example: get_supplement_recs

Trigger prompt

A description for this function that allows the AI chatbot to determine when to trigger the function.
Example: User is asking for supplement recommendations.

Fallback message

A message to display when the function is not triggered successfully.
Example: Sorry, I couldn't get the supplement recommendations right now. Please check back later or consult a healthcare provider for personalized advice.



3. Enter the request information for the API call.

FieldDescription

HTTP method

The action you want to perform.
-GET: Retrieve data
-POST: Create or send new data
-PUT: Update existing data
-DELETE: Remove data

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 POST or PUT request.



4. Click on Send request and test your API call.


Connect to your AI chatbot

Copy link

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.

  1. 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.

  2. 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

Copy link

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.

  1. 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.

  2. You can add a function call by clicking on a Custom response box, then Add response + > Function calls (using API) > Select a function.

  1. For detailed guide on how to create custom responses, see this page.

To learn more, see Sendbird's AI chatbot product page.