JSONSearchTool

JSONSearchTool 目前处于实验阶段。这意味着该工具正在积极开发中,用户可能会遇到意外行为或更改。我们强烈鼓励就任何问题或改进建议提供反馈。

描述

JSONSearchTool 工具旨在促进在 JSON 文件内容中进行高效和精确的搜索。它利用 RAG(检索增强生成)搜索机制,允许用户指定 JSON 路径以在特定 JSON 文件内进行定向搜索。此功能显著提高了搜索结果的准确性和相关性。

安装

要安装 JSONSearchTool 工具,请使用以下 pip 命令:

pip install 'crewai[tools]'

使用示例

这里提供了更新的示例,说明如何有效利用 JSONSearchTool 在 JSON 文件中进行搜索。这些示例考虑了当前实现和代码库中识别的使用模式。

代码
from crewai_tools import JSONSearchTool

# General JSON content search
# This approach is suitable when the JSON path is either known beforehand or can be dynamically identified.
tool = JSONSearchTool()

# Restricting search to a specific JSON file
# Use this initialization method when you want to limit the search scope to a specific JSON file.
tool = JSONSearchTool(json_path='./path/to/your/file.json')

参数

  • json_path (str, 可选): 指定要搜索的 JSON 文件的路径。如果工具初始化用于一般搜索,则此参数不是必需的。提供此参数后,搜索将仅限于指定的 JSON 文件。

配置选项

JSONSearchTool 支持通过配置字典进行广泛的自定义。这允许用户根据其需求选择不同的嵌入和摘要模型。

代码
tool = JSONSearchTool(
    config={
        "llm": {
            "provider": "ollama",  # Other options include google, openai, anthropic, llama2, etc.
            "config": {
                "model": "llama2",
                # Additional optional configurations can be specified here.
                # temperature=0.5,
                # top_p=1,
                # stream=true,
            },
        },
        "embedding_model": {
            "provider": "google", # or openai, ollama, ...
            "config": {
                "model": "models/embedding-001",
                "task_type": "retrieval_document",
                # Further customization options can be added here.
            },
        },
    }
)