From 76c640b985c68b3bdf0122bcaf3a8d4697531856 Mon Sep 17 00:00:00 2001 From: Lorenze Jay Date: Mon, 16 Dec 2024 19:41:10 -0800 Subject: [PATCH] use file_paths instead of file_path 2 --- .../source/base_file_knowledge_source.py | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/crewai/knowledge/source/base_file_knowledge_source.py b/src/crewai/knowledge/source/base_file_knowledge_source.py index 24dd4a3f2..f06e4bfd5 100644 --- a/src/crewai/knowledge/source/base_file_knowledge_source.py +++ b/src/crewai/knowledge/source/base_file_knowledge_source.py @@ -14,6 +14,10 @@ class BaseFileKnowledgeSource(BaseKnowledgeSource, ABC): """Base class for knowledge sources that load content from files.""" _logger: Logger = Logger(verbose=True) + file_path: Union[Path, List[Path], str, List[str]] = Field( + default=None, + description="[Deprecated] The path to the file. Use file_paths instead.", + ) file_paths: Union[Path, List[Path], str, List[str]] = Field( ..., description="The path to the file" ) @@ -59,13 +63,29 @@ class BaseFileKnowledgeSource(BaseKnowledgeSource, ABC): def _process_file_paths(self) -> List[Path]: """Convert file_path to a list of Path objects.""" - paths = ( - [self.file_paths] - if isinstance(self.file_paths, (str, Path)) - else self.file_paths - ) + + # Check if old file_path is being used + if hasattr(self, "file_path") and self.file_path is not None: + self._logger.log( + "warning", + "The 'file_path' attribute is deprecated and will be removed in a future version. Please use 'file_paths' instead.", + color="yellow", + ) + paths = ( + [self.file_path] + if isinstance(self.file_path, (str, Path)) + else self.file_path + ) + else: + paths = ( + [self.file_paths] + if isinstance(self.file_paths, (str, Path)) + else self.file_paths + ) if not isinstance(paths, list): - raise ValueError("file_path must be a Path, str, or a list of these types") + raise ValueError( + "file_path/file_paths must be a Path, str, or a list of these types" + ) return [self.convert_to_path(path) for path in paths]