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

This commit is contained in:
Eugene Yurtsev 2024-05-02 10:36:08 -04:00 committed by GitHub
parent c9119b0e75
commit b5c3a04e4b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
21 changed files with 543 additions and 90 deletions

View File

@ -1,32 +1,69 @@
import warnings from typing import TYPE_CHECKING, Any
from typing import 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",
}
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
def __getattr__(name: str) -> Any: def __getattr__(name: str) -> Any:
from langchain_community import chat_message_histories """Look up attributes dynamically."""
return _import_attribute(name)
# 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)
__all__ = [ __all__ = [
"AstraDBChatMessageHistory", "AstraDBChatMessageHistory",
"ChatMessageHistory",
"CassandraChatMessageHistory", "CassandraChatMessageHistory",
"ChatMessageHistory",
"CosmosDBChatMessageHistory", "CosmosDBChatMessageHistory",
"DynamoDBChatMessageHistory", "DynamoDBChatMessageHistory",
"ElasticsearchChatMessageHistory", "ElasticsearchChatMessageHistory",
@ -34,14 +71,14 @@ __all__ = [
"FirestoreChatMessageHistory", "FirestoreChatMessageHistory",
"MomentoChatMessageHistory", "MomentoChatMessageHistory",
"MongoDBChatMessageHistory", "MongoDBChatMessageHistory",
"Neo4jChatMessageHistory",
"PostgresChatMessageHistory", "PostgresChatMessageHistory",
"RedisChatMessageHistory", "RedisChatMessageHistory",
"RocksetChatMessageHistory", "RocksetChatMessageHistory",
"SingleStoreDBChatMessageHistory",
"SQLChatMessageHistory", "SQLChatMessageHistory",
"StreamlitChatMessageHistory", "StreamlitChatMessageHistory",
"SingleStoreDBChatMessageHistory", "UpstashRedisChatMessageHistory",
"XataChatMessageHistory", "XataChatMessageHistory",
"ZepChatMessageHistory", "ZepChatMessageHistory",
"UpstashRedisChatMessageHistory",
"Neo4jChatMessageHistory",
] ]

View File

@ -1,5 +1,25 @@
from langchain_community.chat_message_histories.astradb import ( from typing import TYPE_CHECKING, Any
AstraDBChatMessageHistory,
)
__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",
]

View File

@ -1,5 +1,25 @@
from langchain_community.chat_message_histories.cassandra import ( from typing import TYPE_CHECKING, Any
CassandraChatMessageHistory,
)
__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",
]

View File

@ -1,5 +1,25 @@
from langchain_community.chat_message_histories.cosmos_db import ( from typing import TYPE_CHECKING, Any
CosmosDBChatMessageHistory,
)
__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",
]

View File

@ -1,5 +1,25 @@
from langchain_community.chat_message_histories.dynamodb import ( from typing import TYPE_CHECKING, Any
DynamoDBChatMessageHistory,
)
__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",
]

View File

@ -1,5 +1,27 @@
from langchain_community.chat_message_histories.elasticsearch import ( from typing import TYPE_CHECKING, Any
from langchain._api import create_importer
if TYPE_CHECKING:
from langchain_community.chat_message_histories import (
ElasticsearchChatMessageHistory, ElasticsearchChatMessageHistory,
) )
__all__ = ["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",
]

View File

@ -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",
]

View File

@ -1,5 +1,25 @@
from langchain_community.chat_message_histories.firestore import ( from typing import TYPE_CHECKING, Any
FirestoreChatMessageHistory,
)
__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",
]

View File

@ -1,3 +1,21 @@
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 from langchain_community.chat_message_histories.in_memory import ChatMessageHistory
# 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"] __all__ = ["ChatMessageHistory"]

View File

@ -1,5 +1,25 @@
from langchain_community.chat_message_histories.momento import ( from typing import TYPE_CHECKING, Any
MomentoChatMessageHistory,
)
__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",
]

View File

@ -1,5 +1,25 @@
from langchain_community.chat_message_histories.mongodb import ( from typing import TYPE_CHECKING, Any
MongoDBChatMessageHistory,
)
__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",
]

View File

@ -1,3 +1,25 @@
from langchain_community.chat_message_histories.neo4j import Neo4jChatMessageHistory from typing import TYPE_CHECKING, Any
__all__ = ["Neo4jChatMessageHistory"] from langchain._api import create_importer
if TYPE_CHECKING:
from langchain_community.chat_message_histories import Neo4jChatMessageHistory
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {
"Neo4jChatMessageHistory": "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__ = [
"Neo4jChatMessageHistory",
]

View File

