LLM RAG with Agent

题意:基于代理的LLM检索增强生成

问题背景:

I was trying the application code in the link.

我正在尝试链接中的应用程序代码。

I am using the following Llang Chain version

我正在使用以下Llang Chain版本

langchain 0.0.327 langchain-community 0.0.2 langchain-core 0.1.0

Getting the following error:        得到以下的错误

Entering new AgentExecutor chain...Traceback (most recent call last):File "RAGWithAgent.py", line 54, in <module>result = agent_executor({"input": "hi, im bob"})File "\lib\site-packages\langchain\chains\base.py", line 310, in __call__raise eFile "\lib\site-packages\langchain\chains\base.py", line 304, in __call__self._call(inputs, run_manager=run_manager)File "\lib\site-packages\langchain\agents\agent.py", line 1146, in _callnext_step_output = self._take_next_step(File "\lib\site-packages\langchain\agents\agent.py", line 933, in _take_next_stepoutput = self.agent.plan(File "\lib\site-packages\langchain\agents\openai_functions_agent\base.py", line 104, in planpredicted_message = self.llm.predict_messages(File "\lib\site-packages\langchain\chat_models\base.py", line 650, in predict_messagesreturn self(messages, stop=_stop, **kwargs)File "\lib\site-packages\langchain\chat_models\base.py", line 600, in __call__generation = self.generate(File "\lib\site-packages\langchain\chat_models\base.py", line 349, in generateraise eFile "\lib\site-packages\langchain\chat_models\base.py", line 339, in generateself._generate_with_cache(File "\lib\site-packages\langchain\chat_models\base.py", line 492, in _generate_with_cachereturn self._generate(File "\lib\site-packages\langchain\chat_models\openai.py", line 357, in _generatereturn _generate_from_stream(stream_iter)File "\lib\site-packages\langchain\chat_models\base.py", line 57, in _generate_from_streamfor chunk in stream:File "\lib\site-packages\langchain\chat_models\openai.py", line 326, in _streamfor chunk in self.completion_with_retry(File "\lib\site-packages\langchain\chat_models\openai.py", line 299, in completion_with_retryreturn _completion_with_retry(**kwargs)File "\lib\site-packages\tenacity\__init__.py", line 289, in wrapped_freturn self(f, *args, **kw)File "\lib\site-packages\tenacity\__init__.py", line 379, in __call__do = self.iter(retry_state=retry_state)File "\lib\site-packages\tenacity\__init__.py", line 314, in iterreturn fut.result()File "D:\Program Files\Python38\lib\concurrent\futures\_base.py", line 432, in resultreturn self.__get_result()File "D:\Program Files\Python38\lib\concurrent\futures\_base.py", line 388, in __get_resultraise self._exceptionFile "\lib\site-packages\tenacity\__init__.py", line 382, in __call__result = fn(*args, **kwargs)File "\lib\site-packages\langchain\chat_models\openai.py", line 297, in _completion_with_retryreturn self.client.create(**kwargs)File "\lib\site-packages\openai\api_resources\chat_completion.py", line 25, in createreturn super().create(*args, **kwargs)File "\lib\site-packages\openai\api_resources\abstract\engine_api_resource.py", line 155, in createresponse, _, api_key = requestor.request(File "\lib\site-packages\openai\api_requestor.py", line 299, in requestresp, got_stream = self._interpret_response(result, stream)File "\lib\site-packages\openai\api_requestor.py", line 710, in _interpret_responseself._interpret_response_line(File "\lib\site-packages\openai\api_requestor.py", line 775, in _interpret_response_lineraise self.handle_error_response(
openai.error.InvalidRequestError: Unrecognized request argument supplied: functionsProcess finished with exit code 1

I used Azure LLM instead openAI. FAISS was not working for me so used Chroma Vector Store.

我使用了Azure的LLM,而不是OpenAI。FAISS对我不起作用,所以我使用了Chroma Vector Store。

Following is my code:        下面是我的代码

from langchain.text_splitter import CharacterTextSplitterfrom langchain.document_loaders import TextLoader
from langchain.agents.agent_toolkits import create_retriever_tool
from langchain.agents.agent_toolkits import create_conversational_retrieval_agentfrom langchain.chat_models import AzureChatOpenAI
from langchain.vectorstores import Chroma
from langchain.embeddings.sentence_transformer import SentenceTransformerEmbeddingsimport osAZURE_OPENAI_API_KEY = ""
os.environ["OPENAI_API_KEY"] = AZURE_OPENAI_API_KEYloader = TextLoader(r"Toward a Knowledge Graph of Cybersecurity Countermeasures.txt")
documents = loader.load()
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
chunks = text_splitter.split_documents(documents)# create the open-source embedding function
embedding_function = SentenceTransformerEmbeddings(model_name="all-mpnet-base-v2")current_directory = os.path.dirname("__file__")# load it into Chroma and save it to disk
db = Chroma.from_documents(chunks, embedding_function, collection_name="groups_collection",persist_directory=r"\rag_with_agent_chroma_db")retriever = db.as_retriever(search_kwargs={"k": 5})tool = create_retriever_tool(retriever,"search_state_of_union",
"Searches and returns documents regarding the state-of-the-union.",
)
tools = [tool]llm = AzureChatOpenAI(deployment_name='gtp35turbo',model_name='gpt-35-turbo',openai_api_key=AZURE_OPENAI_API_KEY,openai_api_version='2023-03-15-preview',openai_api_base='https://azureft.openai.azure.com/',openai_api_type='azure',streaming=True,verbose=True
)agent_executor = create_conversational_retrieval_agent(llm, tools, verbose=True, remember_intermediate_steps=True,memory_key="chat_history")result = agent_executor({"input": "hi, im bob"})print(result["output"])

问题解决:

I tried multiple including the answers mentioned above. But did not work. I even tried to degrade, and upgrade llm version.

我尝试了包括上面提到的多种方法,但都没有成功。我甚至尝试降级和升级LLM(大型语言模型)的版本。

Finally, the following code to initialize the agent worked for me with the current version of llm

最后,以下代码使用当前版本的LLM(大型语言模型)来初始化代理对我起作用了。

conversational_agent = initialize_agent(agent=AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION, tools=tools,llm=llm,max_iterations=10,handle_parsing_errors=True,early_stopping_method="generate",memory=memory, verbose=True,)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/39093.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

云数据中心运维新纪元:让Linux服务器如虎添翼

文章目录 一、Linux系统管理的高级技巧1. 性能调优与监控&#xff1a;2. 自动化与脚本编写&#xff1a;3. 文件系统与存储管理&#xff1a; 二、服务器配置优化的策略1. 硬件选型与配置&#xff1a;2. 网络配置与优化&#xff1a;3. 应用部署与调优&#xff1a; 三、安全策略的…

极速升级:MacOS系统中Pip源的切换指南

极速升级&#xff1a;MacOS系统中Pip源的切换指南 在MacOS系统中&#xff0c;Python的包管理工具Pip是我们管理和安装Python库的得力助手。然而&#xff0c;默认的Pip源在国外&#xff0c;对于国内用户来说&#xff0c;访问速度可能较慢。因此&#xff0c;更换Pip源以提高下载…

工厂模式-实现

一.工厂模式 通过使用工厂模式&#xff0c;可以将对象的创建逻辑封装在一个工厂类中&#xff0c;而不是在客户端代码中直接实例化对象&#xff0c;这样可以提高代码的可维护性和可扩展性 Demo:以协议为例 1.抽象接口 public interface IProtocolGateWay{string ProtocolType{…

SMARTFORMS

page&#xff08;节点&#xff09;-> wondows(容器)

OpenCV 车牌检测

OpenCV 车牌检测 级联分类器算法流程车牌检测相关链接 级联分类器 假设我们需要识别汽车图像中车牌的位置&#xff0c;利用深度学习目标检测技术可以采取基于锚框的模型&#xff0c;但这需要在大量图像上训练模型。 但是&#xff0c;级联分类器可以作为预训练文件直接使用&…

go使用grpc编辑器 windows

先看最后效果&#xff1a; 当我执行 protoc --go_out. proto.proto 会生成proto.pb.go文件&#xff0c;主要存储的是封装好的结构体 执行 protoc --go-grpc_out. proto.proto 会生成对应的方法 那么现在提供解决方案&#xff1a; https://github.com/protocolbuffers…

MongoDB数据库 MQL (MongoDB Query Language)语句大全

基本命令 连接到 MongoDB mongo显示所有数据库 show dbs选择&#xff08;或创建&#xff09;数据库 db集合操作 显示当前数据库中的所有集合 show collections创建集合 db.createCollection("myCollection")删除集合 db.myCollection.drop()文档操作 插入文…

新手教程系列 -- SQLAlchemy对同一张表联表两次

在开发过程中&#xff0c;我们经常会遇到对同一张表进行多次联表查询的需求。比如在查询航线时&#xff0c;我们希望将起飞和降落的机场名称代入结果中。为了实现这一目标&#xff0c;机场名称统一存放在 AirPort 表中。下面&#xff0c;我们将介绍如何通过 SQLAlchemy 实现这一…

多线程编程基础与并发问题解决方案

多线程编程基础与并发问题解决方案 大家好&#xff0c;我是免费搭建查券返利机器人省钱赚佣金就用微赚淘客系统3.0的小编&#xff0c;也是冬天不穿秋裤&#xff0c;天冷也要风度的程序猿&#xff01; 引言 在现代软件开发中&#xff0c;多线程编程成为了处理并发任务和提升程…

[漏洞分析] CVE-2024-6387 OpenSSH核弹核的并不是很弹

文章目录 漏洞简介漏洞原理补丁分析漏洞原理 漏洞利用漏洞利用1: SSH-2.0-OpenSSH_3.4p1 Debian 1:3.4p1-1.woody.3 (Debian 3.0r6, from 2005) [无ASLR无NX]漏洞利用原理漏洞利用关键点 漏洞利用2: SSH-2.0-OpenSSH_4.2p1 Debian-7ubuntu3 (Ubuntu 6.06.1, from 2006) [无ASLR…

Hadoop集群误删数据紧急恢复详细步骤

1、发现集群误删数据处理 与现场核实是否可以停止集群&#xff0c;建议立即停止集群&#xff0c;减少数据丢失数据。 2、第一时间检查Fsimage文件&#xff0c;确认是否存在可用于数据恢复的Fsimage文件。 最新checkpoint的元数据只有原来的1/4&#xff0c;故使用离当前时间点最…

Python爬虫之爬虫逆向常见的加密方式

Python爬虫之爬虫逆向常见的加密方式 在Python爬虫领域&#xff0c;数据加密是一个重要的议题&#xff0c;尤其是在处理敏感信息或需要绕过网站的反爬虫机制时。下面&#xff0c;我们将探讨一些常见的数据加密方式&#xff0c;以及它们在Python爬虫中的应用。 常见的数据加密…

PD/PPS适配器/充电器高频快速AC-DC充电器芯片

概述 PC1067 是一款集成 GaN 功率器件的高频准谐振反激控制器&#xff0c;适合设计在离线式 USB-PD和USB Type-C 等快速充电器和电源供应器方案&#xff0c;待机功耗小于 75mW。 PC1067 集成全面的保护功能&#xff0c;包括逐周期过流保护&#xff08;OCP&#xff09;&#x…

library source does not match the bytecode for class SpringApplication

library source does not match the bytecode for class SpringApplication 问题描述&#xff1a;springboot源码点进去然后download source后提示标题内容。spring版本5.2.8.RELEASE&#xff0c;springboot版本2.7.18 解决方法&#xff1a;把spring版本改为与boot版本对应的6.…

一键搞定长图处理:高效精准,轻松实现按固定高度像素切割

在数字时代&#xff0c;图像已经成为我们日常生活中不可或缺的一部分。无论是网页设计、广告海报&#xff0c;还是社交媒体分享&#xff0c;图像都在扮演着至关重要的角色。但是&#xff0c;当你面临一张长长的图片&#xff0c;需要按照特定的尺寸进行切割时&#xff0c;你是否…

物流行业:智能物流跟踪

在现代物流中&#xff0c;RFID技术的应用已经成为提高运输效率和安全性的重要手段。RFID标签可以被轻松地附加到货物上&#xff0c;并能够实时记录物品的位置和状态。通过这些标签&#xff0c;物流公司可以实时追踪货物的运输路径&#xff0c;监控货物的运输状况&#xff0c;确…

Docker 部署 Minio 对象存储服务器

文章目录 Github官网文档简介dockerdocker-compose.ymlmc 客户端mc 基础命令Golang 示例创建 test 账号密钥文件上传示例 Github https://github.com/minio/minio 官网 https://min.io/https://www.minio.org.cn/ 文档 https://www.minio.org.cn/docs/minio/kubernetes/up…

解决跨域问题(vite、axios/koa)

两种方法选其一即可 一、后端koa设置中间件 app.use(async (ctx, next)> {ctx.set(Access-Control-Allow-Origin, *);ctx.set(Access-Control-Allow-Headers, Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild);ctx.set(Access-C…

hamibot 学习

1.参考文档&#xff1a; https://blog.csdn.net/zxl0428/article/details/1285318731.参考官网 快速入手步骤&#xff1a;注册&#xff0c;安装客户端&#xff0c;添加设备&#xff0c;开发脚本&#xff0c;运行脚本 https://hamibot.com/guide1.安装客户端 2.添加设备 …

【Python网络爬虫案例】python爬虫之模拟登录

&#x1f517; 运行环境&#xff1a;PYTHON &#x1f6a9; 撰写作者&#xff1a;左手の明天 &#x1f947; 精选专栏&#xff1a;《python》 &#x1f525; 推荐专栏&#xff1a;《算法研究》 #### 防伪水印——左手の明天 #### &#x1f497; 大家好&#x1f917;&#x1f91…