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

There are some static methods in ChatLoaders, try to add @staticmethod
decorator for them.
This commit is contained in:
ZhangShenao 2024-08-23 23:00:41 +08:00 committed by GitHub
parent 644e0d3463
commit b38c83ff93
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 7 deletions

View File

@ -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.

View File

@ -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)

View File

@ -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:

View File

@ -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: