mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-20 21:38:14 +00:00
Fix #2762: Make CSV knowledge sources detect and load file updates
Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
@@ -43,7 +43,15 @@ class BaseFileKnowledgeSource(BaseKnowledgeSource, ABC):
|
||||
"""Post-initialization method to load content."""
|
||||
self.safe_file_paths = self._process_file_paths()
|
||||
self.validate_content()
|
||||
self._record_file_mtimes()
|
||||
self.content = self.load_content()
|
||||
|
||||
def _record_file_mtimes(self):
|
||||
"""Record modification times of all files."""
|
||||
self._file_mtimes = {}
|
||||
for path in self.safe_file_paths:
|
||||
if path.exists() and path.is_file():
|
||||
self._file_mtimes[path] = path.stat().st_mtime
|
||||
|
||||
@abstractmethod
|
||||
def load_content(self) -> Dict[Path, str]:
|
||||
@@ -107,3 +115,14 @@ class BaseFileKnowledgeSource(BaseKnowledgeSource, ABC):
|
||||
)
|
||||
|
||||
return [self.convert_to_path(path) for path in path_list]
|
||||
|
||||
def files_have_changed(self) -> bool:
|
||||
"""Check if any of the files have been modified since they were last loaded."""
|
||||
for path in self.safe_file_paths:
|
||||
if not path.exists() or not path.is_file():
|
||||
continue
|
||||
current_mtime = path.stat().st_mtime
|
||||
if path not in self._file_mtimes or current_mtime > self._file_mtimes[path]:
|
||||
self._logger.log("info", f"File {path} has been modified. Reloading data.")
|
||||
return True
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user