From 44e3e2391c48bfd0a8e6a20adde0b6567f4f43c3 Mon Sep 17 00:00:00 2001 From: ZhangShenao <15201440436@163.com> Date: Tue, 27 Aug 2024 02:20:22 +0800 Subject: [PATCH] Improvement[Community] Improve methods in `IMessageChatLoader` (#25746) - Add @staticmethod to static methods in `IMessageChatLoader`. - Format args name. --- .../langchain_community/chat_loaders/imessage.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libs/community/langchain_community/chat_loaders/imessage.py b/libs/community/langchain_community/chat_loaders/imessage.py index e69f0a04251..41411113550 100644 --- a/libs/community/langchain_community/chat_loaders/imessage.py +++ b/libs/community/langchain_community/chat_loaders/imessage.py @@ -68,7 +68,8 @@ class IMessageChatLoader(BaseChatLoader): "Please install it with `pip install pysqlite3`" ) from e - def _parse_attributedBody(self, attributedBody: bytes) -> str: + @staticmethod + def _parse_attributed_body(attributed_body: bytes) -> str: """ Parse the attributedBody field of the message table for the text content of the message. @@ -88,17 +89,18 @@ class IMessageChatLoader(BaseChatLoader): that byte. Args: - attributedBody (bytes): attributedBody field of the message table. + attributed_body (bytes): attributedBody field of the message table. Return: str: Text content of the message. """ - content = attributedBody.split(b"NSString")[1][5:] + content = attributed_body.split(b"NSString")[1][5:] length, start = content[0], 1 if content[0] == 129: length, start = int.from_bytes(content[1:3], "little"), 3 return content[start : start + length].decode("utf-8", errors="ignore") - def _get_session_query(self, use_chat_handle_table: bool) -> str: + @staticmethod + def _get_session_query(use_chat_handle_table: bool) -> str: # Messages sent pre OSX 12 require a join through the chat_handle_join table # However, the table doesn't exist if database created with OSX 12 or above. @@ -151,7 +153,7 @@ class IMessageChatLoader(BaseChatLoader): if text: content = text elif attributedBody: - content = self._parse_attributedBody(attributedBody) + content = self._parse_attributed_body(attributedBody) else: # Skip messages with no content continue