通过阿里云 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-maxtemperature=0.7
)# 调用模型
response = llm("请写一首关于春天的诗。")
print(response)
大模型应用之路:从提示词到通用人工智能(AGI)
https://cloud.tencent.com/developer/article/2414263
一文读懂:大模型RAG(检索增强生成)含高级方法