世界工厂采购网站,软件公司做网站推广科目,企业网站制作 南京,商城建站模板有时会定义很多工具#xff0c;而定义Agent的时候只想使用与问题相关的工具#xff0c;这是可以通过向量数据库来检索相关的工具#xff0c;传递给Agent
# Define which tools the agent can use to answer user queries
search SerpAPIWrapper()
search_tool Tool(name …有时会定义很多工具而定义Agent的时候只想使用与问题相关的工具这是可以通过向量数据库来检索相关的工具传递给Agent
# Define which tools the agent can use to answer user queries
search SerpAPIWrapper()
search_tool Tool(name Search,funcsearch.run,descriptionuseful for when you need to answer questions about current events)
def fake_func(inp: str) - str:return foo
fake_tools [Tool(nameffoo-{i}, funcfake_func, descriptionfa 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_contentt.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)