mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-25 08:03:39 +00:00
langchain[patch]: Upgrade storage to treat langchain community as optional (#21105)
This commit is contained in:
parent
ab55f6996d
commit
2fcab9acd9
@ -5,48 +5,52 @@ to a simple key-value interface.
|
|||||||
|
|
||||||
The primary goal of these storages is to support implementation of caching.
|
The primary goal of these storages is to support implementation of caching.
|
||||||
"""
|
"""
|
||||||
import warnings
|
from typing import TYPE_CHECKING, Any
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
from langchain_core._api import LangChainDeprecationWarning
|
|
||||||
from langchain_core.stores import (
|
from langchain_core.stores import (
|
||||||
InMemoryByteStore,
|
InMemoryByteStore,
|
||||||
InMemoryStore,
|
InMemoryStore,
|
||||||
InvalidKeyException,
|
InvalidKeyException,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from langchain._api import create_importer
|
||||||
from langchain.storage._lc_store import create_kv_docstore, create_lc_store
|
from langchain.storage._lc_store import create_kv_docstore, create_lc_store
|
||||||
from langchain.storage.encoder_backed import EncoderBackedStore
|
from langchain.storage.encoder_backed import EncoderBackedStore
|
||||||
from langchain.storage.file_system import LocalFileStore
|
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,
|
||||||
|
)
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
||||||
|
|
||||||
def __getattr__(name: str) -> Any:
|
def __getattr__(name: str) -> Any:
|
||||||
from langchain_community import storage
|
"""Look up attributes dynamically."""
|
||||||
|
return _import_attribute(name)
|
||||||
# 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)
|
|
||||||
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"EncoderBackedStore",
|
|
||||||
"RedisStore",
|
|
||||||
"create_lc_store",
|
|
||||||
"create_kv_docstore",
|
"create_kv_docstore",
|
||||||
"LocalFileStore",
|
"create_lc_store",
|
||||||
|
"EncoderBackedStore",
|
||||||
|
"InMemoryByteStore",
|
||||||
"InMemoryStore",
|
"InMemoryStore",
|
||||||
"InvalidKeyException",
|
"InvalidKeyException",
|
||||||
"InMemoryByteStore",
|
"LocalFileStore",
|
||||||
|
"RedisStore",
|
||||||
"UpstashRedisByteStore",
|
"UpstashRedisByteStore",
|
||||||
"UpstashRedisStore",
|
"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 (
|
from typing import TYPE_CHECKING, Any
|
||||||
UpstashRedisByteStore,
|
|
||||||
UpstashRedisStore,
|
|
||||||
)
|
|
||||||
|
|
||||||
__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…
Reference in New Issue
Block a user