The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
community: Implement lazy_load() for SlackDirectoryLoader (#18675)
Christophe Bornet302985fea15e
diff --git a/libs/community/langchain_community/document_loaders/slack_directory.py b/libs/community/langchain_community/document_loaders/slack_directory.pyindex 7c11535809..cbd0173ea4 100644--- a/libs/community/langchain_community/document_loaders/slack_directory.py+++ b/libs/community/langchain_community/document_loaders/slack_directory.py@@ -1,7 +1,7 @@import jsonimport zipfilefrom pathlib import Path-from typing import Dict, List, Optional+from typing import Dict, Iterator, List, Optionalfrom langchain_core.documents import Document@@ -35,9 +35,8 @@ class SlackDirectoryLoader(BaseLoader):except KeyError:return {}- def load(self) -> List[Document]:+ def lazy_load(self) -> Iterator[Document]:"""Load and return documents from the Slack directory dump."""- docs = []with zipfile.ZipFile(self.zip_path, "r") as zip_file:for channel_path in zip_file.namelist():channel_name = Path(channel_path).parent.name@@ -46,11 +45,7 @@ class SlackDirectoryLoader(BaseLoader):if channel_path.endswith(".json"):messages = self._read_json(zip_file, channel_path)for message in messages:- document = self._convert_message_to_document(- message, channel_name- )- docs.append(document)- return docs+ yield self._convert_message_to_document(message, channel_name)def _read_json(self, zip_file: zipfile.ZipFile, file_path: str) -> List[dict]:"""Read JSON data from a zip subfile."""