TXTSearchTool

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

描述

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

安装

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

pip install 'crewai[tools]'

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

示例

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

Code
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进行嵌入和摘要生成。 要自定义模型,您可以使用如下配置字典:

Code
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",
            ),
        ),
    )
)

这个页面有帮助吗?