Skip to content

The agent engineering platform.

patch[Community] Optimize methods in several ChatLoaders (#24806)

ZhangShenaob38c83ff93b7
diff --git a/libs/community/langchain_community/chat_loaders/langsmith.py b/libs/community/langchain_community/chat_loaders/langsmith.py
index 7d099632c0..7f3ac6cdd7 100644
--- a/libs/community/langchain_community/chat_loaders/langsmith.py
+++ b/libs/community/langchain_community/chat_loaders/langsmith.py
@@ -38,7 +38,8 @@ class LangSmithRunChatLoader(BaseChatLoader):
self.runs = runs
self.client = client or Client()
- def _load_single_chat_session(self, llm_run: "Run") -> ChatSession:
+ @staticmethod
+ def _load_single_chat_session(llm_run: "Run") -> ChatSession:
"""
Convert an individual LangSmith LLM run to a ChatSession.
diff --git a/libs/community/langchain_community/chat_loaders/slack.py b/libs/community/langchain_community/chat_loaders/slack.py
index fcce989aa9..4a11e14445 100644
--- a/libs/community/langchain_community/chat_loaders/slack.py
+++ b/libs/community/langchain_community/chat_loaders/slack.py
@@ -28,7 +28,8 @@ class SlackChatLoader(BaseChatLoader):
if not self.zip_path.exists():
raise FileNotFoundError(f"File {self.zip_path} not found")
- def _load_single_chat_session(self, messages: List[Dict]) -> ChatSession:
+ @staticmethod
+ def _load_single_chat_session(messages: List[Dict]) -> ChatSession:
results: List[Union[AIMessage, HumanMessage]] = []
previous_sender = None
for message in messages:
@@ -63,7 +64,8 @@ class SlackChatLoader(BaseChatLoader):
previous_sender = sender
return ChatSession(messages=results)
- def _read_json(self, zip_file: zipfile.ZipFile, file_path: str) -> List[dict]:
+ @staticmethod
+ def _read_json(zip_file: zipfile.ZipFile, file_path: str) -> List[dict]:
"""Read JSON data from a zip subfile."""
with zip_file.open(file_path, "r") as f:
data = json.load(f)
diff --git a/libs/community/langchain_community/chat_loaders/telegram.py b/libs/community/langchain_community/chat_loaders/telegram.py
index e8d87b08fd..c0c9bf7e7b 100644
--- a/libs/community/langchain_community/chat_loaders/telegram.py
+++ b/libs/community/langchain_community/chat_loaders/telegram.py
@@ -36,7 +36,8 @@ class TelegramChatLoader(BaseChatLoader):
"""
self.path = path if isinstance(path, str) else str(path)
- def _load_single_chat_session_html(self, file_path: str) -> ChatSession:
+ @staticmethod
+ def _load_single_chat_session_html(file_path: str) -> ChatSession:
"""Load a single chat session from an HTML file.
Args:
@@ -82,7 +83,8 @@ class TelegramChatLoader(BaseChatLoader):
return ChatSession(messages=results)
- def _load_single_chat_session_json(self, file_path: str) -> ChatSession:
+ @staticmethod
+ def _load_single_chat_session_json(file_path: str) -> ChatSession:
"""Load a single chat session from a JSON file.
Args:
@@ -113,7 +115,8 @@ class TelegramChatLoader(BaseChatLoader):
return ChatSession(messages=results)
- def _iterate_files(self, path: str) -> Iterator[str]:
+ @staticmethod
+ def _iterate_files(path: str) -> Iterator[str]:
"""Iterate over files in a directory or zip file.
Args:
diff --git a/libs/community/langchain_community/chat_loaders/whatsapp.py b/libs/community/langchain_community/chat_loaders/whatsapp.py
index 1b3173459e..4856da0ead 100644
--- a/libs/community/langchain_community/chat_loaders/whatsapp.py
+++ b/libs/community/langchain_community/chat_loaders/whatsapp.py
@@ -86,7 +86,8 @@ class WhatsAppChatLoader(BaseChatLoader):
logger.debug(f"Could not parse line: {line}")
return ChatSession(messages=results)
- def _iterate_files(self, path: str) -> Iterator[str]:
+ @staticmethod
+ def _iterate_files(path: str) -> Iterator[str]:
"""Iterate over the files in a directory or zip file.
Args: