通过阿里云 DashScope API 调用通义千问
【代码】通过阿里云 DashScope API 调用通义千问。
·
获取API Key
百炼控制台
https://bailian.console.aliyun.com/?tab=model#/api-key
步骤 1:安装 DashScope SDK
pip install dashscope
步骤 2:LangChain 调用
from langchain_community.llms import Tongyi
# 设置阿里云 API Key(从环境变量或直接写入)
import os
os.environ["DASHSCOPE_API_KEY"] = "your-dashscope-api-key"
# 初始化 Qwen
llm = Tongyi(
model_name="qwen-plus", # 可选 qwen-turbo, qwen-plus, qwen-max
temperature=0.7
)
# 调用模型
response = llm("请写一首关于春天的诗。")
print(response)
DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。
更多推荐

所有评论(0)