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

相关推荐
@atweiwei15 小时前
用 Rust 构建agent的 LLM 应用的高性能框架
开发语言·后端·rust·langchain·eclipse·llm·agent
abigale0316 小时前
Langchain入门到实战开发智能体教程(LLM+RAG+OpenAI+Agent)-下
langchain·prompt
Csvn18 小时前
🌟 LangChain 30 天保姆级教程 · Day 16|文档加载器大合集!PDF、Word、网页、数据库一键读取,构建你的知识库!
python·langchain
前进的李工18 小时前
智能Agent实战指南:从入门到精通(工具)
开发语言·人工智能·架构·langchain·agent·tool·agentexecutor
chaors18 小时前
LangGraph 入门到精通0x00:HelloLangGraph
langchain·llm·agent
老王熬夜敲代码20 小时前
LAngChain工具接入
langchain
怕浪猫20 小时前
第12章 工具(Tools)与函数调用(LangChain实战)
langchain·aigc·ai编程
老王熬夜敲代码20 小时前
接入工具代码讲解
langchain
是小蟹呀^1 天前
【总结】LangChain中工具的使用
python·langchain·agent·tool
ai生成式引擎优化技术1 天前
文心一言的GEO生成式引擎优化技术方案
文心一言