当前位置: 首页 > news >正文

langchain-Agent-工具检索

有时会定义很多工具,而定义Agent的时候只想使用与问题相关的工具,这是可以通过向量数据库来检索相关的工具,传递给Agent

# Define which tools the agent can use to answer user queries
search = SerpAPIWrapper()
search_tool = Tool(name = "Search",func=search.run,description="useful for when you need to answer questions about current events")
def fake_func(inp: str) -> str:return "foo"
fake_tools = [Tool(name=f"foo-{i}", func=fake_func, description=f"a silly function that you can use to get more information about the number {i}") for i in range(99)
]
ALL_TOOLS = [search_tool] + fake_toolsfrom langchain.vectorstores import FAISS
from langchain.embeddings import OpenAIEmbeddings
from langchain.schema import Document
docs = [Document(page_content=t.description, metadata={"index": i}) for i, t in enumerate(ALL_TOOLS)]
vector_store = FAISS.from_documents(docs, OpenAIEmbeddings())
retriever = vector_store.as_retriever()def get_tools(query):docs = retriever.get_relevant_documents(query)return [ALL_TOOLS[d.metadata["index"]] for d in docs]tool = get_tools("What is today weather")
http://www.lryc.cn/news/279788.html

相关文章:

  • 猫头虎分享:探索TypeScript的世界 — TS基础入门 ‍
  • Unity-生命周期函数
  • SQL概述及SQL分类
  • [VSCode] VSCode 常用快捷键
  • 函数指针和回调函数 以及指针函数
  • 京东年度数据报告-2023全年度游戏本十大热门品牌销量(销额)榜单
  • 秒懂百科,C++如此简单丨第十二天:ASCLL码
  • Qt6入门教程 4:Qt Creator常用技巧
  • 阴盘奇门八字排盘马星位置计算方法php代码
  • vue3 使用 jsoneditor
  • 若依前后端分离版使用mybatis-plus实践教程
  • SpringBoot-Dubbo-Zookeeper
  • 华为HCIE课堂笔记第十二章 ICMPv6和NDP协议
  • GNSS科研常用相关网站及资源
  • 进程的创建与回收学习笔记
  • 【CCNet】《CCNet:Criss-Cross Attention for Semantic Segmentation》
  • Qt QSQlite数据库插入字符串中存在单个双引号或单个单引号解决方案
  • Linux系统中的IP地址、主机名、和域名解析
  • soc算法【周末总结】
  • SpringBoot之优化高并发场景下的HttpClient并提升QPS
  • go-zero 如何在任意地方获取yaml中的值
  • C++20结构化绑定应用实例(二百五十六)
  • 改进YOLOv8注意力系列四:结合中心化特征金字塔EVCBlock、大核卷积注意力LKA_Attention、全局注意力MobileViTAttention
  • idea中使用Lombok 失效,@Slf4j 找不到符号的解决办法
  • MySQL修炼手册8:约束与完整性:保证数据的一致性
  • React入门 - 03(初识 React 组件和 JSX)
  • 华为OD机试 - 反射计数(Java JS Python C)
  • Linux系统中使用systemctl命令控制软件的启动和关闭
  • 2024年01月微软更新Bug 已解决 !Explorer.EXE 提示:Windows无法访问指定设备、路径或文件。你可能没有适当的权限访问该项目。
  • Qt/QML编程学习之心得:slider(34)