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.
},
},
}
)