Skip to content

The agent engineering platform.

Improvement[Community] Improve methods in `IMessageChatLoader` (#25746)

ZhangShenao44e3e2391c48
diff --git a/libs/community/langchain_community/chat_loaders/imessage.py b/libs/community/langchain_community/chat_loaders/imessage.py
index e69f0a0425..4141111355 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