Skip to main content

Overview

Qwen models accessed through Alibaba Cloud’s DashScope service, supporting Qwen-Max, Qwen-Plus, Qwen-Turbo and more.

Class Signature

from qwen_agent.llm import get_chat_model

llm = get_chat_model({
    'model': 'qwen-max',
    'model_type': 'qwen_dashscope',
    'api_key': 'your-dashscope-api-key'
})

Configuration

model
str
required
Model name: ‘qwen-max’, ‘qwen-plus’, ‘qwen-turbo’, ‘qwen-vl-max’, etc.
api_key
str
required
DashScope API key (or set DASHSCOPE_API_KEY env var)
model_type
str
required
Must be ‘qwen_dashscope’
generate_cfg
dict
Generation parameters:
  • temperature (float): 0.0 - 2.0
  • top_p (float): 0.0 - 1.0
  • max_tokens (int): Maximum tokens to generate
  • seed (int): Random seed

Usage Example

from qwen_agent.llm import get_chat_model
from qwen_agent.llm.schema import Message

# Initialize
llm = get_chat_model({
    'model': 'qwen-max',
    'model_type': 'qwen_dashscope',
    'api_key': 'your-api-key',
    'generate_cfg': {
        'temperature': 0.7,
        'top_p': 0.8
    }
})

# Chat
messages = [Message(role='user', content='Hello!')]
for response in llm.chat(messages=messages):
    print(response[-1].content)

Available Models

  • qwen-max: Most capable model
  • qwen-plus: Balanced performance
  • qwen-turbo: Fast responses
  • qwen-vl-max: Vision-language model
  • qwen3-max: Latest Qwen 3 series

Function Calling

functions = [{
    'name': 'get_weather',
    'description': 'Get weather',
    'parameters': {
        'type': 'object',
        'properties': {
            'city': {'type': 'string'}
        },
        'required': ['city']
    }
}]

for response in llm.chat(messages=messages, functions=functions):
    if response[-1].function_call:
        print(response[-1].function_call.name)

See Also

Build docs developers (and LLMs) love