通义千问(Qwen)是阿里云的大语言模型系列,通过百炼平台(DashScope)提供 API。 核心优势:兼容 OpenAI SDK 调用,迁移成本极低;国际版无内容审核。
模型特点适用场景qwen-max最强能力,深度推理复杂分析、创意写作qwen-plus性价比最优(推荐)日常对话、代码生成qwen-turbo响应最快简单任务、高并发qwen-long长文本(1000 万 token)超长文档分析qwq-plus推理增强(思维链)数学、逻辑推理qwen-vl-max视觉理解图片/视频分析qwen-audio-turbo音频理解语音转录、音频分析
地域Base URL说明新加坡(国际版)https://dashscope-intl.aliyuncs.com/compatible-mode/v1推荐,无内容审核中国(北京)https://dashscope.aliyuncs.com/compatible-mode/v1国内访问快美国(弗吉尼亚)https://dashscope-us.aliyuncs.com/compatible-mode/v1美国节点
bash
pip install -U openai
python
from openai import OpenAI
client = OpenAI(
api_key="sk-your-dashscope-api-key",
base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
)
response = client.chat.completions.create(
model="qwen-plus",
messages=[
{"role": "system", "content": "你是一个专业的编程助手。"},
{"role": "user", "content": "用 Python 实现一个 LRU 缓存"}
]
)
print(response.choices[0].message.content)
python
# 图片理解
response = client.chat.completions.create(model="qwen-vl-max", messages=[{"role": "user",
"content": [{"type": "image_url", "image_url": {"url": "https://example.com/photo.jpg"}},
{"type": "text", "text": "描述图片内容"}]}])
# 视频理解
response = client.chat.completions.create(model="qwen-vl-max", messages=[{"role": "user",
"content": [{"type": "video_url", "video_url": {"url": "https://example.com/video.mp4"}},
{"type": "text", "text": "总结视频内容"}]}])
python
tools = [{"type": "function", "function": {"name": "get_weather", "description": "获取城市天气",
"parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}}}]
response = client.chat.completions.create(
model="qwen-plus", messages=[{"role": "user", "content": "北京天气?"}], tools=tools)
python
import json
response = client.chat.completions.create(model="qwen-plus",
messages=[{"role": "user", "content": "你的问题"}],
extra_headers={"X-DashScope-DataInspection": json.dumps({"input": "disable", "output": "disable"})})
仅在国际版端点生效,国内版无法禁用审核。
python
file = client.files.create(file=open("long_doc.pdf", "rb"), purpose="file-extract")
response = client.chat.completions.create(model="qwen-long", messages=[
{"role": "system", "content": f"fileid://{file.id}"},
{"role": "user", "content": "总结文档核心观点"}])
模型输入输出qwen-plus¥0.8¥2.0qwen-max¥2.0¥6.0qwen-turbo¥0.3¥0.6
qwen-plus,兼顾能力和成本qwen-long + 文件上传