Function Calling
1. Use Cases
The Function Calling feature allows the model to call external tools to enhance its capabilities. This functionality enables the model to act as a brain that calls external tools (such as searching for external knowledge, checking itineraries, or specific domain tools), effectively addressing issues like hallucinations and knowledge timeliness.
2. How to Use
2.1 Add tools parameters via REST API
Include the following in the request body:
For example, a complete payload:
2.2 Use with OpenAI Library
This feature is compatible with OpenAI. When using the OpenAI library, add the corresponding tools parameter as tools=[corresponding tools]
. For example:
3. Supported Models
Currently supported models include:
- Qwen Series:
- Qwen/Qwen2.5-72B-Instruct
- Qwen/Qwen2.5-32B-Instruct
- Qwen/Qwen2.5-14B-Instruct
- Qwen/Qwen2.5-7B-Instruct
4. Examples
4.1 Example 1: Extending numerical computation capabilities of large language models via function calling
This code introduces four functions: addition, subtraction, comparison, and counting repeated letters in a string, demonstrating how function calling can address areas where large language models struggle, such as token prediction.
The model will output:
4.2 Example 2: Extending the model’s understanding of external environments through function calling
This code demonstrates querying external information using one function via an external API.
The model will output: