TXTSearchTool

我们仍在努力改进工具,因此未来可能会出现意外行为或更改。

描述

此工具用于在文本文件内容中执行 RAG (检索增强生成) 搜索。它允许在指定文本文件内容中对查询进行语义搜索,是根据提供的查询快速提取信息或查找特定文本部分的宝贵资源。

安装

要使用 TXTSearchTool,您首先需要安装 crewai_tools 包。这可以使用 pip 来完成,pip 是 Python 的一个包管理器。打开您的终端或命令提示符并输入以下命令

pip install 'crewai[tools]'

此命令将下载并安装 TXTSearchTool 以及所有必要的依赖项。

示例

以下示例演示了如何使用 TXTSearchTool 在文本文件中进行搜索。此示例展示了使用特定文本文件初始化工具以及随后在该文件内容中进行搜索的过程。

代码
from crewai_tools import TXTSearchTool

# Initialize the tool to search within any text file's content 
# the agent learns about during its execution
tool = TXTSearchTool()

# OR

# Initialize the tool with a specific text file, 
# so the agent can search within the given text file's content
tool = TXTSearchTool(txt='path/to/text/file.txt')

参数

  • txt (str):可选。您要搜索的文本文件的路径。仅当工具未初始化特定文本文件时,才需要此参数;否则,将在最初提供的文本文件中进行搜索。

自定义模型和嵌入

默认情况下,该工具使用 OpenAI 进行嵌入和摘要。要自定义模型,您可以使用如下配置字典

代码
tool = TXTSearchTool(
    config=dict(
        llm=dict(
            provider="ollama", # or google, openai, anthropic, llama2, ...
            config=dict(
                model="llama2",
                # temperature=0.5,
                # top_p=1,
                # stream=true,
            ),
        ),
        embedder=dict(
            provider="google", # or openai, ollama, ...
            config=dict(
                model="models/embedding-001",
                task_type="retrieval_document",
                # title="Embeddings",
            ),
        ),
    )
)