From b6c57d38fa370c250b5f014a8d9c3908f7a235f4 Mon Sep 17 00:00:00 2001 From: Mohammad Mohtashim <45242107+keenborder786@users.noreply.github.com> Date: Tue, 2 Jan 2024 07:52:23 +0500 Subject: [PATCH] Langchain_community: Small Fix when loading facebook messages (#15358) - **Description:** SingleFileFacebookMessengerChatLoader did not handle the case for when messages had stickers and/or photos so fixed that. - **Issue:** #15356 --------- Co-authored-by: Harrison Chase --- .../chat_loaders/facebook_messenger.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libs/community/langchain_community/chat_loaders/facebook_messenger.py b/libs/community/langchain_community/chat_loaders/facebook_messenger.py index f0aad601ecd68..82d326de083f2 100644 --- a/libs/community/langchain_community/chat_loaders/facebook_messenger.py +++ b/libs/community/langchain_community/chat_loaders/facebook_messenger.py @@ -37,7 +37,13 @@ def lazy_load(self) -> Iterator[ChatSession]: data = json.load(f) sorted_data = sorted(data["messages"], key=lambda x: x["timestamp_ms"]) messages = [] - for m in sorted_data: + for index, m in enumerate(sorted_data): + if "content" not in m: + logger.info( + f"""Skipping Message No. + {index+1} as no content is present in the message""" + ) + continue messages.append( HumanMessage( content=m["content"], additional_kwargs={"sender": m["sender_name"]}