我正在try 使用朗链react 试剂,我想给他们我的松果指数作为背景.我找不到任何接口,可以让我提供使用Reaction链的LLM以及我的向量嵌入.

在这里,我设置了LLM并检索向量嵌入.

llm = ChatOpenAI(temperature=0.1, model_name="gpt-4")
retriever = vector_store.as_retriever(search_type='similarity', search_kwargs={'k': k})

在这里,我开始了我的react 链.

prompt = hub.pull("hwchase17/structured-chat-agent")
agent = create_structured_chat_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
result = agent_executor.invoke(
    {
        "input": question,
        "chat_history": chat_history
    }
)

在使用Reaction代理之前,我像这样使用了向量嵌入.

crc = ConversationalRetrievalChain.from_llm(llm, retriever)
result = crc.invoke({'question': systemPrompt, 'chat_history': chat_history})
chat_history.append((question, result['answer']))

有没有办法将这两种方法结合起来,并拥有也使用矢量嵌入的react 代理?

推荐答案

您可以将检索器指定为代理的工具.示例:

from langchain.tools.retriever import create_retriever_tool


retriever = vector_store.as_retriever(search_type='similarity', search_kwargs={'k': k})

retriever_tool = create_retriever_tool(
    retriever,
    "retriever_name",
    "A detailed description of the retriever and when the agent should use it.",
)

tools = [retriever_tool]

agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

参考资料:

  1. Agent > Retriever (LangChain)

Python相关问答推荐

标题:如何在Python中使用嵌套饼图可视化分层数据?

如果条件不满足,我如何获得掩码的第一个索引并获得None?

ThreadPoolExecutor和单个线程的超时

有没有一种ONE—LINER的方法给一个框架的每一行一个由整数和字符串组成的唯一id?

不能使用Gekko方程'

如何合并两个列表,并获得每个索引值最高的列表名称?

如何使用SentenceTransformers创建矢量嵌入?

如何在FastAPI中为我上传的json文件提供索引ID?

如何在Gekko中使用分层条件约束

BeautifulSoup:超过24个字符(从a到z)的迭代失败:降低了首次深入了解数据集的复杂性:

根据客户端是否正在传输响应来更改基于Flask的API的行为

查看pandas字符列是否在字符串列中

Python—在嵌套列表中添加相同索引的元素,然后计算平均值

Python如何导入类的实例

为什么在不先将包作为模块导入的情况下相对导入不起作用

Groupby并在组内比较单独行上的两个时间戳

如何在Polars中处理用户自定义函数的多行结果?

如何将django url参数传递给模板&S url方法?

将鼠标悬停在海运`pairplot`的批注/高亮显示上

运行从Airflow包导入的python文件,需要airflow实例?