From 57e8e70daad6a66dad1fca0a4e7dd3e6d76036fe Mon Sep 17 00:00:00 2001 From: Eugene Yurtsev Date: Wed, 1 May 2024 16:04:12 -0400 Subject: [PATCH] langchain[patch]: Migrate chat models to optional community imports (#21090) Migrate chat models to optional community imports --- .../langchain/chat_models/anthropic.py | 29 +++++++++++++--- .../langchain/chat_models/anyscale.py | 26 +++++++++++--- .../langchain/chat_models/azure_openai.py | 24 +++++++++++-- .../langchain/chat_models/azureml_endpoint.py | 34 ++++++++++++++++--- .../langchain/chat_models/baichuan.py | 22 ++++++++++-- .../chat_models/baidu_qianfan_endpoint.py | 30 +++++++++++++--- .../langchain/chat_models/bedrock.py | 28 +++++++++++++-- .../langchain/langchain/chat_models/cohere.py | 26 +++++++++++--- .../langchain/chat_models/databricks.py | 24 +++++++++++-- libs/langchain/langchain/chat_models/ernie.py | 24 +++++++++++-- .../langchain/chat_models/everlyai.py | 26 +++++++++++--- libs/langchain/langchain/chat_models/fake.py | 34 ++++++++++++++++--- .../langchain/chat_models/fireworks.py | 22 ++++++++++-- .../langchain/chat_models/gigachat.py | 26 +++++++++++--- .../langchain/chat_models/google_palm.py | 34 ++++++++++++++++--- libs/langchain/langchain/chat_models/human.py | 26 +++++++++++--- .../langchain/chat_models/hunyuan.py | 22 ++++++++++-- .../chat_models/javelin_ai_gateway.py | 34 ++++++++++++++++--- .../langchain/chat_models/jinachat.py | 22 ++++++++++-- libs/langchain/langchain/chat_models/konko.py | 26 +++++++++++--- .../langchain/chat_models/litellm.py | 31 +++++++++++++++-- libs/langchain/langchain/chat_models/meta.py | 28 ++++++++++++--- .../langchain/chat_models/minimax.py | 26 +++++++++++--- .../langchain/langchain/chat_models/mlflow.py | 24 +++++++++++-- .../chat_models/mlflow_ai_gateway.py | 34 ++++++++++++++++--- .../langchain/langchain/chat_models/ollama.py | 26 +++++++++++--- .../langchain/langchain/chat_models/openai.py | 22 ++++++++++-- .../langchain/chat_models/pai_eas_endpoint.py | 26 ++++++++++++-- .../chat_models/promptlayer_openai.py | 26 ++++++++++++-- .../langchain/langchain/chat_models/tongyi.py | 22 ++++++++++-- .../langchain/chat_models/vertexai.py | 22 ++++++++++-- .../langchain/chat_models/volcengine_maas.py | 34 ++++++++++++++++--- .../langchain/langchain/chat_models/yandex.py | 26 +++++++++++--- 33 files changed, 771 insertions(+), 115 deletions(-) diff --git a/libs/langchain/langchain/chat_models/anthropic.py b/libs/langchain/langchain/chat_models/anthropic.py index 2a1f287ffd9..aa925896172 100644 --- a/libs/langchain/langchain/chat_models/anthropic.py +++ b/libs/langchain/langchain/chat_models/anthropic.py @@ -1,7 +1,28 @@ -from langchain_community.chat_models.anthropic import ( - ChatAnthropic, - convert_messages_to_prompt_anthropic, -) +from typing import TYPE_CHECKING, Any + +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.anthropic import ( + ChatAnthropic, + convert_messages_to_prompt_anthropic, + ) + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = { + "convert_messages_to_prompt_anthropic": "langchain_community.chat_models.anthropic", + "ChatAnthropic": "langchain_community.chat_models.anthropic", +} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + __all__ = [ "convert_messages_to_prompt_anthropic", diff --git a/libs/langchain/langchain/chat_models/anyscale.py b/libs/langchain/langchain/chat_models/anyscale.py index d49021b4cbc..279b3be8539 100644 --- a/libs/langchain/langchain/chat_models/anyscale.py +++ b/libs/langchain/langchain/chat_models/anyscale.py @@ -1,5 +1,23 @@ -from langchain_community.chat_models.anyscale import ( - ChatAnyscale, -) +from typing import TYPE_CHECKING, Any -__all__ = ["ChatAnyscale"] +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.anyscale import ChatAnyscale + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = {"ChatAnyscale": "langchain_community.chat_models.anyscale"} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + + +__all__ = [ + "ChatAnyscale", +] diff --git a/libs/langchain/langchain/chat_models/azure_openai.py b/libs/langchain/langchain/chat_models/azure_openai.py index 42380cd0e5a..93441c7e49d 100644 --- a/libs/langchain/langchain/chat_models/azure_openai.py +++ b/libs/langchain/langchain/chat_models/azure_openai.py @@ -1,3 +1,23 @@ -from langchain_community.chat_models.azure_openai import AzureChatOpenAI +from typing import TYPE_CHECKING, Any -__all__ = ["AzureChatOpenAI"] +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.azure_openai import AzureChatOpenAI + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = {"AzureChatOpenAI": "langchain_community.chat_models.azure_openai"} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + + +__all__ = [ + "AzureChatOpenAI", +] diff --git a/libs/langchain/langchain/chat_models/azureml_endpoint.py b/libs/langchain/langchain/chat_models/azureml_endpoint.py index 4acdfad01f5..ebcc0fdccd3 100644 --- a/libs/langchain/langchain/chat_models/azureml_endpoint.py +++ b/libs/langchain/langchain/chat_models/azureml_endpoint.py @@ -1,6 +1,30 @@ -from langchain_community.chat_models.azureml_endpoint import ( - AzureMLChatOnlineEndpoint, - LlamaContentFormatter, -) +from typing import TYPE_CHECKING, Any -__all__ = ["LlamaContentFormatter", "AzureMLChatOnlineEndpoint"] +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.azureml_endpoint import ( + AzureMLChatOnlineEndpoint, + LlamaContentFormatter, + ) + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = { + "LlamaContentFormatter": "langchain_community.chat_models.azureml_endpoint", + "AzureMLChatOnlineEndpoint": "langchain_community.chat_models.azureml_endpoint", +} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + + +__all__ = [ + "LlamaContentFormatter", + "AzureMLChatOnlineEndpoint", +] diff --git a/libs/langchain/langchain/chat_models/baichuan.py b/libs/langchain/langchain/chat_models/baichuan.py index 44488581931..bee1ba3f5f3 100644 --- a/libs/langchain/langchain/chat_models/baichuan.py +++ b/libs/langchain/langchain/chat_models/baichuan.py @@ -1,6 +1,22 @@ -from langchain_community.chat_models.baichuan import ( - ChatBaichuan, -) +from typing import TYPE_CHECKING, Any + +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.baichuan import ChatBaichuan + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = {"ChatBaichuan": "langchain_community.chat_models.baichuan"} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + __all__ = [ "ChatBaichuan", diff --git a/libs/langchain/langchain/chat_models/baidu_qianfan_endpoint.py b/libs/langchain/langchain/chat_models/baidu_qianfan_endpoint.py index ba3a023ec8a..e9db4d9bc6c 100644 --- a/libs/langchain/langchain/chat_models/baidu_qianfan_endpoint.py +++ b/libs/langchain/langchain/chat_models/baidu_qianfan_endpoint.py @@ -1,5 +1,27 @@ -from langchain_community.chat_models.baidu_qianfan_endpoint import ( - QianfanChatEndpoint, -) +from typing import TYPE_CHECKING, Any -__all__ = ["QianfanChatEndpoint"] +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.baidu_qianfan_endpoint import ( + QianfanChatEndpoint, + ) + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = { + "QianfanChatEndpoint": "langchain_community.chat_models.baidu_qianfan_endpoint" +} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + + +__all__ = [ + "QianfanChatEndpoint", +] diff --git a/libs/langchain/langchain/chat_models/bedrock.py b/libs/langchain/langchain/chat_models/bedrock.py index 4b0f49a1474..d2d28172846 100644 --- a/libs/langchain/langchain/chat_models/bedrock.py +++ b/libs/langchain/langchain/chat_models/bedrock.py @@ -1,3 +1,27 @@ -from langchain_community.chat_models.bedrock import BedrockChat, ChatPromptAdapter +from typing import TYPE_CHECKING, Any -__all__ = ["ChatPromptAdapter", "BedrockChat"] +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.bedrock import BedrockChat, ChatPromptAdapter + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = { + "ChatPromptAdapter": "langchain_community.chat_models.bedrock", + "BedrockChat": "langchain_community.chat_models.bedrock", +} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + + +__all__ = [ + "ChatPromptAdapter", + "BedrockChat", +] diff --git a/libs/langchain/langchain/chat_models/cohere.py b/libs/langchain/langchain/chat_models/cohere.py index 63cbc46711e..b43df81d438 100644 --- a/libs/langchain/langchain/chat_models/cohere.py +++ b/libs/langchain/langchain/chat_models/cohere.py @@ -1,5 +1,23 @@ -from langchain_community.chat_models.cohere import ( - ChatCohere, -) +from typing import TYPE_CHECKING, Any -__all__ = ["ChatCohere"] +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.cohere import ChatCohere + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = {"ChatCohere": "langchain_community.chat_models.cohere"} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + + +__all__ = [ + "ChatCohere", +] diff --git a/libs/langchain/langchain/chat_models/databricks.py b/libs/langchain/langchain/chat_models/databricks.py index b73d49b04ba..58dc3f3b75f 100644 --- a/libs/langchain/langchain/chat_models/databricks.py +++ b/libs/langchain/langchain/chat_models/databricks.py @@ -1,3 +1,23 @@ -from langchain_community.chat_models.databricks import ChatDatabricks +from typing import TYPE_CHECKING, Any -__all__ = ["ChatDatabricks"] +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.databricks import ChatDatabricks + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = {"ChatDatabricks": "langchain_community.chat_models.databricks"} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + + +__all__ = [ + "ChatDatabricks", +] diff --git a/libs/langchain/langchain/chat_models/ernie.py b/libs/langchain/langchain/chat_models/ernie.py index 6dbdb34e072..284af4a62c3 100644 --- a/libs/langchain/langchain/chat_models/ernie.py +++ b/libs/langchain/langchain/chat_models/ernie.py @@ -1,3 +1,23 @@ -from langchain_community.chat_models.ernie import ErnieBotChat +from typing import TYPE_CHECKING, Any -__all__ = ["ErnieBotChat"] +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.ernie import ErnieBotChat + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = {"ErnieBotChat": "langchain_community.chat_models.ernie"} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + + +__all__ = [ + "ErnieBotChat", +] diff --git a/libs/langchain/langchain/chat_models/everlyai.py b/libs/langchain/langchain/chat_models/everlyai.py index edeeea78ea8..87c11debf53 100644 --- a/libs/langchain/langchain/chat_models/everlyai.py +++ b/libs/langchain/langchain/chat_models/everlyai.py @@ -1,5 +1,23 @@ -from langchain_community.chat_models.everlyai import ( - ChatEverlyAI, -) +from typing import TYPE_CHECKING, Any -__all__ = ["ChatEverlyAI"] +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.everlyai import ChatEverlyAI + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = {"ChatEverlyAI": "langchain_community.chat_models.everlyai"} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + + +__all__ = [ + "ChatEverlyAI", +] diff --git a/libs/langchain/langchain/chat_models/fake.py b/libs/langchain/langchain/chat_models/fake.py index 24c98e115d5..261d5fa5f3f 100644 --- a/libs/langchain/langchain/chat_models/fake.py +++ b/libs/langchain/langchain/chat_models/fake.py @@ -1,6 +1,30 @@ -from langchain_community.chat_models.fake import ( - FakeListChatModel, - FakeMessagesListChatModel, -) +from typing import TYPE_CHECKING, Any -__all__ = ["FakeMessagesListChatModel", "FakeListChatModel"] +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.fake import ( + FakeListChatModel, + FakeMessagesListChatModel, + ) + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = { + "FakeMessagesListChatModel": "langchain_community.chat_models.fake", + "FakeListChatModel": "langchain_community.chat_models.fake", +} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + + +__all__ = [ + "FakeMessagesListChatModel", + "FakeListChatModel", +] diff --git a/libs/langchain/langchain/chat_models/fireworks.py b/libs/langchain/langchain/chat_models/fireworks.py index 0e5fd2cefcb..a3908b2a876 100644 --- a/libs/langchain/langchain/chat_models/fireworks.py +++ b/libs/langchain/langchain/chat_models/fireworks.py @@ -1,6 +1,22 @@ -from langchain_community.chat_models.fireworks import ( - ChatFireworks, -) +from typing import TYPE_CHECKING, Any + +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.fireworks import ChatFireworks + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = {"ChatFireworks": "langchain_community.chat_models.fireworks"} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + __all__ = [ "ChatFireworks", diff --git a/libs/langchain/langchain/chat_models/gigachat.py b/libs/langchain/langchain/chat_models/gigachat.py index 9dff7f28eba..a59eda70b01 100644 --- a/libs/langchain/langchain/chat_models/gigachat.py +++ b/libs/langchain/langchain/chat_models/gigachat.py @@ -1,5 +1,23 @@ -from langchain_community.chat_models.gigachat import ( - GigaChat, -) +from typing import TYPE_CHECKING, Any -__all__ = ["GigaChat"] +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.gigachat import GigaChat + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = {"GigaChat": "langchain_community.chat_models.gigachat"} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + + +__all__ = [ + "GigaChat", +] diff --git a/libs/langchain/langchain/chat_models/google_palm.py b/libs/langchain/langchain/chat_models/google_palm.py index 6acab6dee73..e9bb012c2b6 100644 --- a/libs/langchain/langchain/chat_models/google_palm.py +++ b/libs/langchain/langchain/chat_models/google_palm.py @@ -1,6 +1,30 @@ -from langchain_community.chat_models.google_palm import ( - ChatGooglePalm, - ChatGooglePalmError, -) +from typing import TYPE_CHECKING, Any -__all__ = ["ChatGooglePalm", "ChatGooglePalmError"] +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.google_palm import ( + ChatGooglePalm, + ChatGooglePalmError, + ) + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = { + "ChatGooglePalm": "langchain_community.chat_models.google_palm", + "ChatGooglePalmError": "langchain_community.chat_models.google_palm", +} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + + +__all__ = [ + "ChatGooglePalm", + "ChatGooglePalmError", +] diff --git a/libs/langchain/langchain/chat_models/human.py b/libs/langchain/langchain/chat_models/human.py index 2b7448ca91f..e3752193b3c 100644 --- a/libs/langchain/langchain/chat_models/human.py +++ b/libs/langchain/langchain/chat_models/human.py @@ -1,5 +1,23 @@ -from langchain_community.chat_models.human import ( - HumanInputChatModel, -) +from typing import TYPE_CHECKING, Any -__all__ = ["HumanInputChatModel"] +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.human import HumanInputChatModel + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = {"HumanInputChatModel": "langchain_community.chat_models.human"} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + + +__all__ = [ + "HumanInputChatModel", +] diff --git a/libs/langchain/langchain/chat_models/hunyuan.py b/libs/langchain/langchain/chat_models/hunyuan.py index a5a7d121ae9..53fe84548d8 100644 --- a/libs/langchain/langchain/chat_models/hunyuan.py +++ b/libs/langchain/langchain/chat_models/hunyuan.py @@ -1,6 +1,22 @@ -from langchain_community.chat_models.hunyuan import ( - ChatHunyuan, -) +from typing import TYPE_CHECKING, Any + +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.hunyuan import ChatHunyuan + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = {"ChatHunyuan": "langchain_community.chat_models.hunyuan"} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + __all__ = [ "ChatHunyuan", diff --git a/libs/langchain/langchain/chat_models/javelin_ai_gateway.py b/libs/langchain/langchain/chat_models/javelin_ai_gateway.py index 131e3c33a8e..0f89edbdf1b 100644 --- a/libs/langchain/langchain/chat_models/javelin_ai_gateway.py +++ b/libs/langchain/langchain/chat_models/javelin_ai_gateway.py @@ -1,6 +1,30 @@ -from langchain_community.chat_models.javelin_ai_gateway import ( - ChatJavelinAIGateway, - ChatParams, -) +from typing import TYPE_CHECKING, Any -__all__ = ["ChatJavelinAIGateway", "ChatParams"] +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.javelin_ai_gateway import ( + ChatJavelinAIGateway, + ChatParams, + ) + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = { + "ChatJavelinAIGateway": "langchain_community.chat_models.javelin_ai_gateway", + "ChatParams": "langchain_community.chat_models.javelin_ai_gateway", +} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + + +__all__ = [ + "ChatJavelinAIGateway", + "ChatParams", +] diff --git a/libs/langchain/langchain/chat_models/jinachat.py b/libs/langchain/langchain/chat_models/jinachat.py index 816dfa55c52..dba660e1999 100644 --- a/libs/langchain/langchain/chat_models/jinachat.py +++ b/libs/langchain/langchain/chat_models/jinachat.py @@ -1,6 +1,22 @@ -from langchain_community.chat_models.jinachat import ( - JinaChat, -) +from typing import TYPE_CHECKING, Any + +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.jinachat import JinaChat + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = {"JinaChat": "langchain_community.chat_models.jinachat"} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + __all__ = [ "JinaChat", diff --git a/libs/langchain/langchain/chat_models/konko.py b/libs/langchain/langchain/chat_models/konko.py index 4f7d5c2cb7b..fd5ba7c4502 100644 --- a/libs/langchain/langchain/chat_models/konko.py +++ b/libs/langchain/langchain/chat_models/konko.py @@ -1,5 +1,23 @@ -from langchain_community.chat_models.konko import ( - ChatKonko, -) +from typing import TYPE_CHECKING, Any -__all__ = ["ChatKonko"] +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.konko import ChatKonko + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = {"ChatKonko": "langchain_community.chat_models.konko"} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + + +__all__ = [ + "ChatKonko", +] diff --git a/libs/langchain/langchain/chat_models/litellm.py b/libs/langchain/langchain/chat_models/litellm.py index 87e4ad7347d..69ebcd91635 100644 --- a/libs/langchain/langchain/chat_models/litellm.py +++ b/libs/langchain/langchain/chat_models/litellm.py @@ -1,3 +1,30 @@ -from langchain_community.chat_models.litellm import ChatLiteLLM, ChatLiteLLMException +from typing import TYPE_CHECKING, Any -__all__ = ["ChatLiteLLM", "ChatLiteLLMException"] +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.litellm import ( + ChatLiteLLM, + ChatLiteLLMException, + ) + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = { + "ChatLiteLLM": "langchain_community.chat_models.litellm", + "ChatLiteLLMException": "langchain_community.chat_models.litellm", +} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + + +__all__ = [ + "ChatLiteLLM", + "ChatLiteLLMException", +] diff --git a/libs/langchain/langchain/chat_models/meta.py b/libs/langchain/langchain/chat_models/meta.py index 5284601ff38..22fa97e08c4 100644 --- a/libs/langchain/langchain/chat_models/meta.py +++ b/libs/langchain/langchain/chat_models/meta.py @@ -1,5 +1,25 @@ -from langchain_community.chat_models.meta import ( - convert_messages_to_prompt_llama, -) +from typing import TYPE_CHECKING, Any -__all__ = ["convert_messages_to_prompt_llama"] +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.meta import convert_messages_to_prompt_llama + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = { + "convert_messages_to_prompt_llama": "langchain_community.chat_models.meta" +} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + + +__all__ = [ + "convert_messages_to_prompt_llama", +] diff --git a/libs/langchain/langchain/chat_models/minimax.py b/libs/langchain/langchain/chat_models/minimax.py index 7363e27fee7..3c4f791b5b4 100644 --- a/libs/langchain/langchain/chat_models/minimax.py +++ b/libs/langchain/langchain/chat_models/minimax.py @@ -1,5 +1,23 @@ -from langchain_community.chat_models.minimax import ( - MiniMaxChat, -) +from typing import TYPE_CHECKING, Any -__all__ = ["MiniMaxChat"] +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.minimax import MiniMaxChat + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = {"MiniMaxChat": "langchain_community.chat_models.minimax"} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + + +__all__ = [ + "MiniMaxChat", +] diff --git a/libs/langchain/langchain/chat_models/mlflow.py b/libs/langchain/langchain/chat_models/mlflow.py index 380b9505b1d..3877e8b98ad 100644 --- a/libs/langchain/langchain/chat_models/mlflow.py +++ b/libs/langchain/langchain/chat_models/mlflow.py @@ -1,3 +1,23 @@ -from langchain_community.chat_models.mlflow import ChatMlflow +from typing import TYPE_CHECKING, Any -__all__ = ["ChatMlflow"] +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.mlflow import ChatMlflow + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = {"ChatMlflow": "langchain_community.chat_models.mlflow"} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + + +__all__ = [ + "ChatMlflow", +] diff --git a/libs/langchain/langchain/chat_models/mlflow_ai_gateway.py b/libs/langchain/langchain/chat_models/mlflow_ai_gateway.py index 101edb7a776..2e54df8cda4 100644 --- a/libs/langchain/langchain/chat_models/mlflow_ai_gateway.py +++ b/libs/langchain/langchain/chat_models/mlflow_ai_gateway.py @@ -1,6 +1,30 @@ -from langchain_community.chat_models.mlflow_ai_gateway import ( - ChatMLflowAIGateway, - ChatParams, -) +from typing import TYPE_CHECKING, Any -__all__ = ["ChatMLflowAIGateway", "ChatParams"] +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.mlflow_ai_gateway import ( + ChatMLflowAIGateway, + ChatParams, + ) + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = { + "ChatMLflowAIGateway": "langchain_community.chat_models.mlflow_ai_gateway", + "ChatParams": "langchain_community.chat_models.mlflow_ai_gateway", +} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + + +__all__ = [ + "ChatMLflowAIGateway", + "ChatParams", +] diff --git a/libs/langchain/langchain/chat_models/ollama.py b/libs/langchain/langchain/chat_models/ollama.py index ff872b8c6b8..d5a9d3f6b58 100644 --- a/libs/langchain/langchain/chat_models/ollama.py +++ b/libs/langchain/langchain/chat_models/ollama.py @@ -1,5 +1,23 @@ -from langchain_community.chat_models.ollama import ( - ChatOllama, -) +from typing import TYPE_CHECKING, Any -__all__ = ["ChatOllama"] +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.ollama import ChatOllama + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = {"ChatOllama": "langchain_community.chat_models.ollama"} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + + +__all__ = [ + "ChatOllama", +] diff --git a/libs/langchain/langchain/chat_models/openai.py b/libs/langchain/langchain/chat_models/openai.py index 18922fd22b1..76482f221ec 100644 --- a/libs/langchain/langchain/chat_models/openai.py +++ b/libs/langchain/langchain/chat_models/openai.py @@ -1,6 +1,22 @@ -from langchain_community.chat_models.openai import ( - ChatOpenAI, -) +from typing import TYPE_CHECKING, Any + +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.openai import ChatOpenAI + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = {"ChatOpenAI": "langchain_community.chat_models.openai"} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + __all__ = [ "ChatOpenAI", diff --git a/libs/langchain/langchain/chat_models/pai_eas_endpoint.py b/libs/langchain/langchain/chat_models/pai_eas_endpoint.py index 14b2fd4e742..2c3134f63e6 100644 --- a/libs/langchain/langchain/chat_models/pai_eas_endpoint.py +++ b/libs/langchain/langchain/chat_models/pai_eas_endpoint.py @@ -1,3 +1,25 @@ -from langchain_community.chat_models.pai_eas_endpoint import PaiEasChatEndpoint +from typing import TYPE_CHECKING, Any -__all__ = ["PaiEasChatEndpoint"] +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.pai_eas_endpoint import PaiEasChatEndpoint + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = { + "PaiEasChatEndpoint": "langchain_community.chat_models.pai_eas_endpoint" +} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + + +__all__ = [ + "PaiEasChatEndpoint", +] diff --git a/libs/langchain/langchain/chat_models/promptlayer_openai.py b/libs/langchain/langchain/chat_models/promptlayer_openai.py index cceb5702cd9..b7a3bb0ddf1 100644 --- a/libs/langchain/langchain/chat_models/promptlayer_openai.py +++ b/libs/langchain/langchain/chat_models/promptlayer_openai.py @@ -1,3 +1,25 @@ -from langchain_community.chat_models.promptlayer_openai import PromptLayerChatOpenAI +from typing import TYPE_CHECKING, Any -__all__ = ["PromptLayerChatOpenAI"] +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.promptlayer_openai import PromptLayerChatOpenAI + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = { + "PromptLayerChatOpenAI": "langchain_community.chat_models.promptlayer_openai" +} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + + +__all__ = [ + "PromptLayerChatOpenAI", +] diff --git a/libs/langchain/langchain/chat_models/tongyi.py b/libs/langchain/langchain/chat_models/tongyi.py index 6ee9bc4f625..bb24bef3880 100644 --- a/libs/langchain/langchain/chat_models/tongyi.py +++ b/libs/langchain/langchain/chat_models/tongyi.py @@ -1,6 +1,22 @@ -from langchain_community.chat_models.tongyi import ( - ChatTongyi, -) +from typing import TYPE_CHECKING, Any + +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.tongyi import ChatTongyi + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = {"ChatTongyi": "langchain_community.chat_models.tongyi"} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + __all__ = [ "ChatTongyi", diff --git a/libs/langchain/langchain/chat_models/vertexai.py b/libs/langchain/langchain/chat_models/vertexai.py index a5096fcce81..b662a337ab2 100644 --- a/libs/langchain/langchain/chat_models/vertexai.py +++ b/libs/langchain/langchain/chat_models/vertexai.py @@ -1,6 +1,22 @@ -from langchain_community.chat_models.vertexai import ( - ChatVertexAI, -) +from typing import TYPE_CHECKING, Any + +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.vertexai import ChatVertexAI + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = {"ChatVertexAI": "langchain_community.chat_models.vertexai"} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + __all__ = [ "ChatVertexAI", diff --git a/libs/langchain/langchain/chat_models/volcengine_maas.py b/libs/langchain/langchain/chat_models/volcengine_maas.py index b6628ef1aed..9c4571140c2 100644 --- a/libs/langchain/langchain/chat_models/volcengine_maas.py +++ b/libs/langchain/langchain/chat_models/volcengine_maas.py @@ -1,6 +1,30 @@ -from langchain_community.chat_models.volcengine_maas import ( - VolcEngineMaasChat, - convert_dict_to_message, -) +from typing import TYPE_CHECKING, Any -__all__ = ["convert_dict_to_message", "VolcEngineMaasChat"] +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.volcengine_maas import ( + VolcEngineMaasChat, + convert_dict_to_message, + ) + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = { + "convert_dict_to_message": "langchain_community.chat_models.volcengine_maas", + "VolcEngineMaasChat": "langchain_community.chat_models.volcengine_maas", +} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + + +__all__ = [ + "convert_dict_to_message", + "VolcEngineMaasChat", +] diff --git a/libs/langchain/langchain/chat_models/yandex.py b/libs/langchain/langchain/chat_models/yandex.py index 05cb4cbea5d..af2a4402930 100644 --- a/libs/langchain/langchain/chat_models/yandex.py +++ b/libs/langchain/langchain/chat_models/yandex.py @@ -1,5 +1,23 @@ -from langchain_community.chat_models.yandex import ( - ChatYandexGPT, -) +from typing import TYPE_CHECKING, Any -__all__ = ["ChatYandexGPT"] +from langchain._api import create_importer + +if TYPE_CHECKING: + from langchain_community.chat_models.yandex import ChatYandexGPT + +# Create a way to dynamically look up deprecated imports. +# Used to consolidate logic for raising deprecation warnings and +# handling optional imports. +DEPRECATED_LOOKUP = {"ChatYandexGPT": "langchain_community.chat_models.yandex"} + +_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP) + + +def __getattr__(name: str) -> Any: + """Look up attributes dynamically.""" + return _import_attribute(name) + + +__all__ = [ + "ChatYandexGPT", +]