JSONSearchTool

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

描述

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

安装

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

pip install 'crewai[tools]'

使用示例

以下是关于如何有效利用JSONSearchTool在JSON文件中进行搜索的更新示例。这些示例考虑了代码库中当前的实现和使用模式。

Code
from crewai.json_tools import JSONSearchTool  # Updated import path

# 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 支持通过配置字典进行广泛的定制。这允许用户根据他们的需求选择不同的嵌入和摘要模型。

Code
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,
            },
        },
        "embedder": {
            "provider": "google", # or openai, ollama, ...
            "config": {
                "model": "models/embedding-001",
                "task_type": "retrieval_document",
                # Further customization options can be added here.
            },
        },
    }
)

这个页面有帮助吗?