Skip to content
This repository was archived by the owner on Nov 10, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions crewai_tools/adapters/embedchain_adapter.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
from typing import Any

from embedchain import App

from crewai_tools.tools.rag.rag_tool import Adapter

try:
from embedchain import App
EMBEDCHAIN_AVAILABLE = True
except ImportError:
EMBEDCHAIN_AVAILABLE = False


class EmbedchainAdapter(Adapter):
embedchain_app: App
embedchain_app: Any # Will be App when embedchain is available
summarize: bool = False

def __init__(self, **data):
if not EMBEDCHAIN_AVAILABLE:
raise ImportError("embedchain is not installed. Please install it with `pip install crewai-tools[embedchain]`")
super().__init__(**data)

def query(self, question: str) -> str:
result, sources = self.embedchain_app.query(
question, citations=True, dry_run=(not self.summarize)
Expand Down
15 changes: 12 additions & 3 deletions crewai_tools/adapters/pdf_embedchain_adapter.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
from typing import Any, Optional

from embedchain import App

from crewai_tools.tools.rag.rag_tool import Adapter

try:
from embedchain import App
EMBEDCHAIN_AVAILABLE = True
except ImportError:
EMBEDCHAIN_AVAILABLE = False


class PDFEmbedchainAdapter(Adapter):
embedchain_app: App
embedchain_app: Any # Will be App when embedchain is available
summarize: bool = False
src: Optional[str] = None

def __init__(self, **data):
if not EMBEDCHAIN_AVAILABLE:
raise ImportError("embedchain is not installed. Please install it with `pip install crewai-tools[embedchain]`")
super().__init__(**data)

def query(self, question: str) -> str:
where = (
{"app_id": self.embedchain_app.config.id, "source": self.src}
Expand Down
22 changes: 13 additions & 9 deletions crewai_tools/tools/brightdata_tool/brightdata_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
import aiohttp
from crewai.tools import BaseTool
from pydantic import BaseModel, Field
from pydantic_settings import BaseSettings

class BrightDataConfig(BaseSettings):
class BrightDataConfig(BaseModel):
API_URL: str = "https://api.brightdata.com"
DEFAULT_TIMEOUT: int = 600
DEFAULT_POLLING_INTERVAL: int = 1

class Config:
env_prefix = "BRIGHTDATA_"

@classmethod
def from_env(cls):
return cls(
API_URL=os.environ.get("BRIGHTDATA_API_URL", "https://api.brightdata.com"),
DEFAULT_TIMEOUT=int(os.environ.get("BRIGHTDATA_DEFAULT_TIMEOUT", "600")),
DEFAULT_POLLING_INTERVAL=int(os.environ.get("BRIGHTDATA_DEFAULT_POLLING_INTERVAL", "1"))
)
class BrightDataDatasetToolException(Exception):
"""Exception raised for custom error in the application."""

Expand Down Expand Up @@ -48,10 +52,10 @@ class BrightDataDatasetToolSchema(BaseModel):
default=None, description="Additional params if any"
)

config = BrightDataConfig()
config = BrightDataConfig.from_env()

BRIGHTDATA_API_URL = config.API_URL
timeout = config.DEFAULT_TIMEOUT
BRIGHTDATA_API_URL = config.API_URL
timeout = config.DEFAULT_TIMEOUT

datasets = [
{
Expand Down Expand Up @@ -532,7 +536,7 @@ def _run(self, url: str = None, dataset_type: str = None, format: str = None, zi
url = url or self.url
zipcode = zipcode or self.zipcode
additional_params = additional_params or self.additional_params

if not dataset_type:
raise ValueError("dataset_type is required either in constructor or method call")
if not url:
Expand Down
19 changes: 11 additions & 8 deletions crewai_tools/tools/brightdata_tool/brightdata_serp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
import requests
from crewai.tools import BaseTool
from pydantic import BaseModel, Field
from pydantic_settings import BaseSettings

class BrightDataConfig(BaseSettings):
API_URL: str = "https://api.brightdata.com/request"
class Config:
env_prefix = "BRIGHTDATA_"
class BrightDataConfig(BaseModel):
API_URL: str = "https://api.brightdata.com/request"

@classmethod
def from_env(cls):
return cls(
API_URL=os.environ.get("BRIGHTDATA_API_URL", "https://api.brightdata.com/request")
)

class BrightDataSearchToolSchema(BaseModel):
"""
Expand Down Expand Up @@ -73,7 +76,7 @@ class BrightDataSearchTool(BaseTool):
name: str = "Bright Data SERP Search"
description: str = "Tool to perform web search using Bright Data SERP API."
args_schema: Type[BaseModel] = BrightDataSearchToolSchema
_config = BrightDataConfig()
_config = BrightDataConfig.from_env()
base_url: str = ""
api_key: str = ""
zone: str = ""
Expand All @@ -95,7 +98,7 @@ def __init__(self, query: str = None, search_engine: str = "google", country: st
self.search_type = search_type
self.device_type = device_type
self.parse_results = parse_results

self.api_key = os.getenv("BRIGHT_DATA_API_KEY")
self.zone = os.getenv("BRIGHT_DATA_ZONE")
if not self.api_key:
Expand Down Expand Up @@ -136,7 +139,7 @@ def _run(self, query: str = None, search_engine: str = None, country: str = None
device_type = device_type or self.device_type
parse_results = parse_results if parse_results is not None else self.parse_results
results_count = kwargs.get("results_count", "10")

# Validate required parameters
if not query:
raise ValueError("query is required either in constructor or method call")
Expand Down
21 changes: 12 additions & 9 deletions crewai_tools/tools/brightdata_tool/brightdata_unlocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
import requests
from crewai.tools import BaseTool
from pydantic import BaseModel, Field
from pydantic_settings import BaseSettings

class BrightDataConfig(BaseSettings):
API_URL: str = "https://api.brightdata.com/request"
class Config:
env_prefix = "BRIGHTDATA_"
class BrightDataConfig(BaseModel):
API_URL: str = "https://api.brightdata.com/request"

@classmethod
def from_env(cls):
return cls(
API_URL=os.environ.get("BRIGHTDATA_API_URL", "https://api.brightdata.com/request")
)

class BrightDataUnlockerToolSchema(BaseModel):
"""
Expand Down Expand Up @@ -57,7 +60,7 @@ class BrightDataWebUnlockerTool(BaseTool):
name: str = "Bright Data Web Unlocker Scraping"
description: str = "Tool to perform web scraping using Bright Data Web Unlocker"
args_schema: Type[BaseModel] = BrightDataUnlockerToolSchema
_config = BrightDataConfig()
_config = BrightDataConfig.from_env()
base_url: str = ""
api_key: str = ""
zone: str = ""
Expand All @@ -71,7 +74,7 @@ def __init__(self, url: str = None, format: str = "raw", data_format: str = "mar
self.url = url
self.format = format
self.data_format = data_format

self.api_key = os.getenv("BRIGHT_DATA_API_KEY")
self.zone = os.getenv("BRIGHT_DATA_ZONE")
if not self.api_key:
Expand All @@ -83,10 +86,10 @@ def _run(self, url: str = None, format: str = None, data_format: str = None, **k
url = url or self.url
format = format or self.format
data_format = data_format or self.data_format

if not url:
raise ValueError("url is required either in constructor or method call")

payload = {
"url": url,
"zone": self.zone,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from typing import Any, Optional, Type

from embedchain.models.data_type import DataType
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
Expand Down Expand Up @@ -37,6 +42,8 @@ def __init__(self, docs_url: Optional[str] = None, **kwargs):
self._generate_description()

def add(self, docs_url: str) -> None:
if not EMBEDCHAIN_AVAILABLE:
raise ImportError("embedchain is not installed. Please install it with `pip install crewai-tools[embedchain]`")
super().add(docs_url, data_type=DataType.DOCS_SITE)

def _run(
Expand Down
9 changes: 8 additions & 1 deletion crewai_tools/tools/csv_search_tool/csv_search_tool.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from typing import Optional, Type

from embedchain.models.data_type import DataType
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
Expand Down Expand Up @@ -37,6 +42,8 @@ def __init__(self, csv: Optional[str] = None, **kwargs):
self._generate_description()

def add(self, csv: str) -> None:
if not EMBEDCHAIN_AVAILABLE:
raise ImportError("embedchain is not installed. Please install it with `pip install crewai-tools[embedchain]`")
super().add(csv, data_type=DataType.CSV)

def _run(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from typing import Optional, Type

from embedchain.loaders.directory_loader import DirectoryLoader
try:
from embedchain.loaders.directory_loader import DirectoryLoader
EMBEDCHAIN_AVAILABLE = True
except ImportError:
EMBEDCHAIN_AVAILABLE = False

from pydantic import BaseModel, Field

from ..rag.rag_tool import RagTool
Expand Down Expand Up @@ -29,6 +34,8 @@ class DirectorySearchTool(RagTool):
args_schema: Type[BaseModel] = DirectorySearchToolSchema

def __init__(self, directory: Optional[str] = None, **kwargs):
if not EMBEDCHAIN_AVAILABLE:
raise ImportError("embedchain is not installed. Please install it with `pip install crewai-tools[embedchain]`")
super().__init__(**kwargs)
if directory is not None:
self.add(directory)
Expand Down
9 changes: 8 additions & 1 deletion crewai_tools/tools/docx_search_tool/docx_search_tool.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from typing import Any, Optional, Type

from embedchain.models.data_type import DataType
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
Expand Down Expand Up @@ -43,6 +48,8 @@ def __init__(self, docx: Optional[str] = None, **kwargs):
self._generate_description()

def add(self, docx: str) -> None:
if not EMBEDCHAIN_AVAILABLE:
raise ImportError("embedchain is not installed. Please install it with `pip install crewai-tools[embedchain]`")
super().add(docx, data_type=DataType.DOCX)

def _run(
Expand Down
13 changes: 10 additions & 3 deletions crewai_tools/tools/github_search_tool/github_search_tool.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from typing import List, Optional, Type
from typing import List, Optional, Type, Any

try:
from embedchain.loaders.github import GithubLoader
EMBEDCHAIN_AVAILABLE = True
except ImportError:
EMBEDCHAIN_AVAILABLE = False

from embedchain.loaders.github import GithubLoader
from pydantic import BaseModel, Field, PrivateAttr

from ..rag.rag_tool import RagTool
Expand Down Expand Up @@ -37,14 +42,16 @@ class GithubSearchTool(RagTool):
default_factory=lambda: ["code", "repo", "pr", "issue"],
description="Content types you want to be included search, options: [code, repo, pr, issue]",
)
_loader: GithubLoader | None = PrivateAttr(default=None)
_loader: Any | None = PrivateAttr(default=None)

def __init__(
self,
github_repo: Optional[str] = None,
content_types: Optional[List[str]] = None,
**kwargs,
):
if not EMBEDCHAIN_AVAILABLE:
raise ImportError("embedchain is not installed. Please install it with `pip install crewai-tools[embedchain]`")
super().__init__(**kwargs)
self._loader = GithubLoader(config={"token": self.gh_token})

Expand Down
9 changes: 8 additions & 1 deletion crewai_tools/tools/mdx_search_tool/mdx_search_tool.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from typing import Optional, Type

from embedchain.models.data_type import DataType
from pydantic import BaseModel, Field

try:
from embedchain.models.data_type import DataType
EMBEDCHAIN_AVAILABLE = True
except ImportError:
EMBEDCHAIN_AVAILABLE = False

from ..rag.rag_tool import RagTool


Expand Down Expand Up @@ -37,6 +42,8 @@ def __init__(self, mdx: Optional[str] = None, **kwargs):
self._generate_description()

def add(self, mdx: str) -> None:
if not EMBEDCHAIN_AVAILABLE:
raise ImportError("embedchain is not installed. Please install it with `pip install crewai-tools[embedchain]`")
super().add(mdx, data_type=DataType.MDX)

def _run(
Expand Down
9 changes: 8 additions & 1 deletion crewai_tools/tools/mysql_search_tool/mysql_search_tool.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from typing import Any, Type

from embedchain.loaders.mysql import MySQLLoader
try:
from embedchain.loaders.mysql import MySQLLoader
EMBEDCHAIN_AVAILABLE = True
except ImportError:
EMBEDCHAIN_AVAILABLE = False

from pydantic import BaseModel, Field

from ..rag.rag_tool import RagTool
Expand All @@ -22,6 +27,8 @@ class MySQLSearchTool(RagTool):
db_uri: str = Field(..., description="Mandatory database URI")

def __init__(self, table_name: str, **kwargs):
if not EMBEDCHAIN_AVAILABLE:
raise ImportError("embedchain is not installed. Please install it with `pip install crewai-tools[embedchain]`")
super().__init__(**kwargs)
kwargs["data_type"] = "mysql"
kwargs["loader"] = MySQLLoader(config=dict(url=self.db_uri))
Expand Down
Loading
Loading