diff --git a/python/packages/autogen-ext/src/autogen_ext/models/anthropic/__init__.py b/python/packages/autogen-ext/src/autogen_ext/models/anthropic/__init__.py index f31e7b1c0b72..cdc41ab751d2 100644 --- a/python/packages/autogen-ext/src/autogen_ext/models/anthropic/__init__.py +++ b/python/packages/autogen-ext/src/autogen_ext/models/anthropic/__init__.py @@ -1,8 +1,3 @@ -from ._anthropic_client import ( - AnthropicBedrockChatCompletionClient, - AnthropicChatCompletionClient, - BaseAnthropicChatCompletionClient, -) from .config import ( AnthropicBedrockClientConfiguration, AnthropicBedrockClientConfigurationConfigModel, @@ -12,6 +7,21 @@ CreateArgumentsConfigModel, ) +try: + from ._anthropic_client import ( + AnthropicBedrockChatCompletionClient, + AnthropicChatCompletionClient, + BaseAnthropicChatCompletionClient, + ) +except ImportError as e: # pragma: no cover - only triggered when optional deps are missing + raise ImportError( + "Failed to import Anthropic dependencies required for AnthropicChatCompletionClient " + "and AnthropicBedrockChatCompletionClient.\n" + f"Original error: {e}\n" + "Required packages (installed via the 'anthropic' extra):\n" + ' pip install "autogen-ext[anthropic]"' + ) from e + __all__ = [ "AnthropicChatCompletionClient", "AnthropicBedrockChatCompletionClient", diff --git a/python/packages/autogen-ext/src/autogen_ext/models/azure/__init__.py b/python/packages/autogen-ext/src/autogen_ext/models/azure/__init__.py index 2dc7b9c70a98..cf015c969685 100644 --- a/python/packages/autogen-ext/src/autogen_ext/models/azure/__init__.py +++ b/python/packages/autogen-ext/src/autogen_ext/models/azure/__init__.py @@ -1,4 +1,12 @@ -from ._azure_ai_client import AzureAIChatCompletionClient -from .config import AzureAIChatCompletionClientConfig +try: + from ._azure_ai_client import AzureAIChatCompletionClient + from .config import AzureAIChatCompletionClientConfig +except ImportError as e: # pragma: no cover - only triggered when optional deps are missing + raise ImportError( + "Failed to import Azure AI dependencies required for AzureAIChatCompletionClient.\n" + f"Original error: {e}\n" + "Required packages (installed via the 'azure' extra):\n" + ' pip install "autogen-ext[azure]"' + ) from e __all__ = ["AzureAIChatCompletionClient", "AzureAIChatCompletionClientConfig"] diff --git a/python/packages/autogen-ext/src/autogen_ext/models/openai/__init__.py b/python/packages/autogen-ext/src/autogen_ext/models/openai/__init__.py index 2241f663af26..d3638dd2ad06 100644 --- a/python/packages/autogen-ext/src/autogen_ext/models/openai/__init__.py +++ b/python/packages/autogen-ext/src/autogen_ext/models/openai/__init__.py @@ -1,10 +1,21 @@ from . import _message_transform -from ._openai_client import ( - AZURE_OPENAI_USER_AGENT, - AzureOpenAIChatCompletionClient, - BaseOpenAIChatCompletionClient, - OpenAIChatCompletionClient, -) + +try: + from ._openai_client import ( + AZURE_OPENAI_USER_AGENT, + AzureOpenAIChatCompletionClient, + BaseOpenAIChatCompletionClient, + OpenAIChatCompletionClient, + ) +except ImportError as e: # pragma: no cover - only triggered when optional deps are missing + raise ImportError( + "Failed to import OpenAI dependencies required for OpenAIChatCompletionClient " + "and AzureOpenAIChatCompletionClient.\n" + f"Original error: {e}\n" + "Required packages (installed via the 'openai' extra):\n" + ' pip install "autogen-ext[openai]"' + ) from e + from .config import ( AzureOpenAIClientConfigurationConfigModel, BaseOpenAIClientConfigurationConfigModel,