-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
langchain[patch]: chat histories to handle optional community depende…
…nce (#21194)
- Loading branch information
Showing
21 changed files
with
542 additions
and
89 deletions.
There are no files selected for viewing
79 changes: 58 additions & 21 deletions
79
libs/langchain/langchain/memory/chat_message_histories/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
28
libs/langchain/langchain/memory/chat_message_histories/astradb.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
] |
28 changes: 24 additions & 4 deletions
28
libs/langchain/langchain/memory/chat_message_histories/cassandra.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
] |
28 changes: 24 additions & 4 deletions
28
libs/langchain/langchain/memory/chat_message_histories/cosmos_db.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
28
libs/langchain/langchain/memory/chat_message_histories/dynamodb.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
] |
30 changes: 26 additions & 4 deletions
30
libs/langchain/langchain/memory/chat_message_histories/elasticsearch.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
26
libs/langchain/langchain/memory/chat_message_histories/file.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
] |
28 changes: 24 additions & 4 deletions
28
libs/langchain/langchain/memory/chat_message_histories/firestore.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
] |
20 changes: 19 additions & 1 deletion
20
libs/langchain/langchain/memory/chat_message_histories/in_memory.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
# 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
28
libs/langchain/langchain/memory/chat_message_histories/momento.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
28
libs/langchain/langchain/memory/chat_message_histories/mongodb.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
] |
Oops, something went wrong.