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 <hw.chase.17@gmail.com>
This commit is contained in:
Mohammad Mohtashim 2024-01-02 07:52:23 +05:00 committed by GitHub
parent cbfaccc424
commit b6c57d38fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -37,7 +37,13 @@ class SingleFileFacebookMessengerChatLoader(BaseChatLoader):
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"]}