Skip to content

Commit

Permalink
langchain[patch]: Migrate chat loaders to optional community imports (#…
Browse files Browse the repository at this point in the history
…21089)

Migrate chat loaders to optional community imports
  • Loading branch information
eyurtsev authored May 1, 2024
1 parent 2b10c4d commit d640605
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 23 deletions.
26 changes: 22 additions & 4 deletions libs/langchain/langchain/chat_loaders/gmail.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
from langchain_community.chat_loaders.gmail import (
GMailLoader,
)
from typing import TYPE_CHECKING, Any

__all__ = ["GMailLoader"]
from langchain._api import create_importer

if TYPE_CHECKING:
from langchain_community.chat_loaders.gmail import GMailLoader

# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {"GMailLoader": "langchain_community.chat_loaders.gmail"}

_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)


def __getattr__(name: str) -> Any:
"""Look up attributes dynamically."""
return _import_attribute(name)


__all__ = [
"GMailLoader",
]
24 changes: 22 additions & 2 deletions libs/langchain/langchain/chat_loaders/imessage.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
from langchain_community.chat_loaders.imessage import IMessageChatLoader
from typing import TYPE_CHECKING, Any

__all__ = ["IMessageChatLoader"]
from langchain._api import create_importer

if TYPE_CHECKING:
from langchain_community.chat_loaders.imessage import IMessageChatLoader

# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {"IMessageChatLoader": "langchain_community.chat_loaders.imessage"}

_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)


def __getattr__(name: str) -> Any:
"""Look up attributes dynamically."""
return _import_attribute(name)


__all__ = [
"IMessageChatLoader",
]
34 changes: 29 additions & 5 deletions libs/langchain/langchain/chat_loaders/langsmith.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
from langchain_community.chat_loaders.langsmith import (
LangSmithDatasetChatLoader,
LangSmithRunChatLoader,
)
from typing import TYPE_CHECKING, Any

__all__ = ["LangSmithRunChatLoader", "LangSmithDatasetChatLoader"]
from langchain._api import create_importer

if TYPE_CHECKING:
from langchain_community.chat_loaders.langsmith import (
LangSmithDatasetChatLoader,
LangSmithRunChatLoader,
)

# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {
"LangSmithRunChatLoader": "langchain_community.chat_loaders.langsmith",
"LangSmithDatasetChatLoader": "langchain_community.chat_loaders.langsmith",
}

_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)


def __getattr__(name: str) -> Any:
"""Look up attributes dynamically."""
return _import_attribute(name)


__all__ = [
"LangSmithRunChatLoader",
"LangSmithDatasetChatLoader",
]
24 changes: 22 additions & 2 deletions libs/langchain/langchain/chat_loaders/slack.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
from langchain_community.chat_loaders.slack import SlackChatLoader
from typing import TYPE_CHECKING, Any

__all__ = ["SlackChatLoader"]
from langchain._api import create_importer

if TYPE_CHECKING:
from langchain_community.chat_loaders.slack import SlackChatLoader

# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {"SlackChatLoader": "langchain_community.chat_loaders.slack"}

_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)


def __getattr__(name: str) -> Any:
"""Look up attributes dynamically."""
return _import_attribute(name)


__all__ = [
"SlackChatLoader",
]
24 changes: 22 additions & 2 deletions libs/langchain/langchain/chat_loaders/telegram.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
from langchain_community.chat_loaders.telegram import TelegramChatLoader
from typing import TYPE_CHECKING, Any

__all__ = ["TelegramChatLoader"]
from langchain._api import create_importer

if TYPE_CHECKING:
from langchain_community.chat_loaders.telegram import TelegramChatLoader

# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {"TelegramChatLoader": "langchain_community.chat_loaders.telegram"}

_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)


def __getattr__(name: str) -> Any:
"""Look up attributes dynamically."""
return _import_attribute(name)


__all__ = [
"TelegramChatLoader",
]
35 changes: 29 additions & 6 deletions libs/langchain/langchain/chat_loaders/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
from langchain_community.chat_loaders.utils import (
map_ai_messages,
map_ai_messages_in_session,
merge_chat_runs,
merge_chat_runs_in_session,
)
from typing import TYPE_CHECKING, Any

from langchain._api import create_importer

if TYPE_CHECKING:
from langchain_community.chat_loaders.utils import (
map_ai_messages,
map_ai_messages_in_session,
merge_chat_runs,
merge_chat_runs_in_session,
)

# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {
"merge_chat_runs_in_session": "langchain_community.chat_loaders.utils",
"merge_chat_runs": "langchain_community.chat_loaders.utils",
"map_ai_messages_in_session": "langchain_community.chat_loaders.utils",
"map_ai_messages": "langchain_community.chat_loaders.utils",
}

_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)


def __getattr__(name: str) -> Any:
"""Look up attributes dynamically."""
return _import_attribute(name)


__all__ = [
"merge_chat_runs_in_session",
Expand Down
24 changes: 22 additions & 2 deletions libs/langchain/langchain/chat_loaders/whatsapp.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
from langchain_community.chat_loaders.whatsapp import WhatsAppChatLoader
from typing import TYPE_CHECKING, Any

__all__ = ["WhatsAppChatLoader"]
from langchain._api import create_importer

if TYPE_CHECKING:
from langchain_community.chat_loaders.whatsapp import WhatsAppChatLoader

# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {"WhatsAppChatLoader": "langchain_community.chat_loaders.whatsapp"}

_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)


def __getattr__(name: str) -> Any:
"""Look up attributes dynamically."""
return _import_attribute(name)


__all__ = [
"WhatsAppChatLoader",
]

0 comments on commit d640605

Please sign in to comment.