mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-13 22:59:05 +00:00
langchain[patch]: Update docstore module to use optional imports from community (#21091)
This commit is contained in:
parent
d640605694
commit
86ff8a3fb4
@ -14,29 +14,34 @@ The **Docstore** is a simplified version of the Document Loader.
|
||||
|
||||
Document, AddableMixin
|
||||
"""
|
||||
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.utils.interactive_env import is_interactive_env
|
||||
if TYPE_CHECKING:
|
||||
from langchain_community.docstore.arbitrary_fn import DocstoreFn
|
||||
from langchain_community.docstore.in_memory import InMemoryDocstore
|
||||
from langchain_community.docstore.wikipedia import Wikipedia
|
||||
|
||||
# Create a way to dynamically look up deprecated imports.
|
||||
# Used to consolidate logic for raising deprecation warnings and
|
||||
# handling optional imports.
|
||||
DEPRECATED_LOOKUP = {
|
||||
"DocstoreFn": "langchain_community.docstore.arbitrary_fn",
|
||||
"InMemoryDocstore": "langchain_community.docstore.in_memory",
|
||||
"Wikipedia": "langchain_community.docstore.wikipedia",
|
||||
}
|
||||
|
||||
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
from langchain_community import docstore
|
||||
|
||||
# If not in interactive env, raise warning.
|
||||
if not is_interactive_env():
|
||||
warnings.warn(
|
||||
"Importing docstores 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.docstore import {name}`.\n\n"
|
||||
"To install langchain-community run `pip install -U langchain-community`.",
|
||||
category=LangChainDeprecationWarning,
|
||||
)
|
||||
|
||||
return getattr(docstore, name)
|
||||
"""Look up attributes dynamically."""
|
||||
return _import_attribute(name)
|
||||
|
||||
|
||||
__all__ = ["DocstoreFn", "InMemoryDocstore", "Wikipedia"]
|
||||
__all__ = [
|
||||
"DocstoreFn",
|
||||
"InMemoryDocstore",
|
||||
"Wikipedia",
|
||||
]
|
||||
|
@ -1,3 +1,23 @@
|
||||
from langchain_community.docstore.arbitrary_fn import DocstoreFn
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
__all__ = ["DocstoreFn"]
|
||||
from langchain._api import create_importer
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain_community.docstore.arbitrary_fn import DocstoreFn
|
||||
|
||||
# Create a way to dynamically look up deprecated imports.
|
||||
# Used to consolidate logic for raising deprecation warnings and
|
||||
# handling optional imports.
|
||||
DEPRECATED_LOOKUP = {"DocstoreFn": "langchain_community.docstore.arbitrary_fn"}
|
||||
|
||||
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""Look up attributes dynamically."""
|
||||
return _import_attribute(name)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"DocstoreFn",
|
||||
]
|
||||
|
@ -1,3 +1,27 @@
|
||||
from langchain_community.docstore.base import AddableMixin, Docstore
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
__all__ = ["Docstore", "AddableMixin"]
|
||||
from langchain._api import create_importer
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain_community.docstore.base import AddableMixin, Docstore
|
||||
|
||||
# Create a way to dynamically look up deprecated imports.
|
||||
# Used to consolidate logic for raising deprecation warnings and
|
||||
# handling optional imports.
|
||||
DEPRECATED_LOOKUP = {
|
||||
"Docstore": "langchain_community.docstore.base",
|
||||
"AddableMixin": "langchain_community.docstore.base",
|
||||
}
|
||||
|
||||
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""Look up attributes dynamically."""
|
||||
return _import_attribute(name)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"Docstore",
|
||||
"AddableMixin",
|
||||
]
|
||||
|
@ -1,3 +1,23 @@
|
||||
from langchain_community.docstore.in_memory import InMemoryDocstore
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
__all__ = ["InMemoryDocstore"]
|
||||
from langchain._api import create_importer
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain_community.docstore.in_memory import InMemoryDocstore
|
||||
|
||||
# Create a way to dynamically look up deprecated imports.
|
||||
# Used to consolidate logic for raising deprecation warnings and
|
||||
# handling optional imports.
|
||||
DEPRECATED_LOOKUP = {"InMemoryDocstore": "langchain_community.docstore.in_memory"}
|
||||
|
||||
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""Look up attributes dynamically."""
|
||||
return _import_attribute(name)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"InMemoryDocstore",
|
||||
]
|
||||
|
@ -1,3 +1,23 @@
|
||||
from langchain_community.docstore.wikipedia import Wikipedia
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
__all__ = ["Wikipedia"]
|
||||
from langchain._api import create_importer
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain_community.docstore.wikipedia import Wikipedia
|
||||
|
||||
# Create a way to dynamically look up deprecated imports.
|
||||
# Used to consolidate logic for raising deprecation warnings and
|
||||
# handling optional imports.
|
||||
DEPRECATED_LOOKUP = {"Wikipedia": "langchain_community.docstore.wikipedia"}
|
||||
|
||||
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""Look up attributes dynamically."""
|
||||
return _import_attribute(name)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"Wikipedia",
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user