Skip to content

Commit

Permalink
feat: More robust imports
Browse files Browse the repository at this point in the history
  • Loading branch information
asafgardin committed Dec 17, 2023
1 parent c8057d9 commit 29c24e0
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions ai21/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from ai21.clients.bedrock.ai21_bedrock_client import AI21BedrockClient
from ai21.clients.bedrock.bedrock_model_id import BedrockModelID
from ai21.clients.sagemaker.ai21_sagemaker_client import AI21SageMakerClient
from typing import Any

from ai21.clients.studio.ai21_client import AI21Client
from ai21.resources.responses.answer_response import AnswerResponse
from ai21.resources.responses.chat_response import ChatResponse
Expand All @@ -22,6 +21,38 @@

__version__ = VERSION


def _import_bedrock_client():
from ai21.clients.bedrock.ai21_bedrock_client import AI21BedrockClient

return AI21BedrockClient


def _import_sagemaker_client():
from ai21.clients.sagemaker.ai21_sagemaker_client import AI21SageMakerClient

return AI21SageMakerClient


def _import_bedrock_model_id():
from ai21.clients.bedrock.bedrock_model_id import BedrockModelID

return BedrockModelID


def __getattr__(name: str) -> Any:
if name == "AI21BedrockClient":
return _import_bedrock_client()

if name == "AI21SageMakerClient":
return _import_sagemaker_client()

if name == "BedrockModelID":
return _import_bedrock_model_id()

raise AttributeError(f"Could not import: {name}")


__all__ = [
"AI21Client",
"AI21BedrockClient",
Expand Down

0 comments on commit 29c24e0

Please sign in to comment.