Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

langchain[patch]: chat histories to handle optional community dependence #21194

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 58 additions & 21 deletions libs/langchain/langchain/memory/chat_message_histories/__init__.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,84 @@
import warnings
from typing import Any
from typing import TYPE_CHECKING, Any

from langchain_core._api import LangChainDeprecationWarning
from langchain._api import create_importer

from langchain._api.interactive_env import is_interactive_env
if TYPE_CHECKING:
from langchain_community.chat_message_histories import (
AstraDBChatMessageHistory,
CassandraChatMessageHistory,
ChatMessageHistory,
CosmosDBChatMessageHistory,
DynamoDBChatMessageHistory,
ElasticsearchChatMessageHistory,
FileChatMessageHistory,
FirestoreChatMessageHistory,
MomentoChatMessageHistory,
MongoDBChatMessageHistory,
Neo4jChatMessageHistory,
PostgresChatMessageHistory,
RedisChatMessageHistory,
RocksetChatMessageHistory,
SingleStoreDBChatMessageHistory,
SQLChatMessageHistory,
StreamlitChatMessageHistory,
UpstashRedisChatMessageHistory,
XataChatMessageHistory,
ZepChatMessageHistory,
)

# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {
"AstraDBChatMessageHistory": "langchain_community.chat_message_histories",
"CassandraChatMessageHistory": "langchain_community.chat_message_histories",
"ChatMessageHistory": "langchain_community.chat_message_histories",
"CosmosDBChatMessageHistory": "langchain_community.chat_message_histories",
"DynamoDBChatMessageHistory": "langchain_community.chat_message_histories",
"ElasticsearchChatMessageHistory": "langchain_community.chat_message_histories",
"FileChatMessageHistory": "langchain_community.chat_message_histories",
"FirestoreChatMessageHistory": "langchain_community.chat_message_histories",
"MomentoChatMessageHistory": "langchain_community.chat_message_histories",
"MongoDBChatMessageHistory": "langchain_community.chat_message_histories",
"Neo4jChatMessageHistory": "langchain_community.chat_message_histories",
"PostgresChatMessageHistory": "langchain_community.chat_message_histories",
"RedisChatMessageHistory": "langchain_community.chat_message_histories",
"RocksetChatMessageHistory": "langchain_community.chat_message_histories",
"SQLChatMessageHistory": "langchain_community.chat_message_histories",
"SingleStoreDBChatMessageHistory": "langchain_community.chat_message_histories",
"StreamlitChatMessageHistory": "langchain_community.chat_message_histories",
"UpstashRedisChatMessageHistory": "langchain_community.chat_message_histories",
"XataChatMessageHistory": "langchain_community.chat_message_histories",
"ZepChatMessageHistory": "langchain_community.chat_message_histories",
}

def __getattr__(name: str) -> Any:
from langchain_community import chat_message_histories
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)

# If not in interactive env, raise warning.
if not is_interactive_env():
warnings.warn(
"Importing chat message histories from langchain is deprecated. Importing "
"from langchain will no longer be supported as of langchain==0.2.0. "
"Please import from langchain-community instead:\n\n"
f"`from langchain_community.chat_message_histories import {name}`.\n\n"
"To install langchain-community run `pip install -U langchain-community`.",
category=LangChainDeprecationWarning,
)

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


__all__ = [
"AstraDBChatMessageHistory",
"ChatMessageHistory",
"CassandraChatMessageHistory",
"ChatMessageHistory",
"CosmosDBChatMessageHistory",
"DynamoDBChatMessageHistory",
"ElasticsearchChatMessageHistory",
"FileChatMessageHistory",
"FirestoreChatMessageHistory",
"MomentoChatMessageHistory",
"MongoDBChatMessageHistory",
"Neo4jChatMessageHistory",
"PostgresChatMessageHistory",
"RedisChatMessageHistory",
"RocksetChatMessageHistory",
"SingleStoreDBChatMessageHistory",
"SQLChatMessageHistory",
"StreamlitChatMessageHistory",
"SingleStoreDBChatMessageHistory",
"UpstashRedisChatMessageHistory",
"XataChatMessageHistory",
"ZepChatMessageHistory",
"UpstashRedisChatMessageHistory",
"Neo4jChatMessageHistory",
]
28 changes: 24 additions & 4 deletions libs/langchain/langchain/memory/chat_message_histories/astradb.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
from langchain_community.chat_message_histories.astradb import (
AstraDBChatMessageHistory,
)
from typing import TYPE_CHECKING, Any

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

