mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-11 09:08:31 +00:00
0b3f00e6 chore: update project version to 0.73.0 and revise uv.lock dependencies (#455) ad19b074 feat: replace embedchain with native crewai adapter (#451) git-subtree-dir: packages/tools git-subtree-split: 0b3f00e67c0dae24d188c292dc99759fd1c841f7
54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
from typing import Optional, Type
|
|
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
from ..rag.rag_tool import RagTool
|
|
from crewai_tools.rag.data_types import DataType
|
|
|
|
|
|
class FixedCSVSearchToolSchema(BaseModel):
|
|
"""Input for CSVSearchTool."""
|
|
|
|
search_query: str = Field(
|
|
...,
|
|
description="Mandatory search query you want to use to search the CSV's content",
|
|
)
|
|
|
|
|
|
class CSVSearchToolSchema(FixedCSVSearchToolSchema):
|
|
"""Input for CSVSearchTool."""
|
|
|
|
csv: str = Field(..., description="File path or URL of a CSV file to be searched")
|
|
|
|
|
|
class CSVSearchTool(RagTool):
|
|
name: str = "Search a CSV's content"
|
|
description: str = (
|
|
"A tool that can be used to semantic search a query from a CSV's content."
|
|
)
|
|
args_schema: Type[BaseModel] = CSVSearchToolSchema
|
|
|
|
def __init__(self, csv: Optional[str] = None, **kwargs):
|
|
super().__init__(**kwargs)
|
|
if csv is not None:
|
|
self.add(csv)
|
|
self.description = f"A tool that can be used to semantic search a query the {csv} CSV's content."
|
|
self.args_schema = FixedCSVSearchToolSchema
|
|
self._generate_description()
|
|
|
|
def add(self, csv: str) -> None:
|
|
super().add(csv, data_type=DataType.CSV)
|
|
|
|
def _run(
|
|
self,
|
|
search_query: str,
|
|
csv: Optional[str] = None,
|
|
similarity_threshold: float | None = None,
|
|
limit: int | None = None,
|
|
) -> str:
|
|
if csv is not None:
|
|
self.add(csv)
|
|
return super()._run(query=search_query, similarity_threshold=similarity_threshold, limit=limit)
|
|
|