mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-28 17:48:13 +00:00
Squashed 'packages/tools/' content from commit 78317b9c
git-subtree-dir: packages/tools git-subtree-split: 78317b9c127f18bd040c1d77e3c0840cdc9a5b38
This commit is contained in:
47
crewai_tools/tools/json_search_tool/json_search_tool.py
Normal file
47
crewai_tools/tools/json_search_tool/json_search_tool.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from typing import Optional, Type
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from ..rag.rag_tool import RagTool
|
||||
|
||||
|
||||
class FixedJSONSearchToolSchema(BaseModel):
|
||||
"""Input for JSONSearchTool."""
|
||||
|
||||
search_query: str = Field(
|
||||
...,
|
||||
description="Mandatory search query you want to use to search the JSON's content",
|
||||
)
|
||||
|
||||
|
||||
class JSONSearchToolSchema(FixedJSONSearchToolSchema):
|
||||
"""Input for JSONSearchTool."""
|
||||
|
||||
json_path: str = Field(
|
||||
..., description="File path or URL of a JSON file to be searched"
|
||||
)
|
||||
|
||||
|
||||
class JSONSearchTool(RagTool):
|
||||
name: str = "Search a JSON's content"
|
||||
description: str = (
|
||||
"A tool that can be used to semantic search a query from a JSON's content."
|
||||
)
|
||||
args_schema: Type[BaseModel] = JSONSearchToolSchema
|
||||
|
||||
def __init__(self, json_path: Optional[str] = None, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
if json_path is not None:
|
||||
self.add(json_path)
|
||||
self.description = f"A tool that can be used to semantic search a query the {json_path} JSON's content."
|
||||
self.args_schema = FixedJSONSearchToolSchema
|
||||
self._generate_description()
|
||||
|
||||
def _run(
|
||||
self,
|
||||
search_query: str,
|
||||
json_path: Optional[str] = None,
|
||||
) -> str:
|
||||
if json_path is not None:
|
||||
self.add(json_path)
|
||||
return super()._run(query=search_query)
|
||||
Reference in New Issue
Block a user