2023-12-11 21:53:30 +00:00
|
|
|
"""**Chat Loaders** load chat messages from common communications platforms.
|
|
|
|
|
|
|
|
Load chat messages from various
|
|
|
|
communications platforms such as Facebook Messenger, Telegram, and
|
|
|
|
WhatsApp. The loaded chat messages can be used for fine-tuning models.
|
|
|
|
|
|
|
|
**Class hierarchy:**
|
|
|
|
|
|
|
|
.. code-block::
|
|
|
|
|
|
|
|
BaseChatLoader --> <name>ChatLoader # Examples: WhatsAppChatLoader, IMessageChatLoader
|
|
|
|
|
|
|
|
**Main helpers:**
|
|
|
|
|
|
|
|
.. code-block::
|
|
|
|
|
|
|
|
ChatSession
|
|
|
|
|
|
|
|
""" # noqa: E501
|
2024-03-11 20:37:36 +00:00
|
|
|
|
|
|
|
import importlib
|
2024-04-10 17:01:19 +00:00
|
|
|
from typing import TYPE_CHECKING, Any
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
from langchain_community.chat_loaders.base import (
|
2024-04-30 17:13:48 +00:00
|
|
|
BaseChatLoader,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_loaders.facebook_messenger import (
|
2024-04-30 17:13:48 +00:00
|
|
|
FolderFacebookMessengerChatLoader,
|
|
|
|
SingleFileFacebookMessengerChatLoader,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_loaders.gmail import (
|
2024-04-30 17:13:48 +00:00
|
|
|
GMailLoader,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_loaders.imessage import (
|
2024-04-30 17:13:48 +00:00
|
|
|
IMessageChatLoader,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_loaders.langsmith import (
|
2024-04-30 17:13:48 +00:00
|
|
|
LangSmithDatasetChatLoader,
|
|
|
|
LangSmithRunChatLoader,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_loaders.slack import (
|
2024-04-30 17:13:48 +00:00
|
|
|
SlackChatLoader,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_loaders.telegram import (
|
2024-04-30 17:13:48 +00:00
|
|
|
TelegramChatLoader,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
from langchain_community.chat_loaders.whatsapp import (
|
2024-04-30 17:13:48 +00:00
|
|
|
WhatsAppChatLoader,
|
2024-04-10 17:01:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
__all__ = [
|
|
|
|
"BaseChatLoader",
|
|
|
|
"FolderFacebookMessengerChatLoader",
|
|
|
|
"GMailLoader",
|
|
|
|
"IMessageChatLoader",
|
|
|
|
"LangSmithDatasetChatLoader",
|
|
|
|
"LangSmithRunChatLoader",
|
|
|
|
"SingleFileFacebookMessengerChatLoader",
|
|
|
|
"SlackChatLoader",
|
|
|
|
"TelegramChatLoader",
|
|
|
|
"WhatsAppChatLoader",
|
|
|
|
]
|
2024-03-11 20:37:36 +00:00
|
|
|
|
|
|
|
_module_lookup = {
|
2024-04-26 21:45:51 +00:00
|
|
|
"BaseChatLoader": "langchain_core.chat_loaders",
|
2024-03-11 20:37:36 +00:00
|
|
|
"FolderFacebookMessengerChatLoader": "langchain_community.chat_loaders.facebook_messenger", # noqa: E501
|
|
|
|
"GMailLoader": "langchain_community.chat_loaders.gmail",
|
|
|
|
"IMessageChatLoader": "langchain_community.chat_loaders.imessage",
|
|
|
|
"LangSmithDatasetChatLoader": "langchain_community.chat_loaders.langsmith",
|
|
|
|
"LangSmithRunChatLoader": "langchain_community.chat_loaders.langsmith",
|
|
|
|
"SingleFileFacebookMessengerChatLoader": "langchain_community.chat_loaders.facebook_messenger", # noqa: E501
|
|
|
|
"SlackChatLoader": "langchain_community.chat_loaders.slack",
|
|
|
|
"TelegramChatLoader": "langchain_community.chat_loaders.telegram",
|
|
|
|
"WhatsAppChatLoader": "langchain_community.chat_loaders.whatsapp",
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def __getattr__(name: str) -> Any:
|
|
|
|
if name in _module_lookup:
|
|
|
|
module = importlib.import_module(_module_lookup[name])
|
|
|
|
return getattr(module, name)
|
|
|
|
raise AttributeError(f"module {__name__} has no attribute {name}")
|