diff --git a/src/crewai_tools/adapters/embedchain_adapter.py b/src/crewai_tools/adapters/embedchain_adapter.py index 446aab96c..1e7b83c0b 100644 --- a/src/crewai_tools/adapters/embedchain_adapter.py +++ b/src/crewai_tools/adapters/embedchain_adapter.py @@ -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) diff --git a/src/crewai_tools/adapters/pdf_embedchain_adapter.py b/src/crewai_tools/adapters/pdf_embedchain_adapter.py index 12557c971..aa682c84f 100644 --- a/src/crewai_tools/adapters/pdf_embedchain_adapter.py +++ b/src/crewai_tools/adapters/pdf_embedchain_adapter.py @@ -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} diff --git a/src/crewai_tools/tools/brightdata_tool/brightdata_dataset.py b/src/crewai_tools/tools/brightdata_tool/brightdata_dataset.py index bd0dcc1c3..88ca65077 100644 --- a/src/crewai_tools/tools/brightdata_tool/brightdata_dataset.py +++ b/src/crewai_tools/tools/brightdata_tool/brightdata_dataset.py @@ -5,15 +5,19 @@ from typing import Any, Dict, Optional, Type 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.""" @@ -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 = [ { @@ -532,7 +536,7 @@ class BrightDataDatasetTool(BaseTool): 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: diff --git a/src/crewai_tools/tools/brightdata_tool/brightdata_serp.py b/src/crewai_tools/tools/brightdata_tool/brightdata_serp.py index 3b1170713..ae197ce0f 100644 --- a/src/crewai_tools/tools/brightdata_tool/brightdata_serp.py +++ b/src/crewai_tools/tools/brightdata_tool/brightdata_serp.py @@ -5,12 +5,15 @@ from typing import Any, Optional, Type 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): """ @@ -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 = "" @@ -95,7 +98,7 @@ class BrightDataSearchTool(BaseTool): 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: @@ -136,7 +139,7 @@ class BrightDataSearchTool(BaseTool): 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") diff --git a/src/crewai_tools/tools/brightdata_tool/brightdata_unlocker.py b/src/crewai_tools/tools/brightdata_tool/brightdata_unlocker.py index fb8c2fb07..27864cb97 100644 --- a/src/crewai_tools/tools/brightdata_tool/brightdata_unlocker.py +++ b/src/crewai_tools/tools/brightdata_tool/brightdata_unlocker.py @@ -4,12 +4,15 @@ from typing import Any, Optional, Type 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): """ @@ -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 = "" @@ -71,7 +74,7 @@ class BrightDataWebUnlockerTool(BaseTool): 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: @@ -83,10 +86,10 @@ class BrightDataWebUnlockerTool(BaseTool): 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, diff --git a/src/crewai_tools/tools/code_docs_search_tool/code_docs_search_tool.py b/src/crewai_tools/tools/code_docs_search_tool/code_docs_search_tool.py index 05711d7bc..155b4390d 100644 --- a/src/crewai_tools/tools/code_docs_search_tool/code_docs_search_tool.py +++ b/src/crewai_tools/tools/code_docs_search_tool/code_docs_search_tool.py @@ -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 @@ -37,6 +42,8 @@ class CodeDocsSearchTool(RagTool): 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( diff --git a/src/crewai_tools/tools/csv_search_tool/csv_search_tool.py b/src/crewai_tools/tools/csv_search_tool/csv_search_tool.py index 05572d8bb..4be84efdd 100644 --- a/src/crewai_tools/tools/csv_search_tool/csv_search_tool.py +++ b/src/crewai_tools/tools/csv_search_tool/csv_search_tool.py @@ -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 @@ -37,6 +42,8 @@ class CSVSearchTool(RagTool): 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( diff --git a/src/crewai_tools/tools/directory_search_tool/directory_search_tool.py b/src/crewai_tools/tools/directory_search_tool/directory_search_tool.py index 20d21731a..30fdd52cc 100644 --- a/src/crewai_tools/tools/directory_search_tool/directory_search_tool.py +++ b/src/crewai_tools/tools/directory_search_tool/directory_search_tool.py @@ -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 @@ -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) diff --git a/src/crewai_tools/tools/docx_search_tool/docx_search_tool.py b/src/crewai_tools/tools/docx_search_tool/docx_search_tool.py index a9d2c9610..97dab02cd 100644 --- a/src/crewai_tools/tools/docx_search_tool/docx_search_tool.py +++ b/src/crewai_tools/tools/docx_search_tool/docx_search_tool.py @@ -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 @@ -43,6 +48,8 @@ class DOCXSearchTool(RagTool): 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( diff --git a/src/crewai_tools/tools/github_search_tool/github_search_tool.py b/src/crewai_tools/tools/github_search_tool/github_search_tool.py index 51fe4033c..afde4fe92 100644 --- a/src/crewai_tools/tools/github_search_tool/github_search_tool.py +++ b/src/crewai_tools/tools/github_search_tool/github_search_tool.py @@ -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 @@ -37,7 +42,7 @@ 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, @@ -45,6 +50,8 @@ class GithubSearchTool(RagTool): 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}) diff --git a/src/crewai_tools/tools/mdx_search_tool/mdx_search_tool.py b/src/crewai_tools/tools/mdx_search_tool/mdx_search_tool.py index 14afe5db7..807da62fe 100644 --- a/src/crewai_tools/tools/mdx_search_tool/mdx_search_tool.py +++ b/src/crewai_tools/tools/mdx_search_tool/mdx_search_tool.py @@ -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 @@ -37,6 +42,8 @@ class MDXSearchTool(RagTool): 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( diff --git a/src/crewai_tools/tools/mysql_search_tool/mysql_search_tool.py b/src/crewai_tools/tools/mysql_search_tool/mysql_search_tool.py index a472e1761..8c2c5ef5d 100644 --- a/src/crewai_tools/tools/mysql_search_tool/mysql_search_tool.py +++ b/src/crewai_tools/tools/mysql_search_tool/mysql_search_tool.py @@ -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 @@ -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)) diff --git a/src/crewai_tools/tools/nl2sql/nl2sql_tool.py b/src/crewai_tools/tools/nl2sql/nl2sql_tool.py index 786550ee7..f3d892d1a 100644 --- a/src/crewai_tools/tools/nl2sql/nl2sql_tool.py +++ b/src/crewai_tools/tools/nl2sql/nl2sql_tool.py @@ -2,8 +2,13 @@ from typing import Any, Type, Union from crewai.tools import BaseTool from pydantic import BaseModel, Field -from sqlalchemy import create_engine, text -from sqlalchemy.orm import sessionmaker + +try: + from sqlalchemy import create_engine, text + from sqlalchemy.orm import sessionmaker + SQLALCHEMY_AVAILABLE = True +except ImportError: + SQLALCHEMY_AVAILABLE = False class NL2SQLToolInput(BaseModel): @@ -25,6 +30,9 @@ class NL2SQLTool(BaseTool): args_schema: Type[BaseModel] = NL2SQLToolInput def model_post_init(self, __context: Any) -> None: + if not SQLALCHEMY_AVAILABLE: + raise ImportError("sqlalchemy is not installed. Please install it with `pip install crewai-tools[sqlalchemy]`") + data = {} tables = self._fetch_available_tables() @@ -58,6 +66,9 @@ class NL2SQLTool(BaseTool): return data def execute_sql(self, sql_query: str) -> Union[list, str]: + if not SQLALCHEMY_AVAILABLE: + raise ImportError("sqlalchemy is not installed. Please install it with `pip install crewai-tools[sqlalchemy]`") + engine = create_engine(self.db_uri) Session = sessionmaker(bind=engine) session = Session() diff --git a/src/crewai_tools/tools/pdf_search_tool/pdf_search_tool.py b/src/crewai_tools/tools/pdf_search_tool/pdf_search_tool.py index ad0b8f8d3..96f141c17 100644 --- a/src/crewai_tools/tools/pdf_search_tool/pdf_search_tool.py +++ b/src/crewai_tools/tools/pdf_search_tool/pdf_search_tool.py @@ -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 @@ -36,6 +41,8 @@ class PDFSearchTool(RagTool): self._generate_description() def add(self, pdf: str) -> None: + if not EMBEDCHAIN_AVAILABLE: + raise ImportError("embedchain is not installed. Please install it with `pip install crewai-tools[embedchain]`") super().add(pdf, data_type=DataType.PDF_FILE) def _run( diff --git a/src/crewai_tools/tools/pg_search_tool/pg_search_tool.py b/src/crewai_tools/tools/pg_search_tool/pg_search_tool.py index ec0207aa7..30e294944 100644 --- a/src/crewai_tools/tools/pg_search_tool/pg_search_tool.py +++ b/src/crewai_tools/tools/pg_search_tool/pg_search_tool.py @@ -1,6 +1,11 @@ from typing import Any, Type -from embedchain.loaders.postgres import PostgresLoader +try: + from embedchain.loaders.postgres import PostgresLoader + EMBEDCHAIN_AVAILABLE = True +except ImportError: + EMBEDCHAIN_AVAILABLE = False + from pydantic import BaseModel, Field from ..rag.rag_tool import RagTool @@ -22,6 +27,8 @@ class PGSearchTool(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"] = "postgres" kwargs["loader"] = PostgresLoader(config=dict(url=self.db_uri)) diff --git a/src/crewai_tools/tools/rag/rag_tool.py b/src/crewai_tools/tools/rag/rag_tool.py index f7e785bd7..1a9fad8b8 100644 --- a/src/crewai_tools/tools/rag/rag_tool.py +++ b/src/crewai_tools/tools/rag/rag_tool.py @@ -40,7 +40,11 @@ class RagTool(BaseTool): @model_validator(mode="after") def _set_default_adapter(self): if isinstance(self.adapter, RagTool._AdapterPlaceholder): - from embedchain import App + try: + from embedchain import App + except ImportError: + raise ImportError("embedchain is not installed. Please install it with `pip install crewai-tools[embedchain]`") + from crewai_tools.adapters.embedchain_adapter import EmbedchainAdapter with portalocker.Lock("crewai-rag-tool.lock", timeout=10): diff --git a/src/crewai_tools/tools/scrape_element_from_website/scrape_element_from_website.py b/src/crewai_tools/tools/scrape_element_from_website/scrape_element_from_website.py index f1e215bf3..61f5d9c8c 100644 --- a/src/crewai_tools/tools/scrape_element_from_website/scrape_element_from_website.py +++ b/src/crewai_tools/tools/scrape_element_from_website/scrape_element_from_website.py @@ -2,10 +2,15 @@ import os from typing import Any, Optional, Type import requests -from bs4 import BeautifulSoup from crewai.tools import BaseTool from pydantic import BaseModel, Field +try: + from bs4 import BeautifulSoup + BEAUTIFULSOUP_AVAILABLE = True +except ImportError: + BEAUTIFULSOUP_AVAILABLE = False + class FixedScrapeElementFromWebsiteToolSchema(BaseModel): """Input for ScrapeElementFromWebsiteTool.""" @@ -61,6 +66,9 @@ class ScrapeElementFromWebsiteTool(BaseTool): self, **kwargs: Any, ) -> Any: + if not BEAUTIFULSOUP_AVAILABLE: + raise ImportError("beautifulsoup4 is not installed. Please install it with `pip install crewai-tools[beautifulsoup4]`") + website_url = kwargs.get("website_url", self.website_url) css_element = kwargs.get("css_element", self.css_element) page = requests.get( diff --git a/src/crewai_tools/tools/scrape_website_tool/scrape_website_tool.py b/src/crewai_tools/tools/scrape_website_tool/scrape_website_tool.py index bfb371275..262e79a69 100644 --- a/src/crewai_tools/tools/scrape_website_tool/scrape_website_tool.py +++ b/src/crewai_tools/tools/scrape_website_tool/scrape_website_tool.py @@ -3,7 +3,11 @@ import re from typing import Any, Optional, Type import requests -from bs4 import BeautifulSoup +try: + from bs4 import BeautifulSoup + BEAUTIFULSOUP_AVAILABLE = True +except ImportError: + BEAUTIFULSOUP_AVAILABLE = False from crewai.tools import BaseTool from pydantic import BaseModel, Field @@ -40,6 +44,9 @@ class ScrapeWebsiteTool(BaseTool): **kwargs, ): super().__init__(**kwargs) + if not BEAUTIFULSOUP_AVAILABLE: + raise ImportError("beautifulsoup4 is not installed. Please install it with `pip install crewai-tools[beautifulsoup4]`") + if website_url is not None: self.website_url = website_url self.description = ( diff --git a/src/crewai_tools/tools/website_search/website_search_tool.py b/src/crewai_tools/tools/website_search/website_search_tool.py index b89af6656..9728b44db 100644 --- a/src/crewai_tools/tools/website_search/website_search_tool.py +++ b/src/crewai_tools/tools/website_search/website_search_tool.py @@ -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 @@ -39,6 +44,8 @@ class WebsiteSearchTool(RagTool): 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( diff --git a/src/crewai_tools/tools/youtube_channel_search_tool/youtube_channel_search_tool.py b/src/crewai_tools/tools/youtube_channel_search_tool/youtube_channel_search_tool.py index 9de4b568f..6d16a708d 100644 --- a/src/crewai_tools/tools/youtube_channel_search_tool/youtube_channel_search_tool.py +++ b/src/crewai_tools/tools/youtube_channel_search_tool/youtube_channel_search_tool.py @@ -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 diff --git a/src/crewai_tools/tools/youtube_video_search_tool/youtube_video_search_tool.py b/src/crewai_tools/tools/youtube_video_search_tool/youtube_video_search_tool.py index 639f1a266..b93cc6c29 100644 --- a/src/crewai_tools/tools/youtube_video_search_tool/youtube_video_search_tool.py +++ b/src/crewai_tools/tools/youtube_video_search_tool/youtube_video_search_tool.py @@ -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 @@ -39,6 +44,8 @@ class YoutubeVideoSearchTool(RagTool): self._generate_description() def add(self, youtube_video_url: str) -> None: + if not EMBEDCHAIN_AVAILABLE: + raise ImportError("embedchain is not installed. Please install it with `pip install crewai-tools[embedchain]`") super().add(youtube_video_url, data_type=DataType.YOUTUBE_VIDEO) def _run(