Skip to content

The agent engineering platform.

docstrings: `chat_loaders` (#10307)

Leonid Ganeline1b3ea1eeb4c8
diff --git a/libs/langchain/langchain/chat_loaders/__init__.py b/libs/langchain/langchain/chat_loaders/__init__.py
index 594d87344d..7547ddcecc 100644
--- a/libs/langchain/langchain/chat_loaders/__init__.py
+++ b/libs/langchain/langchain/chat_loaders/__init__.py
@@ -1,6 +1,19 @@
-"""Load chat messages from common communications platforms for finetuning.
+"""**Chat Loaders** load chat messages from common communications platforms.
-This module provides functions to load chat messages from various
+Load chat messages from various
communications platforms such as Facebook Messenger, Telegram, and
-WhatsApp. The loaded chat messages can be used for finetuning models.
-"""
+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
diff --git a/libs/langchain/langchain/chat_loaders/base.py b/libs/langchain/langchain/chat_loaders/base.py
index 418ba15d2f..6e1f37ca9a 100644
--- a/libs/langchain/langchain/chat_loaders/base.py
+++ b/libs/langchain/langchain/chat_loaders/base.py
@@ -1,10 +1,3 @@
-"""Base definitions for chat loaders.
-
-A chat loader is a class that loads chat messages from an external
-source such as a file or a database. The chat messages can then be
-used for finetuning.
-"""
-
from abc import ABC, abstractmethod
from typing import Iterator, List, Sequence, TypedDict
@@ -12,7 +5,7 @@ from langchain.schema.messages import BaseMessage
class ChatSession(TypedDict):
- """A chat session represents a single
+ """Chat Session represents a single
conversation, channel, or other group of messages."""
messages: Sequence[BaseMessage]
diff --git a/libs/langchain/langchain/chat_loaders/facebook_messenger.py b/libs/langchain/langchain/chat_loaders/facebook_messenger.py
index 5864c32740..bfdc0155c7 100644
--- a/libs/langchain/langchain/chat_loaders/facebook_messenger.py
+++ b/libs/langchain/langchain/chat_loaders/facebook_messenger.py
@@ -10,7 +10,7 @@ logger = logging.getLogger(__file__)
class SingleFileFacebookMessengerChatLoader(BaseChatLoader):
- """A chat loader for loading Facebook Messenger chat data from a single file.
+ """Load `Facebook Messenger` chat data from a single file.
Args:
path (Union[Path, str]): The path to the chat file.
@@ -45,7 +45,7 @@ class SingleFileFacebookMessengerChatLoader(BaseChatLoader):
class FolderFacebookMessengerChatLoader(BaseChatLoader):
- """A chat loader for loading Facebook Messenger chat data from a folder.
+ """Load `Facebook Messenger` chat data from a folder.
Args:
path (Union[str, Path]): The path to the directory
diff --git a/libs/langchain/langchain/chat_loaders/gmail.py b/libs/langchain/langchain/chat_loaders/gmail.py
index 4e88accdee..94a3c5617e 100644
--- a/libs/langchain/langchain/chat_loaders/gmail.py
+++ b/libs/langchain/langchain/chat_loaders/gmail.py
@@ -62,7 +62,7 @@ def _get_message_data(service: Any, message: Any) -> ChatSession:
class GMailLoader(BaseChatLoader):
- """This loader goes over how to load data from GMail.
+ """Load data from `GMail`.
There are many ways you could want to load data from GMail.
This loader is currently fairly opinionated in how to do so.
diff --git a/libs/langchain/langchain/chat_loaders/imessage.py b/libs/langchain/langchain/chat_loaders/imessage.py
index ff9a06142c..d6c02f1e53 100644
--- a/libs/langchain/langchain/chat_loaders/imessage.py
+++ b/libs/langchain/langchain/chat_loaders/imessage.py
@@ -1,14 +1,3 @@
-"""IMessage Chat Loader.
-
-This class is used to load chat sessions from the iMessage chat.db SQLite file.
-It only works on macOS when you have iMessage enabled and have the chat.db file.
-
-The chat.db file is likely located at ~/Library/Messages/chat.db. However, your
-terminal may not have permission to access this file. To resolve this, you can
-copy the file to a different location, change the permissions of the file, or
-grant full disk access for your terminal emulator in System Settings > Security
-and Privacy > Full Disk Access.
-"""
from __future__ import annotations
from pathlib import Path
@@ -22,6 +11,17 @@ if TYPE_CHECKING:
class IMessageChatLoader(chat_loaders.BaseChatLoader):
+ """Load chat sessions from the `iMessage` chat.db SQLite file.
+
+ It only works on macOS when you have iMessage enabled and have the chat.db file.
+
+ The chat.db file is likely located at ~/Library/Messages/chat.db. However, your
+ terminal may not have permission to access this file. To resolve this, you can
+ copy the file to a different location, change the permissions of the file, or
+ grant full disk access for your terminal emulator in System Settings > Security
+ and Privacy > Full Disk Access.
+ """
+
def __init__(self, path: Optional[Union[str, Path]] = None):
"""
Initialize the IMessageChatLoader.
diff --git a/libs/langchain/langchain/chat_loaders/slack.py b/libs/langchain/langchain/chat_loaders/slack.py
index 261289bb43..0bbd503979 100644
--- a/libs/langchain/langchain/chat_loaders/slack.py
+++ b/libs/langchain/langchain/chat_loaders/slack.py
@@ -12,6 +12,8 @@ logger = logging.getLogger(__name__)
class SlackChatLoader(chat_loaders.BaseChatLoader):
+ """Load `Slack` conversations from a dump zip file."""
+
def __init__(
self,
path: Union[str, Path],
diff --git a/libs/langchain/langchain/chat_loaders/telegram.py b/libs/langchain/langchain/chat_loaders/telegram.py
index f55fd71476..5f0bbfa324 100644
--- a/libs/langchain/langchain/chat_loaders/telegram.py
+++ b/libs/langchain/langchain/chat_loaders/telegram.py
@@ -13,8 +13,7 @@ logger = logging.getLogger(__name__)
class TelegramChatLoader(chat_loaders.BaseChatLoader):
- """A loading utility for converting telegram conversations
- to LangChain chat messages.
+ """Load `telegram` conversations to LangChain chat messages.
To export, use the Telegram Desktop app from
https://desktop.telegram.org/, select a conversation, click the three dots
diff --git a/libs/langchain/langchain/chat_loaders/whatsapp.py b/libs/langchain/langchain/chat_loaders/whatsapp.py
index c911e262c6..e2518ab44d 100644
--- a/libs/langchain/langchain/chat_loaders/whatsapp.py
+++ b/libs/langchain/langchain/chat_loaders/whatsapp.py
@@ -12,6 +12,8 @@ logger = logging.getLogger(__name__)
class WhatsAppChatLoader(chat_loaders.BaseChatLoader):
+ """Load `WhatsApp` conversations from a dump zip file or directory."""
+
def __init__(self, path: str):
"""Initialize the WhatsAppChatLoader.