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
4 changed files with 14 additions and 7 deletions

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)