From 745e3e29dac89da7d48d973dcc258eafcc2cd22c Mon Sep 17 00:00:00 2001 From: Erick Friis Date: Tue, 3 Oct 2023 14:34:30 -0700 Subject: [PATCH] add getattr case for llms.type_to_cls_dict (#11362) For external libraries that depend on `type_to_cls_dict`, adds a workaround to continue using the old format. Recommend people use `get_type_to_cls_dict()` instead and only resolve the imports when they're used. --- libs/langchain/langchain/llms/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libs/langchain/langchain/llms/__init__.py b/libs/langchain/langchain/llms/__init__.py index 4ef57fbbf3..de577c7064 100644 --- a/libs/langchain/langchain/llms/__init__.py +++ b/libs/langchain/langchain/llms/__init__.py @@ -617,6 +617,12 @@ def __getattr__(name: str) -> Any: return _import_writer() elif name == "Xinference": return _import_xinference() + elif name == "type_to_cls_dict": + # for backwards compatibility + type_to_cls_dict: Dict[str, Type[BaseLLM]] = { + k: v() for k, v in get_type_to_cls_dict().items() + } + return type_to_cls_dict else: raise AttributeError(f"Could not find: {name}")