diff --git a/libs/langchain/langchain/cache.py b/libs/langchain/langchain/cache.py index 7d84971d16..e8cee3c8cd 100644 --- a/libs/langchain/langchain/cache.py +++ b/libs/langchain/langchain/cache.py @@ -1,21 +1,56 @@ -from langchain_community.cache import ( - AstraDBCache, - AstraDBSemanticCache, - AzureCosmosDBSemanticCache, - CassandraCache, - CassandraSemanticCache, - FullLLMCache, - FullMd5LLMCache, - GPTCache, - InMemoryCache, - MomentoCache, - RedisCache, - RedisSemanticCache, - SQLAlchemyCache, - SQLAlchemyMd5Cache, - SQLiteCache, - UpstashRedisCache, -) +from typing import TYPE_CHECKING, Any + +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.cache import ( + AstraDBCache, + AstraDBSemanticCache, + AzureCosmosDBSemanticCache, + CassandraCache, + CassandraSemanticCache, + FullLLMCache, + FullMd5LLMCache, + GPTCache, + InMemoryCache, + MomentoCache, + RedisCache, + RedisSemanticCache, + SQLAlchemyCache, + SQLAlchemyMd5Cache, + SQLiteCache, + UpstashRedisCache, + ) + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = { + "FullLLMCache": "langchain_community.cache", + "SQLAlchemyCache": "langchain_community.cache", + "SQLiteCache": "langchain_community.cache", + "UpstashRedisCache": "langchain_community.cache", + "RedisCache": "langchain_community.cache", + "RedisSemanticCache": "langchain_community.cache", + "GPTCache": "langchain_community.cache", + "MomentoCache": "langchain_community.cache", + "InMemoryCache": "langchain_community.cache", + "CassandraCache": "langchain_community.cache", + "CassandraSemanticCache": "langchain_community.cache", + "FullMd5LLMCache": "langchain_community.cache", + "SQLAlchemyMd5Cache": "langchain_community.cache", + "AstraDBCache": "langchain_community.cache", + "AstraDBSemanticCache": "langchain_community.cache", + "AzureCosmosDBSemanticCache": "langchain_community.cache", +} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + __all__ = [ "FullLLMCache", diff --git a/libs/langchain/langchain/requests.py b/libs/langchain/langchain/requests.py index f848efbf7c..990796018b 100644 --- a/libs/langchain/langchain/requests.py +++ b/libs/langchain/langchain/requests.py @@ -1,5 +1,31 @@ """DEPRECATED: Kept for backwards compatibility.""" -from langchain_community.utilities import Requests, RequestsWrapper, TextRequestsWrapper +from typing import TYPE_CHECKING, Any + +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.utilities import ( + Requests, + RequestsWrapper, + TextRequestsWrapper, + ) + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = { + "Requests": "langchain_community.utilities", + "RequestsWrapper": "langchain_community.utilities", + "TextRequestsWrapper": "langchain_community.utilities", +} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + __all__ = [ "Requests", diff --git a/libs/langchain/langchain/serpapi.py b/libs/langchain/langchain/serpapi.py index 3b3dd24885..03a28d08e5 100644 --- a/libs/langchain/langchain/serpapi.py +++ b/libs/langchain/langchain/serpapi.py @@ -1,4 +1,24 @@ """For backwards compatibility.""" -from langchain_community.utilities.serpapi import SerpAPIWrapper +from typing import TYPE_CHECKING, Any -__all__ = ["SerpAPIWrapper"] +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.utilities import SerpAPIWrapper + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = {"SerpAPIWrapper": "langchain_community.utilities"} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + + +__all__ = [ + "SerpAPIWrapper", +] diff --git a/libs/langchain/langchain/sql_database.py b/libs/langchain/langchain/sql_database.py index a1de4ade2a..e7379f7db6 100644 --- a/libs/langchain/langchain/sql_database.py +++ b/libs/langchain/langchain/sql_database.py @@ -1,4 +1,24 @@ """Keep here for backwards compatibility.""" -from langchain_community.utilities.sql_database import SQLDatabase +from typing import TYPE_CHECKING, Any -__all__ = ["SQLDatabase"] +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.utilities import SQLDatabase + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = {"SQLDatabase": "langchain_community.utilities"} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + + +__all__ = [ + "SQLDatabase", +]