langchain[patch]: Upgrade storage to treat langchain community as optional (#21105)

pull/21143/head
Eugene Yurtsev 1 month ago committed by GitHub
parent ab55f6996d
commit 2fcab9acd9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -5,48 +5,52 @@ to a simple key-value interface.
The primary goal of these storages is to support implementation of caching.
"""
import warnings
from typing import Any
from typing import TYPE_CHECKING, Any
from langchain_core._api import LangChainDeprecationWarning
from langchain_core.stores import (
InMemoryByteStore,
InMemoryStore,
InvalidKeyException,
)
from langchain._api import create_importer
from langchain.storage._lc_store import create_kv_docstore, create_lc_store
from langchain.storage.encoder_backed import EncoderBackedStore
from langchain.storage.file_system import LocalFileStore
from langchain.utils.interactive_env import is_interactive_env
if TYPE_CHECKING:
from langchain_community.storage import (
RedisStore,
UpstashRedisByteStore,
UpstashRedisStore,
)
def __getattr__(name: str) -> Any:
from langchain_community import storage
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {
"RedisStore": "langchain_community.storage",
"UpstashRedisByteStore": "langchain_community.storage",
"UpstashRedisStore": "langchain_community.storage",
}
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
# If not in interactive env, raise warning.
if not is_interactive_env():
warnings.warn(
"Importing stores 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.storage import {name}`.\n\n"
"To install langchain-community run `pip install -U langchain-community`.",
category=LangChainDeprecationWarning,
)
return getattr(storage, name)
def __getattr__(name: str) -> Any:
"""Look up attributes dynamically."""
return _import_attribute(name)
__all__ = [
"EncoderBackedStore",
"RedisStore",
"create_lc_store",
"create_kv_docstore",
"LocalFileStore",
"create_lc_store",
"EncoderBackedStore",
"InMemoryByteStore",
"InMemoryStore",
"InvalidKeyException",
"InMemoryByteStore",
"LocalFileStore",
"RedisStore",
"UpstashRedisByteStore",
"UpstashRedisStore",
]

@ -1,3 +1,23 @@
from langchain_community.storage.redis import RedisStore
from typing import TYPE_CHECKING, Any
__all__ = ["RedisStore"]
from langchain._api import create_importer
if TYPE_CHECKING:
from langchain_community.storage import RedisStore
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {"RedisStore": "langchain_community.storage"}
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
def __getattr__(name: str) -> Any:
"""Look up attributes dynamically."""
return _import_attribute(name)
__all__ = [
"RedisStore",
]

@ -1,6 +1,27 @@
from langchain_community.storage.upstash_redis import (
UpstashRedisByteStore,
UpstashRedisStore,
)
from typing import TYPE_CHECKING, Any
__all__ = ["UpstashRedisStore", "UpstashRedisByteStore"]
from langchain._api import create_importer
if TYPE_CHECKING:
from langchain_community.storage import UpstashRedisByteStore, UpstashRedisStore
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {
"UpstashRedisStore": "langchain_community.storage",
"UpstashRedisByteStore": "langchain_community.storage",
}
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
def __getattr__(name: str) -> Any:
"""Look up attributes dynamically."""
return _import_attribute(name)
__all__ = [
"UpstashRedisStore",
"UpstashRedisByteStore",
]

Loading…
Cancel
Save