diff --git a/pyproject.toml b/pyproject.toml index a7c3664..76d6865 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,10 @@ pillow = "*" pydantic = ">=1.10.8" tokenizers = ">=0.14.0" langchain-text-splitters = ">=0.3.8" -ffmpeg-python = "*" +ffmpeg-python = {version = "*", optional = true} + +[tool.poetry.extras] +video = ["ffmpeg-python"] [tool.poetry.group.test.dependencies] pytest = "^7.4.2" diff --git a/voyageai/__init__.py b/voyageai/__init__.py index 452328e..5a3c07a 100644 --- a/voyageai/__init__.py +++ b/voyageai/__init__.py @@ -36,6 +36,19 @@ ) from voyageai.version import VERSION + +def _is_ffmpeg_available() -> bool: + """Check if ffmpeg-python is installed.""" + try: + import ffmpeg # noqa: F401 + + return True + except ImportError: + return False + + +HAS_VIDEO = _is_ffmpeg_available() + if TYPE_CHECKING: import requests from aiohttp import ClientSession diff --git a/voyageai/video_utils.py b/voyageai/video_utils.py index 8acb12a..f2ee4db 100644 --- a/voyageai/video_utils.py +++ b/voyageai/video_utils.py @@ -187,8 +187,8 @@ def _load_video_bytes(video: Union[str, PathLike[str], bytes, Video]) -> bytes: def _ensure_ffmpeg_available() -> None: if ffmpeg is None: raise ImportError( - "ffmpeg-python is required for video optimization. " - "Install `ffmpeg-python` and ensure `ffmpeg` is available on PATH." + "The 'ffmpeg-python' package is required for video optimization. " + "Install it with: pip install voyageai[video]" ) if shutil.which("ffmpeg") is None: raise EnvironmentError(