🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org
Python agentai-societiesartificial-intelligencecommunicative-aicooperative-aideep-learninglarge-language-modelsmulti-agent-systemsnatural-language-processing
feat: Add ExcelToolkit (#1739)
Wendong-Fanfee590562c43
diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.ymlindex a87369066..947ea8a5e 100644--- a/.github/workflows/documentation.yml+++ b/.github/workflows/documentation.yml@@ -26,6 +26,7 @@ jobs:- name: Sphinx buildrun: |+ source .venv/bin/activatecd docsmake htmldiff --git a/camel/toolkits/__init__.py b/camel/toolkits/__init__.pyindex 158e06da1..920126e57 100644--- a/camel/toolkits/__init__.py+++ b/camel/toolkits/__init__.py@@ -43,13 +43,15 @@ from .retrieval_toolkit import RetrievalToolkitfrom .notion_toolkit import NotionToolkitfrom .human_toolkit import HumanToolkitfrom .stripe_toolkit import StripeToolkit-from .video_toolkit import VideoDownloaderToolkit+from .video_download_toolkit import VideoDownloaderToolkitfrom .dappier_toolkit import DappierToolkitfrom .networkx_toolkit import NetworkXToolkitfrom .semantic_scholar_toolkit import SemanticScholarToolkitfrom .zapier_toolkit import ZapierToolkitfrom .sympy_toolkit import SymPyToolkitfrom .mineru_toolkit import MinerUToolkit+from .excel_toolkit import ExcelToolkit+from .video_analysis_toolkit import VideoAnalysisToolkitfrom .image_analysis_toolkit import ImageAnalysisToolkit@@ -89,5 +91,7 @@ __all__ = ['ZapierToolkit','SymPyToolkit','MinerUToolkit',+ 'ExcelToolkit',+ 'VideoAnalysisToolkit','ImageAnalysisToolkit',]diff --git a/camel/toolkits/excel_toolkit.py b/camel/toolkits/excel_toolkit.pynew file mode 100644index 000000000..dc6b55fb6--- /dev/null+++ b/camel/toolkits/excel_toolkit.py@@ -0,0 +1,172 @@+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========++from typing import List++import pandas as pd++from camel.logger import get_logger+from camel.toolkits.base import BaseToolkit+from camel.toolkits.function_tool import FunctionTool++logger = get_logger(__name__)+++class ExcelToolkit(BaseToolkit):+ r"""A class representing a toolkit for extract detailed cell information+ from an Excel file.++ This class provides method for processing docx, pdf, pptx, etc. It cannot+ process excel files.+ """++ def _convert_to_markdown(self, df: pd.DataFrame) -> str:+ r"""Convert DataFrame to Markdown format table.++ Args:+ df (pd.DataFrame): DataFrame containing the Excel data.++ Returns:+ str: Markdown formatted table.+ """+ from tabulate import tabulate++ md_table = tabulate(df, headers='keys', tablefmt='pipe')+ return str(md_table)++ def extract_excel_content(self, document_path: str) -> str:+ r"""Extract detailed cell information from an Excel file, including+ multiple sheets.++ Args:+ document_path (str): The path of the Excel file.++ Returns:+ str: Extracted excel information, including details of each sheet.+ """+ from openpyxl import load_workbook+ from xls2xlsx import XLS2XLSX++ logger.debug(+ f"Calling extract_excel_content with document_path"+ f": {document_path}"+ )++ if not (+ document_path.endswith("xls")+ or document_path.endswith("xlsx")+ or document_path.endswith("csv")+ ):+ logger.error("Only xls, xlsx, csv files are supported.")+ return (+ f"Failed to process file {document_path}: "+ f"It is not excel format. Please try other ways."+ )++ if document_path.endswith("csv"):+ try:+ df = pd.read_csv(document_path)+ md_table = self._convert_to_markdown(df)+ return f"CSV File Processed:\n{md_table}"+ except Exception as e:+ logger.error(f"Failed to process file {document_path}: {e}")+ return f"Failed to process file {document_path}: {e}"++ if document_path.endswith("xls"):+ output_path = document_path.replace(".xls", ".xlsx")+ x2x = XLS2XLSX(document_path)+ x2x.to_xlsx(output_path)+ document_path = output_path++ # Load the Excel workbook+ wb = load_workbook(document_path, data_only=True)+ sheet_info_list = []++ # Iterate through all sheets+ for sheet in wb.sheetnames:+ ws = wb[sheet]+ cell_info_list = []++ for row in ws.iter_rows():+ for cell in row:+ row_num = cell.row+ col_letter = cell.column_letter++ cell_value = cell.value++ font_color = None+ if (+ cell.font+ and cell.font.color+ and "rgb=None" not in str(cell.font.color)+ ): # Handle font color+ font_color = cell.font.color.rgb++ fill_color = None+ if (+ cell.fill+ and cell.fill.fgColor+ and "rgb=None" not in str(cell.fill.fgColor)+ ): # Handle fill color+ fill_color = cell.fill.fgColor.rgb++ cell_info_list.append(+ {+ "index": f"{row_num}{col_letter}",+ "value": cell_value,+ "font_color": font_color,+ "fill_color": fill_color,+ }+ )++ # Convert the sheet to a DataFrame and then to markdown+ sheet_df = pd.read_excel(+ document_path, sheet_name=sheet, engine='openpyxl'+ )+ markdown_content = self._convert_to_markdown(sheet_df)++ # Collect all information for the sheet+ sheet_info = {+ "sheet_name": sheet,+ "cell_info_list": cell_info_list,+ "markdown_content": markdown_content,+ }+ sheet_info_list.append(sheet_info)++ result_str = ""+ for sheet_info in sheet_info_list:+ result_str += f"""+ Sheet Name: {sheet_info['sheet_name']}+ Cell information list:+ {sheet_info['cell_info_list']}++ Markdown View of the content:+ {sheet_info['markdown_content']}++ {'-'*40}+ """++ return result_str++ def get_tools(self) -> List[FunctionTool]:+ r"""Returns a list of FunctionTool objects representing the functions+ in the toolkit.++ Returns:+ List[FunctionTool]: A list of FunctionTool objects representing+ the functions in the toolkit.+ """+ return [+ FunctionTool(self.extract_excel_content),+ ]diff --git a/camel/toolkits/video_analysis_toolkit.py b/camel/toolkits/video_analysis_toolkit.pynew file mode 100644index 000000000..6cc593893--- /dev/null+++ b/camel/toolkits/video_analysis_toolkit.py@@ -0,0 +1,407 @@+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========++import os+import tempfile+from pathlib import Path+from typing import List, Optional++from PIL import Image++from camel.logger import get_logger+from camel.messages import BaseMessage+from camel.models import BaseModelBackend, OpenAIAudioModels+from camel.toolkits.base import BaseToolkit+from camel.toolkits.function_tool import FunctionTool+from camel.utils import dependencies_required++from .video_download_toolkit import (+ VideoDownloaderToolkit,+ _capture_screenshot,+)++logger = get_logger(__name__)++VIDEO_QA_PROMPT = """+Analyze the provided video frames and corresponding audio transcription to \+answer the given question(s) thoroughly and accurately.++Instructions:+ 1. Visual Analysis:+ - Examine the video frames to identify visible entities.+ - Differentiate objects, species, or features based on key attributes \+such as size, color, shape, texture, or behavior.+ - Note significant groupings, interactions, or contextual patterns \+relevant to the analysis.++ 2. Audio Integration:+ - Use the audio transcription to complement or clarify your visual \+observations.+ - Identify names, descriptions, or contextual hints in the \+transcription that help confirm or refine your visual analysis.++ 3. Detailed Reasoning and Justification:+ - Provide a brief explanation of how you identified and distinguished \+each species or object.+ - Highlight specific features or contextual clues that informed \+your reasoning.++ 4. Comprehensive Answer:+ - Specify the total number of distinct species or object types \+identified in the video.+ - Describe the defining characteristics and any supporting evidence \+from the video and transcription.++ 5. Important Considerations:+ - Pay close attention to subtle differences that could distinguish \+similar-looking species or objects+ (e.g., juveniles vs. adults, closely related species).+ - Provide concise yet complete explanations to ensure clarity.++**Audio Transcription:**+{audio_transcription}++**Question:**+{question}+"""+++class VideoAnalysisToolkit(BaseToolkit):+ r"""A class for analysing videos with vision-language model.++ Args:+ download_directory (Optional[str], optional): The directory where the+ video will be downloaded to. If not provided, video will be stored+ in a temporary directory and will be cleaned up after use.+ (default: :obj:`None`)+ model (Optional[BaseModelBackend], optional): The model to use for+ visual analysis. (default: :obj:`None`)+ use_audio_transcription (bool, optional): Whether to enable audio+ transcription using OpenAI's audio models. Requires a valid OpenAI+ API key. When disabled, video analysis will be based solely on+ visual content. (default: :obj:`False`)+ """++ @dependencies_required("ffmpeg", "scenedetect")+ def __init__(+ self,+ download_directory: Optional[str] = None,+ model: Optional[BaseModelBackend] = None,+ use_audio_transcription: bool = False,+ ) -> None:+ self._cleanup = download_directory is None+ self._temp_files: list[str] = [] # Track temporary files for cleanup+ self._use_audio_transcription = use_audio_transcription++ self._download_directory = Path(+ download_directory or tempfile.mkdtemp()+ ).resolve()++ self.video_downloader_toolkit = VideoDownloaderToolkit(+ download_directory=str(self._download_directory)+ )++ try:+ self._download_directory.mkdir(parents=True, exist_ok=True)+ except FileExistsError:+ raise ValueError(+ f"{self._download_directory} is not a valid directory."+ )+ except OSError as e:+ raise ValueError(+ f"Error creating directory {self._download_directory}: {e}"+ )++ logger.info(f"Video will be downloaded to {self._download_directory}")++ self.vl_model = model+ # Ensure ChatAgent is initialized with a model if provided+ if self.vl_model:+ # Import ChatAgent at runtime to avoid circular imports+ from camel.agents import ChatAgent++ self.vl_agent = ChatAgent(model=self.vl_model)+ else:+ # If no model is provided, use default model in ChatAgent+ # Import ChatAgent at runtime to avoid circular imports+ from camel.agents import ChatAgent++ self.vl_agent = ChatAgent()+ logger.warning(+ "No vision-language model provided. Using default model in"+ " ChatAgent."+ )++ # Initialize audio models only if audio transcription is enabled+ self.audio_models = None+ if self._use_audio_transcription:+ try:+ self.audio_models = OpenAIAudioModels()+ except Exception as e:+ logger.warning(+ f"Failed to initialize OpenAIAudioModels: {e}. "+ "Audio transcription will be disabled."+ )+ self._use_audio_transcription = False++ def __del__(self):+ r"""Clean up temporary directories and files when the object is+ destroyed.+ """+ # Clean up temporary files+ for temp_file in self._temp_files:+ if os.path.exists(temp_file):+ try:+ os.remove(temp_file)+ logger.debug(f"Removed temporary file: {temp_file}")+ except OSError as e:+ logger.warning(+ f"Failed to remove temporary file {temp_file}: {e}"+ )++ # Clean up temporary directory if needed+ if self._cleanup and os.path.exists(self._download_directory):+ try:+ import shutil++ shutil.rmtree(self._download_directory)+ logger.debug(+ f"Removed temporary directory: {self._download_directory}"+ )+ except OSError as e:+ logger.warning(+ f"Failed to remove temporary directory"+ f" {self._download_directory}: {e}"+ )++ def _extract_audio_from_video(+ self, video_path: str, output_format: str = "mp3"+ ) -> str:+ r"""Extract audio from the video.++ Args:+ video_path (str): The path to the video file.+ output_format (str): The format of the audio file to be saved.+ (default: :obj:`"mp3"`)++ Returns:+ str: The path to the audio file.+ """+ import ffmpeg++ # Handle case where video file doesn't have an extension+ base_path = os.path.splitext(video_path)[0]+ output_path = f"{base_path}.{output_format}"++ try:+ (+ ffmpeg.input(video_path)+ .output(output_path, vn=None, acodec="libmp3lame")+ .run(quiet=True)+ )+ # Track the audio file for cleanup+ self._temp_files.append(output_path)+ return output_path+ except ffmpeg.Error as e:+ error_message = f"FFmpeg-Python failed: {e}"+ logger.error(error_message)+ raise RuntimeError(error_message)++ def _transcribe_audio(self, audio_path: str) -> str:+ r"""Transcribe the audio of the video."""+ # Check if audio transcription is enabled and audio models are+ # available+ if not self._use_audio_transcription or self.audio_models is None:+ logger.warning("Audio transcription is disabled or not available")+ return "No audio transcription available."++ try:+ audio_transcript = self.audio_models.speech_to_text(audio_path)+ if not audio_transcript:+ logger.warning("Audio transcription returned empty result")+ return "No audio transcription available."+ return audio_transcript+ except Exception as e:+ logger.error(f"Audio transcription failed: {e}")+ return "Audio transcription failed."++ def _extract_keyframes(+ self, video_path: str, num_frames: int, threshold: float = 25.0+ ) -> List[Image.Image]:+ r"""Extract keyframes from a video based on scene changes+ and return them as PIL.Image.Image objects.++ Args:+ video_path (str): Path to the video file.+ num_frames (int): Number of keyframes to extract.+ threshold (float): The threshold value for scene change detection.++ Returns:+ list: A list of PIL.Image.Image objects representing+ the extracted keyframes.+ """+ from scenedetect import ( # type: ignore[import-untyped]+ SceneManager,+ VideoManager,+ )+ from scenedetect.detectors import ( # type: ignore[import-untyped]+ ContentDetector,+ )++ if num_frames <= 0:+ logger.warning(+ f"Invalid num_frames: {num_frames}, using default of 1"+ )+ num_frames = 1++ video_manager = VideoManager([video_path])+ scene_manager = SceneManager()+ scene_manager.add_detector(ContentDetector(threshold=threshold))++ video_manager.set_duration()+ video_manager.start()+ scene_manager.detect_scenes(video_manager)++ scenes = scene_manager.get_scene_list()+ keyframes: List[Image.Image] = []++ # Handle case where no scenes are detected+ if not scenes:+ logger.warning(+ "No scenes detected in video, capturing frames at "+ "regular intervals"+ )+ import cv2++ cap = cv2.VideoCapture(video_path)+ total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))+ fps = cap.get(cv2.CAP_PROP_FPS)+ duration = total_frames / fps if fps > 0 else 0++ if duration > 0 and total_frames > 0:+ # Extract frames at regular intervals+ interval = duration / min(num_frames, total_frames)+ for i in range(min(num_frames, total_frames)):+ time_sec = i * interval+ frame = _capture_screenshot(video_path, time_sec)+ keyframes.append(frame)++ cap.release()+ else:+ # Extract frames from detected scenes+ for start_time, _ in scenes:+ if len(keyframes) >= num_frames:+ break+ frame = _capture_screenshot(video_path, start_time)+ keyframes.append(frame)++ if not keyframes:+ logger.error("Failed to extract any keyframes from video")+ raise ValueError("Failed to extract keyframes from video")++ logger.info(f"Extracted {len(keyframes)} keyframes")+ return keyframes++ def ask_question_about_video(+ self,+ video_path: str,+ question: str,+ num_frames: int = 28,+ ) -> str:+ r"""Ask a question about the video.++ Args:+ video_path (str): The path to the video file.+ It can be a local file or a URL (such as Youtube website).+ question (str): The question to ask about the video.+ num_frames (int): The number of frames to extract from the video.+ To be adjusted based on the length of the video.+ (default: :obj:`28`)++ Returns:+ str: The answer to the question.+ """+ from urllib.parse import urlparse++ if not question:+ raise ValueError("Question cannot be empty")++ if num_frames <= 0:+ logger.warning(+ f"Invalid num_frames: {num_frames}, using default of 28"+ )+ num_frames = 28++ parsed_url = urlparse(video_path)+ is_url = all([parsed_url.scheme, parsed_url.netloc])++ downloaded_video_path = None+ try:+ if is_url:+ downloaded_video_path = (+ self.video_downloader_toolkit.download_video(video_path)+ )+ if not downloaded_video_path or not os.path.exists(+ downloaded_video_path+ ):+ raise ValueError(+ f"Failed to download video from {video_path}"+ )+ video_path = downloaded_video_path++ if not os.path.exists(video_path):+ raise FileNotFoundError(f"Video file not found: {video_path}")++ audio_transcript = "No audio transcription available."+ if self._use_audio_transcription:+ audio_path = self._extract_audio_from_video(video_path)+ audio_transcript = self._transcribe_audio(audio_path)++ video_frames = self._extract_keyframes(video_path, num_frames)+ prompt = VIDEO_QA_PROMPT.format(+ audio_transcription=audio_transcript,+ question=question,+ )++ msg = BaseMessage.make_user_message(+ role_name="User",+ content=prompt,+ image_list=video_frames,+ )++ response = self.vl_agent.step(msg)+ if not response or not response.msgs:+ logger.error("Model returned empty response")+ return (+ "Failed to generate an answer. "+ "The model returned an empty response."+ )++ answer = response.msgs[0].content+ return answer++ except Exception as e:+ error_message = f"Error processing video: {e!s}"+ logger.error(error_message)+ return f"Error: {error_message}"++ def get_tools(self) -> List[FunctionTool]:+ r"""Returns a list of FunctionTool objects representing the+ functions in the toolkit.++ Returns:+ List[FunctionTool]: A list of FunctionTool objects representing+ the functions in the toolkit.+ """+ return [FunctionTool(self.ask_question_about_video)]diff --git a/camel/toolkits/video_toolkit.py b/camel/toolkits/video_download_toolkit.pysimilarity index 87%rename from camel/toolkits/video_toolkit.pyrename to camel/toolkits/video_download_toolkit.pyindex 4a5a5c510..cd0bd68f6 100644--- a/camel/toolkits/video_toolkit.py+++ b/camel/toolkits/video_download_toolkit.py@@ -13,32 +13,19 @@# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========import io-import logging-import reimport tempfilefrom pathlib import Pathfrom typing import List, Optional+from urllib.parse import urlparsefrom PIL import Image+from camel.logger import get_loggerfrom camel.toolkits.base import BaseToolkitfrom camel.toolkits.function_tool import FunctionToolfrom camel.utils import dependencies_required-logger = logging.getLogger(__name__)---def _standardize_url(url: str) -> str:- r"""Standardize the given URL."""- # Special case for YouTube embed URLs- if "youtube.com/embed/" in url:- match = re.search(r"embed/([a-zA-Z0-9_-]+)", url)- if match:- return f"https://www.youtube.com/watch?v={match.group(1)}"- else:- raise ValueError(f"Invalid YouTube URL: {url}")-- return url+logger = get_logger(__name__)def _capture_screenshot(video_file: str, timestamp: float) -> Image.Image:@@ -119,7 +106,7 @@ class VideoDownloaderToolkit(BaseToolkit):if self._cleanup:shutil.rmtree(self._download_directory, ignore_errors=True)- def _download_video(self, url: str) -> str:+ def download_video(self, url: str) -> str:r"""Download the video and optionally split it into chunks.yt-dlp will detect if the video is downloaded automatically so there@@ -149,18 +136,21 @@ class VideoDownloaderToolkit(BaseToolkit):def get_video_bytes(self,- video_url: str,+ video_path: str,) -> bytes:- r"""Download video by the URL, and return the content in bytes.+ r"""Download video by the path, and return the content in bytes.Args:- video_url (str): The URL of the video to download.+ video_path (str): The path to the video file.Returns:bytes: The video file content in bytes."""- url = _standardize_url(video_url)- video_file = self._download_video(url)+ parsed_url = urlparse(video_path)+ is_url = all([parsed_url.scheme, parsed_url.netloc])+ if is_url:+ video_path = self.download_video(video_path)+ video_file = video_pathwith open(video_file, 'rb') as f:video_bytes = f.read()@@ -168,7 +158,7 @@ class VideoDownloaderToolkit(BaseToolkit):return video_bytesdef get_video_screenshots(- self, video_url: str, amount: int+ self, video_path: str, amount: int) -> List[Image.Image]:r"""Capture screenshots from the video at specified timestamps or bydividing the video into equal parts if an integer is provided.@@ -182,8 +172,11 @@ class VideoDownloaderToolkit(BaseToolkit):"""import ffmpeg- url = _standardize_url(video_url)- video_file = self._download_video(url)+ parsed_url = urlparse(video_path)+ is_url = all([parsed_url.scheme, parsed_url.netloc])+ if is_url:+ video_path = self.download_video(video_path)+ video_file = video_path# Get the video lengthtry:@@ -208,6 +201,7 @@ class VideoDownloaderToolkit(BaseToolkit):the functions in the toolkit."""return [+ FunctionTool(self.download_video),FunctionTool(self.get_video_bytes),FunctionTool(self.get_video_screenshots),]diff --git a/examples/toolkits/excel_toolkit.py b/examples/toolkits/excel_toolkit.pynew file mode 100644index 000000000..39a9130fa--- /dev/null+++ b/examples/toolkits/excel_toolkit.py@@ -0,0 +1,101 @@+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========++import os+import tempfile++import pandas as pd++from camel.agents import ChatAgent+from camel.configs import ChatGPTConfig+from camel.models import ModelFactory+from camel.toolkits import ExcelToolkit+from camel.types import ModelPlatformType, ModelType++# Create a sample Excel file for demonstration+temp_file = tempfile.NamedTemporaryFile(suffix=".csv", delete=False)+sample_file_path = temp_file.name++# Create a sample DataFrame+df = pd.DataFrame(+ {+ 'Name': ['Alice', 'Bob', 'Charlie'],+ 'Age': [25, 30, 35],+ 'City': ['New York', 'San Francisco', 'Seattle'],+ 'Department': ['Engineering', 'Marketing', 'Finance'],+ }+)++# Save the DataFrame to the CSV file+df.to_csv(sample_file_path, index=False)+print(f"Created sample Excel file at: {sample_file_path}")++# Initialize the Excel toolkit+excel_toolkit = ExcelToolkit()++# Create a model using OpenAI+model = ModelFactory.create(+ model_platform=ModelPlatformType.OPENAI,+ model_type=ModelType.GPT_4O_MINI,+ model_config_dict=ChatGPTConfig(+ temperature=0.0,+ ).as_dict(),+)++# Create a chat agent with the Excel toolkit+agent = ChatAgent(+ system_message=(+ "You are a helpful assistant that can analyze Excel files. "+ "Use the provided Excel toolkit to extract and analyze data."+ ),+ model=model,+ tools=[*excel_toolkit.get_tools()],+)++# Example: Ask the agent to analyze the Excel file+response = agent.step(+ f"Analyze the Excel file at {sample_file_path} and tell me what data "+ f"it contains."+)++print(response.msgs[0].content)++# Clean up the temporary file+if os.path.exists(sample_file_path):+ os.remove(sample_file_path)+ print(f"Removed temporary file: {sample_file_path}")++'''+===============================================================================+Created sample Excel file at: /var/folders/93/f_71_t957cq9cmq2gsybs4_40000gn/T/+tmpqweue66k.csv+The Excel file contains the following data:++| Name | Age | City | Department |+|---------|-----|---------------|--------------|+| Alice | 25 | New York | Engineering |+| Bob | 30 | San Francisco | Marketing |+| Charlie | 35 | Seattle | Finance |++### Summary:+- **Total Records**: 3+- **Columns**:+ - **Name**: Names of individuals+ - **Age**: Ages of individuals+ - **City**: Cities where individuals reside+ - **Department**: Departments where individuals work+Removed temporary file: /var/folders/93/f_71_t957cq9cmq2gsybs4_40000gn/T/+tmpqweue66k.csv+===============================================================================+'''diff --git a/examples/toolkits/video_analysis_toolkit.py b/examples/toolkits/video_analysis_toolkit.pynew file mode 100644index 000000000..b441618d8--- /dev/null+++ b/examples/toolkits/video_analysis_toolkit.py@@ -0,0 +1,152 @@+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+++from camel.agents import ChatAgent+from camel.configs import ChatGPTConfig+from camel.models import ModelFactory+from camel.toolkits import VideoAnalysisToolkit+from camel.types import ModelPlatformType, ModelType++model = ModelFactory.create(+ model_platform=ModelPlatformType.OPENAI,+ model_type=ModelType.GPT_4O_MINI,+ model_config_dict=ChatGPTConfig(+ temperature=0.0,+ ).as_dict(),+)++video_model = ModelFactory.create(+ model_platform=ModelPlatformType.OPENAI,+ model_type=ModelType.GPT_4O_MINI,+ model_config_dict=ChatGPTConfig(+ temperature=0.0,+ ).as_dict(),+)++# Initialize the VideoAnalysisToolkit with the model+# Note: Audio transcription is disabled for faster processing+video_toolkit = VideoAnalysisToolkit(+ model=video_model,+ use_audio_transcription=False,+)++# Create an agent with the video toolkit's tools+agent = ChatAgent(+ system_message="You are a helpful assistant that can analyze videos.",+ model=model,+ tools=[*video_toolkit.get_tools()],+)++# Example video URL (Very short sample video)+video_url = "https://www.youtube.com/watch?v=kQ_7GtE529M"+question = "What is shown in the first few seconds of this video?"++# Use the toolkit directly for faster processing with fewer frames+print("Analyzing video...")+result = video_toolkit.ask_question_about_video(+ video_path=video_url,+ question=question,+ num_frames=5, # Extract only 5 frames for faster processing+)++print("Video Analysis Result:")+print("-" * 50)+print(result)+print("-" * 50)+"""+==========================================================================+Analyzing video...+[youtube] Extracting URL: https://www.youtube.com/watch?v=kQ_7GtE529M+[youtube] kQ_7GtE529M: Downloading webpage+[youtube] kQ_7GtE529M: Downloading ios player API JSON+[youtube] kQ_7GtE529M: Downloading mweb player API JSON+[youtube] kQ_7GtE529M: Downloading m3u8 information+[info] kQ_7GtE529M: Downloading 1 format(s): 247+251+[download] Destination: /private/var/folders/93/f_71_t957cq9cmq2gsybs4_40000gn/+T/tmp4plhd3s3/Douchebag Bison.f247.webm+[download] 100% of 1.95MiB in 00:00:01 at 1.18MiB/s+[download] Destination: /private/var/folders/93/f_71_t957cq9cmq2gsybs4_40000gn/+T/tmp4plhd3s3/Douchebag Bison.f251.webm+[download] 100% of 303.08KiB in 00:00:00 at 490.62KiB/s+[Merger] Merging formats into "/private/var/folders/93/+f_71_t957cq9cmq2gsybs4_40000gn/T/tmp4plhd3s3/Douchebag Bison.webm"+Deleting original file /private/var/folders/93/f_71_t957cq9cmq2gsybs4_40000gn/+T/tmp4plhd3s3/Douchebag Bison.f251.webm (pass -k to keep)+Deleting original file /private/var/folders/93/f_71_t957cq9cmq2gsybs4_40000gn/+T/tmp4plhd3s3/Douchebag Bison.f247.webm (pass -k to keep)+2025-03-09 21:17:08,036 - pyscenedetect - ERROR - VideoManager is deprecated+and will be removed.+2025-03-09 21:17:08,060 - pyscenedetect - INFO - Loaded 1 video, framerate: 30.+000 FPS, resolution: 1280 x 720+2025-03-09 21:17:08,061 - pyscenedetect - INFO - Duration set, start: None,+duration: None, end: None.+2025-03-09 21:17:08,061 - pyscenedetect - INFO - Detecting scenes...+2025-03-09 21:17:09,065 - camel.camel.toolkits.video_analysis_toolkit -+WARNING - No scenes detected in video, capturing frames at regular intervals+Video Analysis Result:+--------------------------------------------------+### Visual Analysis++1. **Identified Entities**:+ - **Wolves**: Multiple wolves are visible in the frames, characterized by+ their grayish fur, slender bodies, and bushy tails. They appear to be in a+ pack, indicating social behavior.+ - **Bison**: A bison is present, identifiable by its large size, shaggy+ brown fur, and distinctive hump on its back. The bison is significantly+ larger than the wolves.++2. **Key Attributes**:+ - **Wolves**:+ - Size: Smaller than the bison, typically around 26-32 inches tall at the+ shoulder.+ - Color: Predominantly gray with some variations in fur color.+ - Behavior: The wolves are shown moving in a coordinated manner,+ suggesting they are hunting or scavenging.+ - **Bison**:+ - Size: Much larger, can weigh up to 2,000 pounds.+ - Color: Dark brown, with a thick coat.+ - Behavior: The bison appears to be stationary or moving slowly, possibly+ in a defensive posture.++3. **Groupings and Interactions**:+ - The wolves are seen surrounding the bison, indicating a predatory+ behavior. The interaction suggests a hunting scenario, where the wolves are+ attempting to take down or scavenge from the bison.++### Audio Integration+- **No audio transcription available**: Therefore, the analysis relies solely+on visual observations.++### Detailed Reasoning and Justification+- **Identification of Species**:+ - The wolves are identified by their physical characteristics and social+ behavior, which is typical of pack animals. Their movement patterns and+ proximity to the bison indicate a hunting strategy.+ - The bison is easily distinguishable due to its size and unique physical+ features, such as the hump and thick fur.++### Comprehensive Answer+- **Total Number of Distinct Species**: 2 (Wolves and Bison)+- **Defining Characteristics**:+ - **Wolves**: Gray fur, slender build, social behavior in a pack.+ - **Bison**: Large size, shaggy brown fur, distinctive hump.++### Important Considerations+- The wolves exhibit coordinated movement, which is crucial for hunting, while+the bison's size and defensive posture highlight its role as prey in this+scenario. The visual cues of size, color, and behavior effectively distinguish+these two species in the context of a predatory interaction.+==========================================================================+"""diff --git a/pyproject.toml b/pyproject.tomlindex d3e839aac..312c163a4 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -42,6 +42,31 @@ test = ["mock>=5,<6","pytest-asyncio>=0.23.0,<0.24",]+dev = [+ "ruff>=0.7,<0.8",+ "mypy>=1.5.1,<2",+ "toml>=0.10.2",+ "pre-commit>=3,<4",+ "pytest>=7,<8",+ "pytest-cov>=4,<5",+ "pytest-asyncio>=0.23.0,<0.24",+ "gradio>=3,<4",+ "mock>=5,<6",+ "types-colorama>=0.4.15,<0.5",+ "types-PyYAML>=6.0.12,<7",+ "types-mock>=5.1.0,<6",+ "types-tqdm>=4.66.0,<5",+ "types-requests>=2.31.0,<3",+ "types-setuptools>=69.2.0,<70",+]+docs = [+ "sphinx>=7,<8",+ "sphinx_book_theme",+ "docutils<0.20.0",+ "myst-parser",+ "nbsphinx",+ "sphinxext-rediraffe>=0.2.7,<0.3",+]rag = ["sentence-transformers>=3.0.1,<4","qdrant-client>=1.9.0,<2",@@ -77,6 +102,9 @@ document_tools = ["pandasai>=2.3.0,<3","prance>=23.6.21.0,<24","openapi-spec-validator>=0.7.1,<0.8",+ "xls2xlsx>=0.2.0",+ "tabulate>=0.9.0",+ "openpyxl>=3.1.5",]media_tools = ["imageio[pyav]>=2.34.2,<3",@@ -84,6 +112,7 @@ media_tools = ["pydub>=0.25.1,<0.26","yt-dlp>=2024.11.4,<2025","ffmpeg-python>=0.2.0,<0.3",+ "scenedetect>=0.6.5.2",]communication_tools = ["slack-sdk>=3.27.2,<4",@@ -236,6 +265,10 @@ all = ["pytest-asyncio>=0.23.0,<0.24","gradio>=3,<4","mock>=5,<6",+ "xls2xlsx>=0.2.0",+ "tabulate>=0.9.0",+ "openpyxl>=3.1.5",+ "scenedetect>=0.6.5.2",][project.urls]@@ -243,33 +276,6 @@ Homepage = "https://www.camel-ai.org/"Repository = "https://github.com/camel-ai/camel"Documentation = "https://docs.camel-ai.org"-[dependency-groups]-dev = [- "ruff>=0.7,<0.8",- "mypy>=1.5.1,<2",- "toml>=0.10.2",- "pre-commit>=3,<4",- "pytest>=7,<8",- "pytest-cov>=4,<5",- "pytest-asyncio>=0.23.0,<0.24",- "gradio>=3,<4",- "mock>=5,<6",- "types-colorama>=0.4.15,<0.5",- "types-PyYAML>=6.0.12,<7",- "types-mock>=5.1.0,<6",- "types-tqdm>=4.66.0,<5",- "types-requests>=2.31.0,<3",- "types-setuptools>=69.2.0,<70",-]-docs = [- "sphinx>=7,<8",- "sphinx_book_theme",- "docutils<0.20.0",- "myst-parser",- "nbsphinx",- "sphinxext-rediraffe>=0.2.7,<0.3",-]-[tool.uv]default-groups = ["dev",@@ -364,6 +370,9 @@ module = ["requests_oauthlib","fastapi","prance",+ "xls2xlsx",+ "tabulate",+ "openpyxl","openapi-spec-validator","jsonschema.*","bs4.*",@@ -425,5 +434,9 @@ module = ["yaml","mock","uvicorn",+ "xls2xlsx",+ "tabulate",+ "openpyxl",+ "scenedetect",]ignore_missing_imports = truediff --git a/test/toolkits/test_excel_toolkit.py b/test/toolkits/test_excel_toolkit.pynew file mode 100644index 000000000..03a1988a7--- /dev/null+++ b/test/toolkits/test_excel_toolkit.py@@ -0,0 +1,189 @@+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========++import os+import tempfile+from unittest.mock import MagicMock, patch++import pandas as pd+import pytest++from camel.toolkits import ExcelToolkit+++def excel_toolkit():+ return ExcelToolkit()+++def sample_csv_file():+ r"""Create a temporary CSV file for testing."""+ with tempfile.NamedTemporaryFile(suffix=".csv", delete=False) as temp_file:+ df = pd.DataFrame(+ {+ 'Name': ['Alice', 'Bob', 'Charlie'],+ 'Age': [25, 30, 35],+ 'City': ['New York', 'San Francisco', 'Seattle'],+ }+ )+ df.to_csv(temp_file.name, index=False)+ temp_path = temp_file.name++ yield temp_path++ # Clean up the temporary file+ if os.path.exists(temp_path):+ os.remove(temp_path)+++def test_extract_excel_content_csv(excel_toolkit, sample_csv_file):+ r"""Test extracting content from a CSV file."""+ result = excel_toolkit.extract_excel_content(sample_csv_file)++ # Check that the result contains expected content+ assert "CSV File Processed" in result+ assert "Name" in result+ assert "Age" in result+ assert "City" in result+ assert "Alice" in result+ assert "Bob" in result+ assert "Charlie" in result+++def test_extract_excel_content_unsupported_format(excel_toolkit):+ r"""Test handling of unsupported file formats."""+ with tempfile.NamedTemporaryFile(suffix=".txt", delete=False) as temp_file:+ temp_file.write(b"This is a text file, not an Excel file.")+ temp_path = temp_file.name++ try:+ result = excel_toolkit.extract_excel_content(temp_path)+ assert "Failed to process file" in result+ assert "It is not excel format" in result+ finally:+ if os.path.exists(temp_path):+ os.remove(temp_path)+++def test_extract_excel_content_xlsx(excel_toolkit):+ r"""Test extracting content from an XLSX file using mocks."""+ with (+ patch('openpyxl.load_workbook') as mock_load_workbook,+ patch('pandas.read_excel') as mock_read_excel,+ ):+ # Mock the workbook and sheet+ mock_workbook = MagicMock()+ mock_sheet = MagicMock()+ mock_cell = MagicMock()++ # Configure the mocks+ mock_load_workbook.return_value = mock_workbook+ mock_workbook.sheetnames = ['Sheet1']+ mock_workbook.__getitem__.return_value = mock_sheet++ # Mock cell properties+ mock_cell.row = 1+ mock_cell.column_letter = 'A'+ mock_cell.value = 'Test Value'+ mock_cell.font.color = None+ mock_cell.fill.fgColor = None++ # Set up the sheet to return our mock cell+ mock_sheet.iter_rows.return_value = [[mock_cell]]++ # Mock pandas read_excel to return a sample DataFrame+ df = pd.DataFrame({'Column1': ['Test Value'], 'Column2': [42]})+ mock_read_excel.return_value = df++ # Call the function with a fake xlsx path+ result = excel_toolkit.extract_excel_content("test.xlsx")++ # Verify the function was called correctly+ mock_load_workbook.assert_called_once_with("test.xlsx", data_only=True)+ mock_read_excel.assert_called_once()++ # Check the result contains expected content+ assert "Sheet Name: Sheet1" in result+ assert "Cell information list" in result+ assert "Markdown View of the content" in result+++def test_extract_excel_content_xls(excel_toolkit):+ r"""Test extracting content from an XLS file using mocks."""+ with (+ patch('xls2xlsx.XLS2XLSX') as mock_xls2xlsx,+ patch('openpyxl.load_workbook') as mock_load_workbook,+ patch('pandas.read_excel') as mock_read_excel,+ ):+ # Mock the XLS2XLSX conversion+ mock_xls_converter = MagicMock()+ mock_xls2xlsx.return_value = mock_xls_converter++ # Mock the workbook and sheet+ mock_workbook = MagicMock()+ mock_sheet = MagicMock()++ # Configure the mocks+ mock_load_workbook.return_value = mock_workbook+ mock_workbook.sheetnames = ['Sheet1']+ mock_workbook.__getitem__.return_value = mock_sheet++ # Set up the sheet to return an empty list of cells+ mock_sheet.iter_rows.return_value = []++ # Mock pandas read_excel to return a sample DataFrame+ df = pd.DataFrame({'Column1': ['XLS Value'], 'Column2': [100]})+ mock_read_excel.return_value = df++ # Call the function with a fake xls path+ result = excel_toolkit.extract_excel_content("test.xls")++ # Verify the XLS conversion was called+ mock_xls2xlsx.assert_called_once_with("test.xls")+ mock_xls_converter.to_xlsx.assert_called_once()++ # Verify the workbook was loaded+ mock_load_workbook.assert_called_once()++ # Check the result contains expected content+ assert "Sheet Name: Sheet1" in result+ assert "Markdown View of the content" in result+++def test_convert_to_markdown(excel_toolkit):+ r"""Test the _convert_to_markdown method."""+ df = pd.DataFrame({'Name': ['Alice', 'Bob'], 'Age': [25, 30]})++ result = excel_toolkit._convert_to_markdown(df)++ # Check that the result contains expected markdown table format+ assert "|" in result # Table separator+ assert "Name" in result+ assert "Age" in result+ assert "Alice" in result+ assert "Bob" in result+ assert "25" in result+ assert "30" in result+++def test_get_tools(excel_toolkit):+ r"""Test the get_tools method returns the correct tools."""+ tools = excel_toolkit.get_tools()++ # Check that we have the expected number of tools+ assert len(tools) == 1++ # Check that the tool has the correct function name+ assert tools[0].get_function_name() == "extract_excel_content"diff --git a/test/toolkits/test_video_analysis_toolkit.py b/test/toolkits/test_video_analysis_toolkit.pynew file mode 100644index 000000000..6cb55cc89--- /dev/null+++ b/test/toolkits/test_video_analysis_toolkit.py@@ -0,0 +1,487 @@+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+from unittest.mock import MagicMock, patch++import pytest++from camel.messages import BaseMessage+from camel.models import BaseModelBackend, OpenAIAudioModels+from camel.toolkits.video_analysis_toolkit import VideoAnalysisToolkit+++# Mock ffmpeg.Error for testing+class MockFFmpegError(Exception):+ def __init__(self, msg="FFmpeg error"):+ self.stderr = msg.encode() if isinstance(msg, str) else msg+ super().__init__(msg)+++# Fixtures+def mock_model():+ return MagicMock(spec=BaseModelBackend)+++def mock_audio_models():+ mock_audio = MagicMock(spec=OpenAIAudioModels)+ mock_audio.speech_to_text.return_value = "This is a test transcription"+ return mock_audio+++def mock_video_toolkit(mock_model, mock_audio_models):+ r"""Create a VideoAnalysisToolkit with mocked dependencies"""+ with (+ patch("tempfile.mkdtemp", return_value="/tmp/mock_dir"),+ patch("pathlib.Path.mkdir"),+ patch("camel.agents.ChatAgent"),+ patch("camel.toolkits.video_analysis_toolkit.VideoDownloaderToolkit"),+ patch(+ "camel.models.OpenAIAudioModels", return_value=mock_audio_models+ ),+ patch("os.path.exists", return_value=True),+ patch("shutil.rmtree"),+ patch("ffmpeg.input"),+ patch("ffmpeg.probe"),+ ):+ # Mock the chat agent+ mock_agent = MagicMock()+ mock_agent.step.return_value.msgs = [+ MagicMock(content="Test response")+ ]++ # Patch the ChatAgent import+ with patch("camel.agents.ChatAgent", return_value=mock_agent):+ toolkit = VideoAnalysisToolkit(+ model=mock_model, use_audio_transcription=True+ )+ # Manually set audio models to ensure it's available+ toolkit.audio_models = mock_audio_models+ toolkit._use_audio_transcription = True+ toolkit.vl_agent = mock_agent+ yield toolkit+++def test_init_default():+ r"""Test initialization with default parameters"""+ with (+ patch("tempfile.mkdtemp", return_value="/tmp/mock_dir"),+ patch("pathlib.Path.mkdir"),+ patch("camel.agents.ChatAgent"),+ patch("camel.toolkits.video_analysis_toolkit.VideoDownloaderToolkit"),+ ):+ toolkit = VideoAnalysisToolkit()+ assert toolkit._cleanup is True+ assert toolkit._use_audio_transcription is False+ # Use startswith instead of exact match to handle /private/tmp on macOS+ assert toolkit._download_directory.as_posix().endswith("/mock_dir")+++def test_init_with_download_directory():+ r"""Test initialization with custom download directory"""+ with (+ patch("pathlib.Path.mkdir"),+ patch("camel.agents.ChatAgent"),+ patch("camel.toolkits.video_analysis_toolkit.VideoDownloaderToolkit"),+ patch("os.path.exists", return_value=True),+ ):+ toolkit = VideoAnalysisToolkit(download_directory="/custom/dir")+ assert toolkit._cleanup is False+ assert toolkit._download_directory.as_posix() == "/custom/dir"+++def test_init_with_audio_transcription():+ r"""Test initialization with audio transcription enabled"""+ mock_audio = MagicMock()+ with (+ patch("tempfile.mkdtemp", return_value="/tmp/mock_dir"),+ patch("pathlib.Path.mkdir"),+ patch("camel.agents.ChatAgent"),+ patch("camel.toolkits.video_analysis_toolkit.VideoDownloaderToolkit"),+ # Mock OpenAIAudioModels and prevent the exception+ patch("camel.models.OpenAIAudioModels", return_value=mock_audio),+ # Prevent the exception from being raised during initialization+ patch(+ "camel.toolkits.video_analysis_toolkit.OpenAIAudioModels.__init__",+ return_value=None,+ ),+ ):+ toolkit = VideoAnalysisToolkit(use_audio_transcription=True)+ # Manually set the audio models and use_audio_transcription flag+ toolkit.audio_models = mock_audio+ toolkit._use_audio_transcription = True+ assert toolkit._use_audio_transcription is True+ assert toolkit.audio_models is mock_audio+++def test_init_with_invalid_directory():+ r"""Test initialization with invalid directory"""+ with (+ patch(+ "pathlib.Path.mkdir", side_effect=ValueError("Invalid directory")+ ),+ patch("camel.agents.ChatAgent"),+ ):+ with pytest.raises(ValueError):+ VideoAnalysisToolkit(download_directory="invalid_dir")+++# Test cleanup+def test_cleanup():+ r"""Test cleanup on object destruction"""+ with (+ patch("tempfile.mkdtemp", return_value="/tmp/mock_dir"),+ patch("pathlib.Path.mkdir"),+ patch("camel.agents.ChatAgent"),+ patch("camel.toolkits.video_analysis_toolkit.VideoDownloaderToolkit"),+ patch("os.path.exists", return_value=True),+ patch("os.remove") as mock_remove,+ patch("shutil.rmtree") as mock_rmtree,+ ):+ toolkit = VideoAnalysisToolkit()+ # Add a temp file to clean up+ toolkit._temp_files.append("/tmp/test.mp3")+ # Trigger __del__+ toolkit.__del__()++ mock_remove.assert_called_once_with("/tmp/test.mp3")+ # Use any_call instead of assert_called_once_with to handle PosixPath+ assert any(+ call.args[0].as_posix().endswith("/mock_dir")+ for call in mock_rmtree.mock_calls+ )+++# Test audio extraction+def test_extract_audio_from_video(mock_video_toolkit):+ r"""Test extracting audio from video"""+ mock_ffmpeg = MagicMock()+ with patch("ffmpeg.input", return_value=mock_ffmpeg) as mock_input:+ mock_ffmpeg.output.return_value = mock_ffmpeg++ result = mock_video_toolkit._extract_audio_from_video(+ "/path/to/video.mp4"+ )++ assert result == "/path/to/video.mp3"+ assert "/path/to/video.mp3" in mock_video_toolkit._temp_files+ mock_input.assert_called_once_with("/path/to/video.mp4")+ mock_ffmpeg.output.assert_called_once()+ mock_ffmpeg.run.assert_called_once_with(quiet=True)+++def test_extract_audio_error(mock_video_toolkit):+ r"""Test handling errors in audio extraction"""+ mock_ffmpeg = MagicMock()+ with patch("ffmpeg.input", return_value=mock_ffmpeg):+ mock_ffmpeg.output.return_value = mock_ffmpeg++ # Create a patch for ffmpeg.Error at the import level+ with patch("ffmpeg.Error", MockFFmpegError):+ # Set up the side effect after patching ffmpeg.Error+ mock_ffmpeg.run.side_effect = MockFFmpegError("FFmpeg failed")++ with pytest.raises(RuntimeError):+ mock_video_toolkit._extract_audio_from_video(+ "/path/to/video.mp4"+ )+++# Test audio transcription+def test_transcribe_audio(mock_video_toolkit, mock_audio_models):+ r"""Test audio transcription"""+ result = mock_video_toolkit._transcribe_audio("/path/to/audio.mp3")++ assert result == "This is a test transcription"+ mock_audio_models.speech_to_text.assert_called_once_with(+ "/path/to/audio.mp3"+ )+++def test_transcribe_audio_disabled(mock_video_toolkit):+ r"""Test when audio transcription is disabled"""+ mock_video_toolkit._use_audio_transcription = False++ result = mock_video_toolkit._transcribe_audio("/path/to/audio.mp3")++ assert result == "No audio transcription available."+++def test_transcribe_audio_error(mock_video_toolkit, mock_audio_models):+ r"""Test handling errors in audio transcription"""+ mock_audio_models.speech_to_text.side_effect = Exception(+ "Transcription error"+ )++ result = mock_video_toolkit._transcribe_audio("/path/to/audio.mp3")++ assert result == "Audio transcription failed."+++# Test keyframe extraction+def test_extract_keyframes_with_scenes(mock_video_toolkit):+ r"""Test extracting keyframes with scene detection"""+ mock_scene_manager = MagicMock()+ mock_video_manager = MagicMock()+ mock_scene = MagicMock()+ mock_scene_list = [(10.0, 20.0), (30.0, 40.0)]+ mock_frame = MagicMock()++ with (+ patch("scenedetect.SceneManager", return_value=mock_scene_manager),+ patch("scenedetect.VideoManager", return_value=mock_video_manager),+ patch(+ "scenedetect.detectors.ContentDetector", return_value=mock_scene+ ),+ # Directly patch the function in the module where it's being called+ # from+ patch(+ "camel.toolkits.video_analysis_toolkit._capture_screenshot",+ return_value=mock_frame,+ ),+ ):+ mock_scene_manager.get_scene_list.return_value = mock_scene_list++ result = mock_video_toolkit._extract_keyframes("/path/to/video.mp4", 2)++ assert len(result) == 2+ assert result[0] == mock_frame+ assert result[1] == mock_frame+++def test_extract_keyframes_no_scenes(mock_video_toolkit):+ r"""Test extracting keyframes when no scenes are detected"""+ mock_scene_manager = MagicMock()+ mock_video_manager = MagicMock()+ mock_scene = MagicMock()+ mock_cap = MagicMock()+ mock_frame = MagicMock()++ with (+ patch("scenedetect.SceneManager", return_value=mock_scene_manager),+ patch("scenedetect.VideoManager", return_value=mock_video_manager),+ patch(+ "scenedetect.detectors.ContentDetector", return_value=mock_scene+ ),+ patch("cv2.VideoCapture", return_value=mock_cap),+ # Directly patch the function in the module where it's being called+ # from+ patch(+ "camel.toolkits.video_analysis_toolkit._capture_screenshot",+ return_value=mock_frame,+ ),+ ):+ mock_scene_manager.get_scene_list.return_value = []+ mock_cap.get.side_effect = [100, 25] # total_frames, fps++ result = mock_video_toolkit._extract_keyframes("/path/to/video.mp4", 2)++ assert len(result) == 2+ assert result[0] == mock_frame+ assert result[1] == mock_frame+++def test_extract_keyframes_invalid_num_frames(mock_video_toolkit):+ r"""Test extracting keyframes with invalid number of frames"""+ mock_scene_manager = MagicMock()+ mock_video_manager = MagicMock()+ mock_scene = MagicMock()+ mock_scene_list = [(10.0, 20.0)]+ mock_frame = MagicMock()++ with (+ patch("scenedetect.SceneManager", return_value=mock_scene_manager),+ patch("scenedetect.VideoManager", return_value=mock_video_manager),+ patch(+ "scenedetect.detectors.ContentDetector", return_value=mock_scene+ ),+ # Directly patch the function in the module where it's being called+ # from+ patch(+ "camel.toolkits.video_analysis_toolkit._capture_screenshot",+ return_value=mock_frame,+ ),+ ):+ mock_scene_manager.get_scene_list.return_value = mock_scene_list++ result = mock_video_toolkit._extract_keyframes(+ "/path/to/video.mp4", -1+ )++ assert len(result) == 1+ assert result[0] == mock_frame+++# Test ask_question_about_video+def test_ask_question_about_video_local_file(mock_video_toolkit):+ r"""Test asking a question about a local video file"""+ mock_frames = [MagicMock(), MagicMock()]++ with (+ patch.object(+ mock_video_toolkit, "_extract_keyframes", return_value=mock_frames+ ),+ patch("os.path.exists", return_value=True),+ ):+ # Directly patch the _transcribe_audio method+ mock_video_toolkit._transcribe_audio = MagicMock(+ return_value="Test transcription"+ )++ result = mock_video_toolkit.ask_question_about_video(+ "/path/to/video.mp4", "What is happening in this video?"+ )++ assert result == "Test response"+ mock_video_toolkit.vl_agent.step.assert_called_once()++ # Check that the message was created with the right content+ call_args = mock_video_toolkit.vl_agent.step.call_args[0][0]+ assert isinstance(call_args, BaseMessage)+ assert "Test transcription" in call_args.content+ assert "What is happening in this video?" in call_args.content+ assert call_args.image_list == mock_frames+++def test_ask_question_about_video_url(mock_video_toolkit):+ r"""Test asking a question about a video URL"""+ mock_frames = [MagicMock(), MagicMock()]+ mock_video_toolkit.video_downloader_toolkit.download_video.return_value = (+ "/path/to/downloaded.mp4"+ )++ with (+ patch.object(+ mock_video_toolkit, "_extract_keyframes", return_value=mock_frames+ ),+ patch("os.path.exists", return_value=True),+ ):+ # Directly patch the _transcribe_audio method+ mock_video_toolkit._transcribe_audio = MagicMock(+ return_value="Test transcription"+ )++ result = mock_video_toolkit.ask_question_about_video(+ "https://example.com/video.mp4", "What is happening in this video?"+ )++ assert result == "Test response"+ mock_video_toolkit.video_downloader_toolkit.download_video.assert_called_once_with(+ "https://example.com/video.mp4"+ )+++def test_ask_question_about_video_no_audio(mock_video_toolkit):+ r"""Test asking a question about a video with audio transcription+ disabled.+ """+ mock_frames = [MagicMock(), MagicMock()]+ mock_video_toolkit._use_audio_transcription = False++ with (+ patch.object(+ mock_video_toolkit, "_extract_keyframes", return_value=mock_frames+ ),+ patch("os.path.exists", return_value=True),+ ):+ result = mock_video_toolkit.ask_question_about_video(+ "/path/to/video.mp4", "What is happening in this video?"+ )++ assert result == "Test response"+ # Check that the message was created with the right content+ call_args = mock_video_toolkit.vl_agent.step.call_args[0][0]+ assert "No audio transcription available" in call_args.content+++def test_ask_question_about_video_empty_question(mock_video_toolkit):+ r"""Test asking an empty question"""+ with pytest.raises(ValueError):+ mock_video_toolkit.ask_question_about_video("/path/to/video.mp4", "")+++def test_ask_question_about_video_file_not_found(mock_video_toolkit):+ r"""Test handling file not found error"""+ with patch("os.path.exists", return_value=False):+ result = mock_video_toolkit.ask_question_about_video(+ "/path/to/nonexistent.mp4", "What is happening in this video?"+ )++ assert "Error" in result+ assert "not found" in result+++def test_ask_question_about_video_download_error(mock_video_toolkit):+ r"""Test handling video download error"""+ mock_video_toolkit.video_downloader_toolkit.download_video.return_value = (+ None+ )++ result = mock_video_toolkit.ask_question_about_video(+ "https://example.com/video.mp4", "What is happening in this video?"+ )++ assert "Error" in result+ assert "Failed to download" in result+++def test_ask_question_about_video_keyframe_error(mock_video_toolkit):+ r"""Test handling keyframe extraction error"""+ with (+ patch.object(+ mock_video_toolkit,+ "_extract_keyframes",+ side_effect=ValueError("Keyframe error"),+ ),+ patch("os.path.exists", return_value=True),+ ):+ result = mock_video_toolkit.ask_question_about_video(+ "/path/to/video.mp4", "What is happening in this video?"+ )++ assert "Error" in result+ assert "Keyframe error" in result+++def test_ask_question_about_video_empty_response(mock_video_toolkit):+ r"""Test handling empty response from model"""+ mock_video_toolkit.vl_agent.step.return_value.msgs = []+ mock_frames = [MagicMock(), MagicMock()]++ with (+ patch.object(+ mock_video_toolkit, "_extract_keyframes", return_value=mock_frames+ ),+ patch("os.path.exists", return_value=True),+ ):+ # Directly patch the _transcribe_audio method+ mock_video_toolkit._transcribe_audio = MagicMock(+ return_value="Test transcription"+ )++ result = mock_video_toolkit.ask_question_about_video(+ "/path/to/video.mp4", "What is happening in this video?"+ )++ assert "Failed to generate an answer" in result+++# Test get_tools+def test_get_tools(mock_video_toolkit):+ r"""Test getting toolkit tools"""+ tools = mock_video_toolkit.get_tools()++ assert len(tools) == 1+ assert tools[0].func == mock_video_toolkit.ask_question_about_videodiff --git a/test/toolkits/test_video_function.py b/test/toolkits/test_video_download_function.pysimilarity index 94%rename from test/toolkits/test_video_function.pyrename to test/toolkits/test_video_download_function.pyindex 744316fff..0138213b6 100644--- a/test/toolkits/test_video_function.py+++ b/test/toolkits/test_video_download_function.py@@ -15,7 +15,7 @@ from unittest.mock import MagicMock, mock_open, patchimport pytest-from camel.toolkits.video_toolkit import VideoDownloaderToolkit+from camel.toolkits.video_download_toolkit import VideoDownloaderToolkit@pytest.fixture@@ -48,7 +48,7 @@ def mock_downloader():def test_video_bytes_download(mock_downloader):video_bytes = mock_downloader.get_video_bytes(- video_url="https://test_video.mp4",+ video_path="https://test_video.mp4",)assert len(video_bytes) > 0assert video_bytes == b"test"diff --git a/uv.lock b/uv.lockindex 755bb8897..87c575fd5 100644--- a/uv.lock+++ b/uv.lock@@ -573,6 +573,7 @@ all = [{ name = "notion-client" },{ name = "openapi-spec-validator" },{ name = "opencv-python" },+ { name = "openpyxl" },{ name = "outlines" },{ name = "pandas" },{ name = "pandasai" },@@ -595,6 +596,7 @@ all = [{ name = "reka-api" },{ name = "requests-oauthlib" },{ name = "rouge" },+ { name = "scenedetect" },{ name = "scholarly", extra = ["tor"] },{ name = "sentence-transformers" },{ name = "sentencepiece" },@@ -603,6 +605,7 @@ all = [{ name = "soundfile" },{ name = "stripe" },{ name = "sympy" },+ { name = "tabulate" },{ name = "tavily-python" },{ name = "textblob" },{ name = "torch" },@@ -618,6 +621,7 @@ all = [{ name = "unstructured" },{ name = "wikipedia" },{ name = "wolframalpha" },+ { name = "xls2xlsx" },{ name = "yt-dlp" },]communication-tools = [@@ -639,6 +643,23 @@ data-tools = [{ name = "stripe" },{ name = "textblob" },]+dev = [+ { name = "gradio" },+ { name = "mock" },+ { name = "mypy" },+ { name = "pre-commit" },+ { name = "pytest" },+ { name = "pytest-asyncio" },+ { name = "pytest-cov" },+ { name = "ruff" },+ { name = "toml" },+ { name = "types-colorama" },+ { name = "types-mock" },+ { name = "types-pyyaml" },+ { name = "types-requests" },+ { name = "types-setuptools" },+ { name = "types-tqdm" },+]dev-tools = [{ name = "agentops" },{ name = "docker" },@@ -648,14 +669,25 @@ dev-tools = [{ name = "tree-sitter" },{ name = "tree-sitter-python" },]+docs = [+ { name = "docutils" },+ { name = "myst-parser" },+ { name = "nbsphinx" },+ { name = "sphinx" },+ { name = "sphinx-book-theme" },+ { name = "sphinxext-rediraffe" },+]document-tools = [{ name = "beautifulsoup4" },{ name = "docx2txt" },{ name = "openapi-spec-validator" },+ { name = "openpyxl" },{ name = "pandasai" },{ name = "prance" },{ name = "pymupdf" },+ { name = "tabulate" },{ name = "unstructured" },+ { name = "xls2xlsx" },]huggingface = [{ name = "accelerate" },@@ -672,6 +704,7 @@ media-tools = [{ name = "imageio", extra = ["pyav"] },{ name = "pillow" },{ name = "pydub" },+ { name = "scenedetect" },{ name = "yt-dlp" },]model-platforms = [@@ -730,33 +763,6 @@ web-tools = [{ name = "wolframalpha" },]-[package.dev-dependencies]-dev = [- { name = "gradio" },- { name = "mock" },- { name = "mypy" },- { name = "pre-commit" },- { name = "pytest" },- { name = "pytest-asyncio" },- { name = "pytest-cov" },- { name = "ruff" },- { name = "toml" },- { name = "types-colorama" },- { name = "types-mock" },- { name = "types-pyyaml" },- { name = "types-requests" },- { name = "types-setuptools" },- { name = "types-tqdm" },-]-docs = [- { name = "docutils" },- { name = "myst-parser" },- { name = "nbsphinx" },- { name = "sphinx" },- { name = "sphinx-book-theme" },- { name = "sphinxext-rediraffe" },-]-[package.metadata]requires-dist = [{ name = "accelerate", marker = "extra == 'all'", specifier = ">=0.26.0,<0.27" },@@ -799,6 +805,7 @@ requires-dist = [{ name = "docker", marker = "extra == 'all'", specifier = ">=7.1.0,<8" },{ name = "docker", marker = "extra == 'dev-tools'", specifier = ">=7.1.0,<8" },{ name = "docstring-parser", specifier = ">=0.15,<0.16" },+ { name = "docutils", marker = "extra == 'docs'", specifier = "<0.20.0" },{ name = "docx2txt", marker = "extra == 'all'", specifier = ">=0.8,<0.9" },{ name = "docx2txt", marker = "extra == 'document-tools'", specifier = ">=0.8,<0.9" },{ name = "duckduckgo-search", marker = "extra == 'all'", specifier = ">=6.3.5,<7" },@@ -819,6 +826,7 @@ requires-dist = [{ name = "googlemaps", marker = "extra == 'all'", specifier = ">=4.10.0,<5" },{ name = "googlemaps", marker = "extra == 'web-tools'", specifier = ">=4.10.0,<5" },{ name = "gradio", marker = "extra == 'all'", specifier = ">=3,<4" },+ { name = "gradio", marker = "extra == 'dev'", specifier = ">=3,<4" },{ name = "httpx", specifier = ">=0.28.0,<1.0.0.dev0" },{ name = "imageio", extras = ["pyav"], marker = "extra == 'all'", specifier = ">=2.34.2,<3" },{ name = "imageio", extras = ["pyav"], marker = "extra == 'media-tools'", specifier = ">=2.34.2,<3" },@@ -834,8 +842,12 @@ requires-dist = [{ name = "mistralai", marker = "extra == 'all'", specifier = ">=1.1.0,<2" },{ name = "mistralai", marker = "extra == 'model-platforms'", specifier = ">=1.1.0,<2" },{ name = "mock", marker = "extra == 'all'", specifier = ">=5,<6" },+ { name = "mock", marker = "extra == 'dev'", specifier = ">=5,<6" },{ name = "mock", marker = "extra == 'test'", specifier = ">=5,<6" },{ name = "mypy", marker = "extra == 'all'", specifier = ">=1.5.1,<2" },+ { name = "mypy", marker = "extra == 'dev'", specifier = ">=1.5.1,<2" },+ { name = "myst-parser", marker = "extra == 'docs'" },+ { name = "nbsphinx", marker = "extra == 'docs'" },{ name = "nebula3-python", marker = "extra == 'all'", specifier = "==3.8.2" },{ name = "nebula3-python", marker = "extra == 'rag'", specifier = "==3.8.2" },{ name = "nebula3-python", marker = "extra == 'storage'", specifier = "==3.8.2" },@@ -854,6 +866,8 @@ requires-dist = [{ name = "openapi-spec-validator", marker = "extra == 'document-tools'", specifier = ">=0.7.1,<0.8" },{ name = "opencv-python", marker = "extra == 'all'", specifier = ">=4,<5" },{ name = "opencv-python", marker = "extra == 'huggingface'", specifier = ">=4,<5" },+ { name = "openpyxl", marker = "extra == 'all'", specifier = ">=3.1.5" },+ { name = "openpyxl", marker = "extra == 'document-tools'", specifier = ">=3.1.5" },{ name = "outlines", marker = "extra == 'all'", specifier = ">=0.1.7,<0.2" },{ name = "pandas", marker = "extra == 'all'", specifier = ">=1.5.3,<2" },{ name = "pandas", marker = "extra == 'data-tools'", specifier = ">=1.5.3,<2" },@@ -867,6 +881,7 @@ requires-dist = [{ name = "praw", marker = "extra == 'all'", specifier = ">=7.7.1,<8" },{ name = "praw", marker = "extra == 'communication-tools'", specifier = ">=7.7.1,<8" },{ name = "pre-commit", marker = "extra == 'all'", specifier = ">=3,<4" },+ { name = "pre-commit", marker = "extra == 'dev'", specifier = ">=3,<4" },{ name = "protobuf", specifier = ">=5,<6" },{ name = "psutil", specifier = ">=5.9.8,<6" },{ name = "pydantic", specifier = ">=1.9,<2.10" },@@ -884,10 +899,13 @@ requires-dist = [{ name = "pytelegrambotapi", marker = "extra == 'all'", specifier = ">=4.18.0,<5" },{ name = "pytelegrambotapi", marker = "extra == 'communication-tools'", specifier = ">=4.18.0,<5" },{ name = "pytest", marker = "extra == 'all'", specifier = ">=7,<8" },+ { name = "pytest", marker = "extra == 'dev'", specifier = ">=7,<8" },{ name = "pytest", marker = "extra == 'test'", specifier = ">=7,<8" },{ name = "pytest-asyncio", marker = "extra == 'all'", specifier = ">=0.23.0,<0.24" },+ { name = "pytest-asyncio", marker = "extra == 'dev'", specifier = ">=0.23.0,<0.24" },{ name = "pytest-asyncio", marker = "extra == 'test'", specifier = ">=0.23.0,<0.24" },{ name = "pytest-cov", marker = "extra == 'all'", specifier = ">=4,<5" },+ { name = "pytest-cov", marker = "extra == 'dev'", specifier = ">=4,<5" },{ name = "pyyaml", specifier = ">=6.0.2,<7" },{ name = "qdrant-client", marker = "extra == 'all'", specifier = ">=1.9.0,<2" },{ name = "qdrant-client", marker = "extra == 'rag'", specifier = ">=1.9.0,<2" },@@ -902,6 +920,9 @@ requires-dist = [{ name = "requests-oauthlib", marker = "extra == 'web-tools'", specifier = ">=1.3.1,<2" },{ name = "rouge", marker = "extra == 'all'", specifier = ">=1.0.1,<2" },{ name = "rouge", marker = "extra == 'data-tools'", specifier = ">=1.0.1,<2" },+ { name = "ruff", marker = "extra == 'dev'", specifier = ">=0.7,<0.8" },+ { name = "scenedetect", marker = "extra == 'all'", specifier = ">=0.6.5.2" },+ { name = "scenedetect", marker = "extra == 'media-tools'", specifier = ">=0.6.5.2" },{ name = "scholarly", extras = ["tor"], marker = "extra == 'all'", specifier = "==1.7.11" },{ name = "scholarly", extras = ["tor"], marker = "extra == 'research-tools'", specifier = "==1.7.11" },{ name = "sentence-transformers", marker = "extra == 'all'", specifier = ">=3.0.1,<4" },@@ -914,15 +935,21 @@ requires-dist = [{ name = "slack-sdk", marker = "extra == 'communication-tools'", specifier = ">=3.27.2,<4" },{ name = "soundfile", marker = "extra == 'all'", specifier = ">=0.13,<0.14" },{ name = "soundfile", marker = "extra == 'huggingface'", specifier = ">=0.13,<0.14" },+ { name = "sphinx", marker = "extra == 'docs'", specifier = ">=7,<8" },+ { name = "sphinx-book-theme", marker = "extra == 'docs'" },+ { name = "sphinxext-rediraffe", marker = "extra == 'docs'", specifier = ">=0.2.7,<0.3" },{ name = "stripe", marker = "extra == 'all'", specifier = ">=11.3.0,<12" },{ name = "stripe", marker = "extra == 'data-tools'", specifier = ">=11.3.0,<12" },{ name = "sympy", marker = "extra == 'all'", specifier = ">=1.13.3,<2" },{ name = "sympy", marker = "extra == 'web-tools'", specifier = ">=1.13.3,<2" },+ { name = "tabulate", marker = "extra == 'all'", specifier = ">=0.9.0" },+ { name = "tabulate", marker = "extra == 'document-tools'", specifier = ">=0.9.0" },{ name = "tavily-python", marker = "extra == 'all'", specifier = ">=0.5.0,<0.6" },{ name = "tavily-python", marker = "extra == 'web-tools'", specifier = ">=0.5.0,<0.6" },{ name = "textblob", marker = "extra == 'all'", specifier = ">=0.17.1,<0.18" },{ name = "textblob", marker = "extra == 'data-tools'", specifier = ">=0.17.1,<0.18" },{ name = "tiktoken", specifier = ">=0.7.0,<0.8" },+ { name = "toml", marker = "extra == 'dev'", specifier = ">=0.10.2" },{ name = "torch", marker = "extra == 'all'" },{ name = "torch", marker = "extra == 'huggingface'" },{ name = "transformers", marker = "extra == 'all'", specifier = ">=4,<5" },@@ -932,11 +959,17 @@ requires-dist = [{ name = "tree-sitter-python", marker = "extra == 'all'", specifier = ">=0.23.6,<0.24" },{ name = "tree-sitter-python", marker = "extra == 'dev-tools'", specifier = ">=0.23.6,<0.24" },{ name = "types-colorama", marker = "extra == 'all'", specifier = ">=0.4.15,<0.5" },+ { name = "types-colorama", marker = "extra == 'dev'", specifier = ">=0.4.15,<0.5" },{ name = "types-mock", marker = "extra == 'all'", specifier = ">=5.1.0,<6" },+ { name = "types-mock", marker = "extra == 'dev'", specifier = ">=5.1.0,<6" },{ name = "types-pyyaml", marker = "extra == 'all'", specifier = ">=6.0.12,<7" },+ { name = "types-pyyaml", marker = "extra == 'dev'", specifier = ">=6.0.12,<7" },{ name = "types-requests", marker = "extra == 'all'", specifier = ">=2.31.0,<3" },+ { name = "types-requests", marker = "extra == 'dev'", specifier = ">=2.31.0,<3" },{ name = "types-setuptools", marker = "extra == 'all'", specifier = ">=69.2.0,<70" },+ { name = "types-setuptools", marker = "extra == 'dev'", specifier = ">=69.2.0,<70" },{ name = "types-tqdm", marker = "extra == 'all'", specifier = ">=4.66.0,<5" },+ { name = "types-tqdm", marker = "extra == 'dev'", specifier = ">=4.66.0,<5" },{ name = "unstructured", marker = "extra == 'all'", specifier = "==0.16.20" },{ name = "unstructured", marker = "extra == 'document-tools'", specifier = "==0.16.20" },{ name = "unstructured", marker = "extra == 'rag'", specifier = "==0.16.20" },@@ -944,37 +977,12 @@ requires-dist = [{ name = "wikipedia", marker = "extra == 'web-tools'", specifier = ">=1,<2" },{ name = "wolframalpha", marker = "extra == 'all'", specifier = ">=5.0.0,<6" },{ name = "wolframalpha", marker = "extra == 'web-tools'", specifier = ">=5.0.0,<6" },+ { name = "xls2xlsx", marker = "extra == 'all'", specifier = ">=0.2.0" },+ { name = "xls2xlsx", marker = "extra == 'document-tools'", specifier = ">=0.2.0" },{ name = "yt-dlp", marker = "extra == 'all'", specifier = ">=2024.11.4,<2025" },{ name = "yt-dlp", marker = "extra == 'media-tools'", specifier = ">=2024.11.4,<2025" },]-provides-extras = ["test", "rag", "web-tools", "document-tools", "media-tools", "communication-tools", "data-tools", "research-tools", "dev-tools", "model-platforms", "huggingface", "storage", "all"]--[package.metadata.requires-dev]-dev = [- { name = "gradio", specifier = ">=3,<4" },- { name = "mock", specifier = ">=5,<6" },- { name = "mypy", specifier = ">=1.5.1,<2" },- { name = "pre-commit", specifier = ">=3,<4" },- { name = "pytest", specifier = ">=7,<8" },- { name = "pytest-asyncio", specifier = ">=0.23.0,<0.24" },- { name = "pytest-cov", specifier = ">=4,<5" },- { name = "ruff", specifier = ">=0.7,<0.8" },- { name = "toml", specifier = ">=0.10.2" },- { name = "types-colorama", specifier = ">=0.4.15,<0.5" },- { name = "types-mock", specifier = ">=5.1.0,<6" },- { name = "types-pyyaml", specifier = ">=6.0.12,<7" },- { name = "types-requests", specifier = ">=2.31.0,<3" },- { name = "types-setuptools", specifier = ">=69.2.0,<70" },- { name = "types-tqdm", specifier = ">=4.66.0,<5" },-]-docs = [- { name = "docutils", specifier = "<0.20.0" },- { name = "myst-parser" },- { name = "nbsphinx" },- { name = "sphinx", specifier = ">=7,<8" },- { name = "sphinx-book-theme" },- { name = "sphinxext-rediraffe", specifier = ">=0.2.7,<0.3" },-]+provides-extras = ["test", "dev", "docs", "rag", "web-tools", "document-tools", "media-tools", "communication-tools", "data-tools", "research-tools", "dev-tools", "model-platforms", "huggingface", "storage", "all"][[package]]name = "certifi"@@ -1302,6 +1310,18 @@ wheels = [{ url = "https://files.pythonhosted.org/packages/06/a9/2da08717a6862c48f1d61ef957a7bba171e7eefa6c0aa0ceb96a140c2a6b/cssselect-1.2.0-py2.py3-none-any.whl", hash = "sha256:da1885f0c10b60c03ed5eccbb6b68d6eff248d91976fcde348f395d54c9fd35e", size = 18687 },]+[[package]]+name = "cssutils"+version = "2.11.1"+source = { registry = "https://pypi.org/simple" }+dependencies = [+ { name = "more-itertools" },+]+sdist = { url = "https://files.pythonhosted.org/packages/33/9f/329d26121fe165be44b1dfff21aa0dc348f04633931f1d20ed6cf448a236/cssutils-2.11.1.tar.gz", hash = "sha256:0563a76513b6af6eebbe788c3bf3d01c920e46b3f90c8416738c5cfc773ff8e2", size = 711657 }+wheels = [+ { url = "https://files.pythonhosted.org/packages/a7/ec/bb273b7208c606890dc36540fe667d06ce840a6f62f9fae7e658fcdc90fb/cssutils-2.11.1-py3-none-any.whl", hash = "sha256:a67bfdfdff4f3867fab43698ec4897c1a828eca5973f4073321b3bccaf1199b1", size = 385747 },+]+[[package]]name = "curl-cffi"version = "0.6.2"@@ -1320,6 +1340,15 @@ wheels = [{ url = "https://files.pythonhosted.org/packages/e8/43/9cbd2dde60f7e9ef83748dc0c254d64073c1eafdccd8b1d37d399d457449/curl_cffi-0.6.2-cp38-abi3-win_amd64.whl", hash = "sha256:3791b7a9ae4cb1298165300f2dc2d60a86779f055570ae83163fc2d8a74bf714", size = 2312273 },]+[[package]]+name = "currency-symbols"+version = "2.0.3"+source = { registry = "https://pypi.org/simple" }+sdist = { url = "https://files.pythonhosted.org/packages/35/09/aaafc15ae4412897085addcd3445411d82a2dc069cc17e3c393295fe9aa2/currency-symbols-2.0.3.tar.gz", hash = "sha256:f6101415319e06674c63d05ed9988b131dd8004cc437e77f7e83e734e5d2eb2f", size = 3547 }+wheels = [+ { url = "https://files.pythonhosted.org/packages/20/42/70e58c51f5c519fcfe8a633702562a9dda4e54b7d5dcdbee511cd6250d57/currency_symbols-2.0.3-py3-none-any.whl", hash = "sha256:e71c82320f1b410ab15614f5df6ea3645b204752081689bae30b6331006357f0", size = 5030 },+]+[[package]]name = "cycler"version = "0.12.1"@@ -1648,6 +1677,15 @@ wheels = [{ url = "https://files.pythonhosted.org/packages/91/db/a0335710caaa6d0aebdaa65ad4df789c15d89b7babd9a30277838a7d9aac/emoji-2.14.1-py3-none-any.whl", hash = "sha256:35a8a486c1460addb1499e3bf7929d3889b2e2841a57401903699fef595e942b", size = 590617 },]+[[package]]+name = "et-xmlfile"+version = "2.0.0"+source = { registry = "https://pypi.org/simple" }+sdist = { url = "https://files.pythonhosted.org/packages/d3/38/af70d7ab1ae9d4da450eeec1fa3918940a5fafb9055e934af8d6eb0c2313/et_xmlfile-2.0.0.tar.gz", hash = "sha256:dab3f4764309081ce75662649be815c4c9081e88f0837825f90fd28317d4da54", size = 17234 }+wheels = [+ { url = "https://files.pythonhosted.org/packages/c1/8b/5fe2cc11fee489817272089c4203e679c63b570a5aaeb18d852ae3cbba6a/et_xmlfile-2.0.0-py3-none-any.whl", hash = "sha256:7a91720bc756843502c3b7504c77b8fe44217c85c537d85037f0f536151b2caa", size = 18059 },+]+[[package]]name = "eval-type-backport"version = "0.2.0"@@ -3733,6 +3771,18 @@ wheels = [{ url = "https://files.pythonhosted.org/packages/a4/7d/f1c30a92854540bf789e9cd5dde7ef49bbe63f855b85a2e6b3db8135c591/opencv_python-4.11.0.86-cp37-abi3-win_amd64.whl", hash = "sha256:085ad9b77c18853ea66283e98affefe2de8cc4c1f43eda4c100cf9b2721142ec", size = 39488044 },]+[[package]]+name = "openpyxl"+version = "3.1.5"+source = { registry = "https://pypi.org/simple" }+dependencies = [+ { name = "et-xmlfile" },+]+sdist = { url = "https://files.pythonhosted.org/packages/3d/f9/88d94a75de065ea32619465d2f77b29a0469500e99012523b91cc4141cd1/openpyxl-3.1.5.tar.gz", hash = "sha256:cf0e3cf56142039133628b5acffe8ef0c12bc902d2aadd3e0fe5878dc08d1050", size = 186464 }+wheels = [+ { url = "https://files.pythonhosted.org/packages/c0/da/977ded879c29cbd04de313843e76868e6e13408a94ed6b987245dc7c8506/openpyxl-3.1.5-py2.py3-none-any.whl", hash = "sha256:5282c12b107bffeef825f4617dc029afaf41d0ea60823bbb665ef3079dc79de2", size = 250910 },+]+[[package]]name = "opentelemetry-api"version = "1.30.0"@@ -5323,6 +5373,21 @@ wheels = [{ url = "https://files.pythonhosted.org/packages/69/e2/b011c38e5394c4c18fb5500778a55ec43ad6106126e74723ffaee246f56e/safetensors-0.5.3-cp38-abi3-win_amd64.whl", hash = "sha256:836cbbc320b47e80acd40e44c8682db0e8ad7123209f69b093def21ec7cafd11", size = 308878 },]+[[package]]+name = "scenedetect"+version = "0.6.5.2"+source = { registry = "https://pypi.org/simple" }+dependencies = [+ { name = "click" },+ { name = "numpy" },+ { name = "platformdirs" },+ { name = "tqdm" },+]+sdist = { url = "https://files.pythonhosted.org/packages/ef/4e/2f20c616b3dc8420dcc456fd1a0efee35e34f3e499843e22a2661e11f73d/scenedetect-0.6.5.2.tar.gz", hash = "sha256:cf1af517409ac7b98905d8962de4fbefad01684355d12b5ccb992cbc6c4f8a52", size = 150927 }+wheels = [+ { url = "https://files.pythonhosted.org/packages/4a/b5/2c95bb825cf453e1bdfc9acf0ae3c7f249f47290422cc592a170b6e16530/scenedetect-0.6.5.2-py3-none-any.whl", hash = "sha256:148d312d84b26f6e086e5cca278b68ec61985a0957bf165ca1a5c9c55f6f627e", size = 127315 },+]+[[package]]name = "scholarly"version = "1.7.11"@@ -5873,6 +5938,15 @@ wheels = [{ url = "https://files.pythonhosted.org/packages/99/ff/c87e0622b1dadea79d2fb0b25ade9ed98954c9033722eb707053d310d4f3/sympy-1.13.3-py3-none-any.whl", hash = "sha256:54612cf55a62755ee71824ce692986f23c88ffa77207b30c1368eda4a7060f73", size = 6189483 },]+[[package]]+name = "tabulate"+version = "0.9.0"+source = { registry = "https://pypi.org/simple" }+sdist = { url = "https://files.pythonhosted.org/packages/ec/fe/802052aecb21e3797b8f7902564ab6ea0d60ff8ca23952079064155d1ae1/tabulate-0.9.0.tar.gz", hash = "sha256:0095b12bf5966de529c0feb1fa08671671b3368eec77d7ef7ab114be2c068b3c", size = 81090 }+wheels = [+ { url = "https://files.pythonhosted.org/packages/40/44/4a5f08c96eb108af5cb50b41f76142f0afa346dfa99d5296fe7202a11854/tabulate-0.9.0-py3-none-any.whl", hash = "sha256:024ca478df22e9340661486f85298cff5f6dcdba14f3813e8830015b9ed1948f", size = 35252 },+]+[[package]]name = "tavily-python"version = "0.5.1"@@ -6489,6 +6563,15 @@ wheels = [{ url = "https://files.pythonhosted.org/packages/fd/84/fd2ba7aafacbad3c4201d395674fc6348826569da3c0937e75505ead3528/wcwidth-0.2.13-py2.py3-none-any.whl", hash = "sha256:3da69048e4540d84af32131829ff948f1e022c1c6bdb8d6102117aac784f6859", size = 34166 },]+[[package]]+name = "webcolors"+version = "24.11.1"+source = { registry = "https://pypi.org/simple" }+sdist = { url = "https://files.pythonhosted.org/packages/7b/29/061ec845fb58521848f3739e466efd8250b4b7b98c1b6c5bf4d40b419b7e/webcolors-24.11.1.tar.gz", hash = "sha256:ecb3d768f32202af770477b8b65f318fa4f566c22948673a977b00d589dd80f6", size = 45064 }+wheels = [+ { url = "https://files.pythonhosted.org/packages/60/e8/c0e05e4684d13459f93d312077a9a2efbe04d59c393bc2b8802248c908d4/webcolors-24.11.1-py3-none-any.whl", hash = "sha256:515291393b4cdf0eb19c155749a096f779f7d909f7cceea072791cb9095b92e9", size = 14934 },+]+[[package]]name = "webencodings"version = "0.5.1"@@ -6618,6 +6701,38 @@ wheels = [{ url = "https://files.pythonhosted.org/packages/78/58/e860788190eba3bcce367f74d29c4675466ce8dddfba85f7827588416f01/wsproto-1.2.0-py3-none-any.whl", hash = "sha256:b9acddd652b585d75b20477888c56642fdade28bdfd3579aa24a4d2c037dd736", size = 24226 },]+[[package]]+name = "xlrd"+version = "2.0.1"+source = { registry = "https://pypi.org/simple" }+sdist = { url = "https://files.pythonhosted.org/packages/a6/b3/19a2540d21dea5f908304375bd43f5ed7a4c28a370dc9122c565423e6b44/xlrd-2.0.1.tar.gz", hash = "sha256:f72f148f54442c6b056bf931dbc34f986fd0c3b0b6b5a58d013c9aef274d0c88", size = 100259 }+wheels = [+ { url = "https://files.pythonhosted.org/packages/a6/0c/c2a72d51fe56e08a08acc85d13013558a2d793028ae7385448a6ccdfae64/xlrd-2.0.1-py2.py3-none-any.whl", hash = "sha256:6a33ee89877bd9abc1158129f6e94be74e2679636b8a205b43b85206c3f0bbdd", size = 96531 },+]++[[package]]+name = "xls2xlsx"+version = "0.2.0"+source = { registry = "https://pypi.org/simple" }+dependencies = [+ { name = "beautifulsoup4" },+ { name = "chardet" },+ { name = "cssutils" },+ { name = "currency-symbols" },+ { name = "fonttools" },+ { name = "openpyxl" },+ { name = "pillow" },+ { name = "python-dateutil" },+ { name = "pyyaml" },+ { name = "requests" },+ { name = "webcolors" },+ { name = "xlrd" },+]+sdist = { url = "https://files.pythonhosted.org/packages/bb/f1/cd87cb50c5da52a32f3c8eb268f31f2e0594171a89de69b37a66dc5de0b8/xls2xlsx-0.2.0.tar.gz", hash = "sha256:98123cb8f43fdd68f4af8d61d7223100d6003daf9a592fa6c0746acbc7314c35", size = 1330340 }+wheels = [+ { url = "https://files.pythonhosted.org/packages/fc/be/8302d331252974200ff4adb392d1fc67e4ff161c85a3109b915f4cbaa1ca/xls2xlsx-0.2.0-py2.py3-none-any.whl", hash = "sha256:a6b9c6f887d2e366a54d26682d1ec399f5dbf408567d47768ef6178ef587af4e", size = 39191 },+]+[[package]]name = "xmltodict"version = "0.14.2"