Files
crewAI/crewai_tools/tools/pdf_search_tool/pdf_search_tool.py
Greyson LaLonde c960f26601 Squashed 'packages/tools/' changes from 78317b9c..0b3f00e6
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
2025-09-18 23:38:08 -04:00

51 lines
1.5 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 FixedPDFSearchToolSchema(BaseModel):
"""Input for PDFSearchTool."""
query: str = Field(
..., description="Mandatory query you want to use to search the PDF's content"
)
class PDFSearchToolSchema(FixedPDFSearchToolSchema):
"""Input for PDFSearchTool."""
pdf: str = Field(..., description="File path or URL of a PDF file to be searched")
class PDFSearchTool(RagTool):
name: str = "Search a PDF's content"
description: str = (
"A tool that can be used to semantic search a query from a PDF's content."
)
args_schema: Type[BaseModel] = PDFSearchToolSchema
def __init__(self, pdf: Optional[str] = None, **kwargs):
super().__init__(**kwargs)
if pdf is not None:
self.add(pdf)
self.description = f"A tool that can be used to semantic search a query the {pdf} PDF's content."
self.args_schema = FixedPDFSearchToolSchema
self._generate_description()
def add(self, pdf: str) -> None:
super().add(pdf, data_type=DataType.PDF_FILE)
def _run(
self,
query: str,
pdf: Optional[str] = None,
similarity_threshold: float | None = None,
limit: int | None = None,
) -> str:
if pdf is not None:
self.add(pdf)
return super()._run(query=query, similarity_threshold=similarity_threshold, limit=limit)