From 2860b9b6a78fb8323d15979f65b1e40b72781e1d Mon Sep 17 00:00:00 2001 From: Rajendra Kadam Date: Fri, 10 May 2024 23:39:59 +0530 Subject: [PATCH] Speed up chain import times --- .../langchain_community/chains/__init__.py | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/libs/community/langchain_community/chains/__init__.py b/libs/community/langchain_community/chains/__init__.py index 860bbf678b1b4..dda2a19aaf2ad 100644 --- a/libs/community/langchain_community/chains/__init__.py +++ b/libs/community/langchain_community/chains/__init__.py @@ -4,6 +4,24 @@ This module contains the community chains. """ -from langchain_community.chains.pebblo_retrieval.base import PebbloRetrievalQA +import importlib +from typing import TYPE_CHECKING, Any + +if TYPE_CHECKING: + from langchain_community.chains.pebblo_retrieval.base import PebbloRetrievalQA __all__ = ["PebbloRetrievalQA"] + +_module_lookup = { + "PebbloRetrievalQA": "langchain_community.chains.pebblo_retrieval.base" +} + + +def __getattr__(name: str) -> Any: + if name in _module_lookup: + module = importlib.import_module(_module_lookup[name]) + return getattr(module, name) + raise AttributeError(f"module {__name__} has no attribute {name}") + + +__all__ = list(_module_lookup.keys())