Function Calling
1. Use Cases
The Function Calling feature enables models to invoke external tools, thereby enhancing their capabilities.
This feature allows models to act as a “brain” that utilizes external tools (e.g., searching for external knowledge, checking itineraries, or accessing specialized domain tools) to effectively address issues such as hallucinations and knowledge recency.
2. How to Use
2.1 Add tools as a request parameter via REST API
Include the following in the request body:
for example, payload:
2.2 Requesting via the OpenAI Library
This feature is compatible with OpenAI. When using the OpenAI library, add the parameter tools=[corresponding tools]
in the request.
For example:
3. Supported Models
The currently supported models are:
-
Deepseek Series:
- deepseek-ai/DeepSeek-V2.5
-
Qwen Series:
- Qwen/Qwen2.5-72B-Instruct
- Qwen/Qwen2.5-7B-Instruct
4. Examples
4.1. Example 1: Extending numerical computation capabilities
This code demonstrates the use of four functions: addition, subtraction, comparison of values, and counting repeated letters in a string. The example illustrates how function calling can address execution challenges in areas where large language models are less proficient, such as numerical operations within token predictions.
Output might look like:
4.2. Example: Extending a large language model’s understanding of the external environment
This code uses a single function to query external information via an external API.
Output might look like: