From 914067df37fc6b7f8f43efa4763b9d0a3c8c3419 Mon Sep 17 00:00:00 2001 From: Lorenze Jay Date: Tue, 19 Nov 2024 11:39:18 -0800 Subject: [PATCH] fixed text_file_knowledge --- .../knowledge/source/text_file_knowledge_source.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/crewai/knowledge/source/text_file_knowledge_source.py b/src/crewai/knowledge/source/text_file_knowledge_source.py index 3165493ad..640db4ef9 100644 --- a/src/crewai/knowledge/source/text_file_knowledge_source.py +++ b/src/crewai/knowledge/source/text_file_knowledge_source.py @@ -10,16 +10,21 @@ class TextFileKnowledgeSource(BaseFileKnowledgeSource): def load_content(self) -> Dict[Path, str]: """Load and preprocess text file content.""" super().load_content() - with self.file_path.open("r", encoding="utf-8") as f: - return f.read() # type: ignore + paths = [self.file_path] if isinstance(self.file_path, Path) else self.file_path + content = {} + for path in paths: + with path.open("r", encoding="utf-8") as f: + content[path] = f.read() # type: ignore + return content def add(self) -> None: """ Add text file content to the knowledge source, chunk it, compute embeddings, and save the embeddings. """ - new_chunks = self._chunk_text(self.content) - self.chunks.extend(new_chunks) + for _, text in self.content.items(): + new_chunks = self._chunk_text(text) + self.chunks.extend(new_chunks) self.save_documents(metadata=self.metadata) def _chunk_text(self, text: str) -> List[str]: