跳到主要内容

JSONSearchTool

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

描述

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

安装

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

pip install 'crewai[tools]'

使用示例

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

from crewai.json_tools import JSONSearchTool  # 更新的导入路径

# 通用 JSON 内容搜索
# 当 JSON 路径事先已知或可以动态识别时,可以使用这种方法。
tool = JSONSearchTool()

# 限制搜索范围到特定的 JSON 文件
# 当您希望将搜索范围限制到特定的 JSON 文件时,请使用此初始化方法。
tool = JSONSearchTool(json_path='./path/to/your/file.json')

参数

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

配置选项

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

tool = JSONSearchTool(
config={
"llm": {
"provider": "ollama", # 其他选项包括 google、openai、anthropic、llama2 等。
"config": {
"model": "llama2",
# 这里可以指定其他可选配置。
# temperature=0.5,
# top_p=1,
# stream=true,
},
},
"embedder": {
"provider": "google", # 或 openai、ollama 等。
"config": {
"model": "models/embedding-001",
"task_type": "retrieval_document",
# 这里可以添加更多的定制选项。
},
},
}
)