@ -1,5 +1,25 @@
from langchain_community.chat_message_histories.postgres import ( from typing import TYPE_CHECKING, Any
PostgresChatMessageHistory,
)
__all__ = ["PostgresChatMessageHistory"] from langchain._api import create_importer
if TYPE_CHECKING:
from langchain_community.chat_message_histories import PostgresChatMessageHistory
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {
"PostgresChatMessageHistory": "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__ = [
"PostgresChatMessageHistory",
]

View File

@ -1,3 +1,25 @@
from langchain_community.chat_message_histories.redis import RedisChatMessageHistory from typing import TYPE_CHECKING, Any
__all__ = ["RedisChatMessageHistory"] from langchain._api import create_importer
if TYPE_CHECKING:
from langchain_community.chat_message_histories import RedisChatMessageHistory
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {
"RedisChatMessageHistory": "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__ = [
"RedisChatMessageHistory",
]

View File

@ -1,5 +1,25 @@
from langchain_community.chat_message_histories.rocksetdb import ( from typing import TYPE_CHECKING, Any
RocksetChatMessageHistory,
)
__all__ = ["RocksetChatMessageHistory"] from langchain._api import create_importer
if TYPE_CHECKING:
from langchain_community.chat_message_histories import RocksetChatMessageHistory
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {
"RocksetChatMessageHistory": "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__ = [
"RocksetChatMessageHistory",
]

View File

@ -1,5 +1,27 @@
from langchain_community.chat_message_histories.singlestoredb import ( from typing import TYPE_CHECKING, Any
from langchain._api import create_importer
if TYPE_CHECKING:
from langchain_community.chat_message_histories import (
SingleStoreDBChatMessageHistory, SingleStoreDBChatMessageHistory,
) )
__all__ = ["SingleStoreDBChatMessageHistory"] # Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {
"SingleStoreDBChatMessageHistory": "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__ = [
"SingleStoreDBChatMessageHistory",
]

View File

@ -1,9 +1,31 @@
from typing import TYPE_CHECKING, Any
from langchain._api import create_importer
if TYPE_CHECKING:
from langchain_community.chat_message_histories import SQLChatMessageHistory
from langchain_community.chat_message_histories.sql import ( from langchain_community.chat_message_histories.sql import (
BaseMessageConverter, BaseMessageConverter,
DefaultMessageConverter, DefaultMessageConverter,
SQLChatMessageHistory,
) )
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {
"BaseMessageConverter": "langchain_community.chat_message_histories.sql",
"DefaultMessageConverter": "langchain_community.chat_message_histories.sql",
"SQLChatMessageHistory": "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__ = [ __all__ = [
"BaseMessageConverter", "BaseMessageConverter",
"DefaultMessageConverter", "DefaultMessageConverter",

View File

@ -1,5 +1,25 @@
from langchain_community.chat_message_histories.streamlit import ( from typing import TYPE_CHECKING, Any
StreamlitChatMessageHistory,
)
__all__ = ["StreamlitChatMessageHistory"] from langchain._api import create_importer
if TYPE_CHECKING:
from langchain_community.chat_message_histories import StreamlitChatMessageHistory
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {
"StreamlitChatMessageHistory": "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__ = [
"StreamlitChatMessageHistory",
]

View File

@ -1,5 +1,27 @@
from langchain_community.chat_message_histories.upstash_redis import ( from typing import TYPE_CHECKING, Any
from langchain._api import create_importer
if TYPE_CHECKING:
from langchain_community.chat_message_histories import (
UpstashRedisChatMessageHistory, UpstashRedisChatMessageHistory,
) )
__all__ = ["UpstashRedisChatMessageHistory"] # Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {
"UpstashRedisChatMessageHistory": "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__ = [
"UpstashRedisChatMessageHistory",
]

View File

@ -1,3 +1,25 @@
from langchain_community.chat_message_histories.xata import XataChatMessageHistory from typing import TYPE_CHECKING, Any
__all__ = ["XataChatMessageHistory"] from langchain._api import create_importer
if TYPE_CHECKING:
from langchain_community.chat_message_histories import XataChatMessageHistory
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {
"XataChatMessageHistory": "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__ = [
"XataChatMessageHistory",
]

View File

@ -1,3 +1,25 @@
from langchain_community.chat_message_histories.zep import ZepChatMessageHistory from typing import TYPE_CHECKING, Any
__all__ = ["ZepChatMessageHistory"] from langchain._api import create_importer
if TYPE_CHECKING:
from langchain_community.chat_message_histories import ZepChatMessageHistory
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {
"ZepChatMessageHistory": "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__ = [
"ZepChatMessageHistory",
]