if TYPE_CHECKING:
from langchain_community.chat_message_histories import AstraDBChatMessageHistory

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

_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)


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


__all__ = [
"AstraDBChatMessageHistory",
]
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
from langchain_community.chat_message_histories.cassandra import (
CassandraChatMessageHistory,
)
from typing import TYPE_CHECKING, Any

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

if TYPE_CHECKING:
from langchain_community.chat_message_histories import CassandraChatMessageHistory

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

_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)


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


__all__ = [
"CassandraChatMessageHistory",
]
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
from langchain_community.chat_message_histories.cosmos_db import (
CosmosDBChatMessageHistory,
)
from typing import TYPE_CHECKING, Any

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

if TYPE_CHECKING:
from langchain_community.chat_message_histories import CosmosDBChatMessageHistory

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

_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)


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


__all__ = [
"CosmosDBChatMessageHistory",
]
28 changes: 24 additions & 4 deletions libs/langchain/langchain/memory/chat_message_histories/dynamodb.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
from langchain_community.chat_message_histories.dynamodb import (
DynamoDBChatMessageHistory,
)
from typing import TYPE_CHECKING, Any

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

if TYPE_CHECKING:
from langchain_community.chat_message_histories import DynamoDBChatMessageHistory

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

_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)


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


__all__ = [
"DynamoDBChatMessageHistory",
]
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
from langchain_community.chat_message_histories.elasticsearch import (
ElasticsearchChatMessageHistory,
)
from typing import TYPE_CHECKING, Any

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

if TYPE_CHECKING:
from langchain_community.chat_message_histories import (
ElasticsearchChatMessageHistory,
)

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

_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)


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


__all__ = [
"ElasticsearchChatMessageHistory",
]
26 changes: 24 additions & 2 deletions libs/langchain/langchain/memory/chat_message_histories/file.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
from langchain_community.chat_message_histories.file import FileChatMessageHistory
from typing import TYPE_CHECKING, Any

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

if TYPE_CHECKING:
from langchain_community.chat_message_histories import FileChatMessageHistory

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

_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)


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


__all__ = [
"FileChatMessageHistory",
]
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
from langchain_community.chat_message_histories.firestore import (
FirestoreChatMessageHistory,
)
from typing import TYPE_CHECKING, Any

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

if TYPE_CHECKING:
from langchain_community.chat_message_histories import FirestoreChatMessageHistory

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

_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)


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


__all__ = [
"FirestoreChatMessageHistory",
]
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
from langchain_community.chat_message_histories.in_memory import ChatMessageHistory
from typing import TYPE_CHECKING, Any

from langchain._api import create_importer

if TYPE_CHECKING:
from langchain_community.chat_message_histories.in_memory import ChatMessageHistory

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could do in another PR, but langchain_community just imports this from core, so it may make sense to do the same here?

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

_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)


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


__all__ = ["ChatMessageHistory"]
28 changes: 24 additions & 4 deletions libs/langchain/langchain/memory/chat_message_histories/momento.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
from langchain_community.chat_message_histories.momento import (
MomentoChatMessageHistory,
)
from typing import TYPE_CHECKING, Any

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

if TYPE_CHECKING:
from langchain_community.chat_message_histories import MomentoChatMessageHistory

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

_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)


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


__all__ = [
"MomentoChatMessageHistory",
]
28 changes: 24 additions & 4 deletions libs/langchain/langchain/memory/chat_message_histories/mongodb.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
from langchain_community.chat_message_histories.mongodb import (
MongoDBChatMessageHistory,
)
from typing import TYPE_CHECKING, Any

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

if TYPE_CHECKING:
from langchain_community.chat_message_histories import MongoDBChatMessageHistory

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

_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)


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


__all__ = [
"MongoDBChatMessageHistory",
]
Loading
Loading