-
Notifications
You must be signed in to change notification settings - Fork 14k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update WhatsAppChatLoader regex to handle multiple date-time formats (#…
…4186) This PR updates the `message_line_regex` used by `WhatsAppChatLoader` to support different date-time formats used in WhatsApp chat exports; resolves #4153. The new regex handles the following input formats: ```terminal [05.05.23, 15:48:11] James: Hi here [11/8/21, 9:41:32 AM] User name: Message 123 1/23/23, 3:19 AM - User 2: Bye! 1/23/23, 3:22_AM - User 1: And let me know if anything changes ``` Tests have been added to verify that the loader works correctly with all formats.
- Loading branch information
Showing
3 changed files
with
47 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
tests/integration_tests/document_loaders/test_whatsapp_chat.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from pathlib import Path | ||
|
||
from langchain.document_loaders import WhatsAppChatLoader | ||
|
||
|
||
def test_whatsapp_chat_loader() -> None: | ||
"""Test WhatsAppChatLoader.""" | ||
file_path = Path(__file__).parent.parent / "examples" / "whatsapp_chat.txt" | ||
loader = WhatsAppChatLoader(str(file_path)) | ||
docs = loader.load() | ||
|
||
assert len(docs) == 1 | ||
assert docs[0].metadata["source"] == str(file_path) | ||
assert docs[0].page_content == ( | ||
"James on 05.05.23, 15:48:11: Hi here\n\n" | ||
"User name on 11/8/21, 9:41:32 AM: Message 123\n\n" | ||
"User 2 on 1/23/23, 3:19 AM: Bye!\n\n" | ||
"User 1 on 1/23/23, 3:22_AM: And let me know if anything changes\n\n" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[05.05.23, 15:48:11] James: Hi here | ||
[11/8/21, 9:41:32 AM] User name: Message 123 | ||
1/23/23, 3:19 AM - User 2: Bye! | ||
1/23/23, 3:22_AM - User 1: And let me know if anything changes |