mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-02 15:52:34 +00:00
Squashed 'packages/tools/' content from commit 78317b9c
git-subtree-dir: packages/tools git-subtree-split: 78317b9c127f18bd040c1d77e3c0840cdc9a5b38
This commit is contained in:
58
crewai_tools/tools/website_search/website_search_tool.py
Normal file
58
crewai_tools/tools/website_search/website_search_tool.py
Normal file
@@ -0,0 +1,58 @@
|
||||
from typing import Any, Optional, Type
|
||||
|
||||
try:
|
||||
from embedchain.models.data_type import DataType
|
||||
EMBEDCHAIN_AVAILABLE = True
|
||||
except ImportError:
|
||||
EMBEDCHAIN_AVAILABLE = False
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from ..rag.rag_tool import RagTool
|
||||
|
||||
|
||||
class FixedWebsiteSearchToolSchema(BaseModel):
|
||||
"""Input for WebsiteSearchTool."""
|
||||
|
||||
search_query: str = Field(
|
||||
...,
|
||||
description="Mandatory search query you want to use to search a specific website",
|
||||
)
|
||||
|
||||
|
||||
class WebsiteSearchToolSchema(FixedWebsiteSearchToolSchema):
|
||||
"""Input for WebsiteSearchTool."""
|
||||
|
||||
website: str = Field(
|
||||
..., description="Mandatory valid website URL you want to search on"
|
||||
)
|
||||
|
||||
|
||||
class WebsiteSearchTool(RagTool):
|
||||
name: str = "Search in a specific website"
|
||||
description: str = (
|
||||
"A tool that can be used to semantic search a query from a specific URL content."
|
||||
)
|
||||
args_schema: Type[BaseModel] = WebsiteSearchToolSchema
|
||||
|
||||
def __init__(self, website: Optional[str] = None, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
if website is not None:
|
||||
self.add(website)
|
||||
self.description = f"A tool that can be used to semantic search a query from {website} website content."
|
||||
self.args_schema = FixedWebsiteSearchToolSchema
|
||||
self._generate_description()
|
||||
|
||||
def add(self, website: str) -> None:
|
||||
if not EMBEDCHAIN_AVAILABLE:
|
||||
raise ImportError("embedchain is not installed. Please install it with `pip install crewai-tools[embedchain]`")
|
||||
super().add(website, data_type=DataType.WEB_PAGE)
|
||||
|
||||
def _run(
|
||||
self,
|
||||
search_query: str,
|
||||
website: Optional[str] = None,
|
||||
) -> str:
|
||||
if website is not None:
|
||||
self.add(website)
|
||||
return super()._run(query=search_query)
|
||||
Reference in New Issue
Block a user