Skip to main content

Use Cases

Function Calling enables models to interact with external tools to retrieve real-time information or perform specific actions. This improves data accuracy and expands model capabilities, allowing models to support more dynamic and practical application scenarios instead of simply generating text. Examples of Function Calling use cases include:
  • Dynamic information lookup: Call APIs to retrieve real-time dynamic data from external systems, such as weather, news, and stock quotes. For example, by calling a weather API to get real-time weather information, when a user asks about the current weather, the model can tell the user the weather conditions at that moment instead of providing an outdated forecast.
  • Task automation: Execute specific actions through function calls, allowing users to trigger automated backend operations through conversation. For example, by calling a ticket booking website API to reserve tickets, when a user asks how to buy tickets for an attraction, the model can help the user complete the booking directly instead of merely explaining how to book tickets.

Supported Models

The following models support Function Calling:

How to Use

  1. Define the tool functions that the model should call.
  2. Add the tools parameter to the request to define the functions the model can use.

Example

The following section provides a complete Python code example. It uses querying the current weather for a location as an example to demonstrate how to use Function Calling. For the specific API format of Function Calling, see the Create Chat Completion API.

1. Initialize the Client

You need to initialize the client with your JieKou AI API key.

2. Define the Function to Call

Define the function that the model should call. The following Python example demonstrates a function for retrieving weather information.

3. Construct an API Request with Tools and the User Message

Create the API call request. This request includes the tools parameter, which defines the function the model can use, as well as the user’s message.
Output:

4. Respond Based on the Function Call Result and Get the Final Answer

Next, handle the function call, execute the get_weather function, and send the result back to the model to generate the final response for the user.
Output:

Complete Code