Langchain+文心一言调用

python 复制代码
import os

from langchain_community.llms import QianfanLLMEndpoint

os.environ["QIANFAN_AK"] = ""
os.environ["QIANFAN_SK"] = ""

llm_wenxin = QianfanLLMEndpoint()

res = llm_wenxin.invoke("中国国庆日是哪一天?")
print(res)

1、安装langchain

python 复制代码
#安装langchain环境
pip install langchain==0.3.3 openai -i https://mirrors.aliyun.com/pypi/simple 
#灵积模型服务
pip install dashscope -i https://mirrors.aliyun.com/pypi/simple   
#安装第三方集成,就是各种大语言模型
pip install langchain-community==0.3.2 -i https://mirrors.aliyun.com/pypi/simple 
#加载环境的工具  
pip install python-dotenv 

2、前期准备工作

**第一个准备工作:**文新一言的key值申请

传送门:百度智能云-云智一体深入产业

2.1.登录或者注册​​

2.2 实名认证

登录后进行实名认证

2.3 创建建新应用

2.4 获取key

选择自己想要的应用,获取key

3、使用langchain

复制代码
pip install qianfan -i https://mirrors.aliyun.com/pypi/simple
python 复制代码
import os

from langchain_community.llms import QianfanLLMEndpoint

os.environ["QIANFAN_AK"] = ""
os.environ["QIANFAN_SK"] = ""

llm_wenxin = QianfanLLMEndpoint()

res = llm_wenxin.invoke("中国国庆日是哪一天?")
print(res)

4、文档参考

平台功能OpenAPI介绍 - ModelBuilder

相关推荐
shut up11 小时前
LangChain - 如何使用阿里云百炼平台的Qwen-plus模型构建一个桌面文件查询AI助手 - 超详细
人工智能·python·langchain·智能体
liliangcsdn12 小时前
如何基于ElasticsearchRetriever构建RAG系统
大数据·elasticsearch·langchain
东方佑13 小时前
基于FastAPI与LangChain的Excel智能数据分析API开发实践
langchain·excel·fastapi
大模型教程2 天前
搞懂 LangChain RAG:检索、召回原理及 docid 的关键意义
程序员·langchain·llm
AI大模型2 天前
别再死磕 Chain 了!想做复杂的 Agent,你必须得上 LangGraph
程序员·langchain·llm
华仔AI智能体2 天前
AI编程工具(Cursor/Copilot/灵码/文心一言/Claude Code/Trae)AI编程辅助工具全方位比较
copilot·文心一言·ai编程
玲小珑2 天前
LangChain.js 完全开发手册(十四)生产环境部署与 DevOps 实践
前端·langchain·ai编程
weixin_438077493 天前
langchain官网翻译:Build a Question/Answering system over SQL data
数据库·sql·langchain·agent·langgraph
老顾聊技术3 天前
【AI课程上线了哦,打造类FastGPT产品】
langchain·rag
行者阿毅3 天前
langchain4j+SpringBoot+DashScope(灵积)整合
spring boot·langchain·ai编程