Overview
Qwen models support function calling capabilities, allowing the model to intelligently decide when to call external functions and generate appropriate parameters. This enables integration with APIs, databases, and other external services. Qwen supports both Qwen-style and GPT-style function calling formats, providing flexibility for different use cases.Function Calling Formats
Qwen-Style Functions
Qwen uses a custom function definition format that includes both human-readable and model-readable descriptions:GPT-Style Functions
Qwen also supports OpenAI-compatible function definitions:Using Function Calling with OpenAI API
Qwen provides an OpenAI-compatible API server for function calling:Setting Up the OpenAI API Server
Function Calling Workflow
Integration with LangChain
Qwen works seamlessly with LangChain for agent-based function calling:Best Practices
Important Considerations:
- Clear Descriptions: Provide detailed function descriptions to help the model understand when to use each function
- Parameter Validation: Always validate function arguments before execution
- Error Handling: Implement proper error handling for function calls
- Chinese vs English: The current version (as of 2023.08) of Qwen-7B-Chat performs better with Chinese tool-use prompts than English ones
Supported Models
Function calling is supported on:- Qwen-7B-Chat
- Qwen-14B-Chat
- Qwen-72B-Chat
- Qwen-1.8B-Chat
Example Use Cases
- Web Search: Integrate search engines to answer factual questions
- Image Generation: Create images based on text descriptions
- Weather APIs: Get real-time weather information
- Database Queries: Retrieve information from databases
- Calculator: Perform mathematical calculations
- Code Execution: Execute code and return results
Next Steps
Tool Use
Learn about ReAct prompting and tool integration
Agent Building
Build intelligent agents with Qwen