diff --git a/.speakeasy/workflow.lock b/.speakeasy/workflow.lock index 4caed8b7..286cf6a9 100644 --- a/.speakeasy/workflow.lock +++ b/.speakeasy/workflow.lock @@ -26,7 +26,7 @@ targets: sourceRevisionDigest: sha256:670c460702ec74f7077491464a6dc5ee9d873969c80e812c48dbf4deb160e470 sourceBlobDigest: sha256:5a3ebfa4cb00a015bb7bb03ec7442fc7e0b9c17ca66ab35d3045290b2ad87eac codeSamplesNamespace: mistral-openapi-azure-code-samples - codeSamplesRevisionDigest: sha256:a4ace4b17dee92b180a2fede7742bd93fa1a83a9f96e4f61531289cafc50f6ad + codeSamplesRevisionDigest: sha256:e6802c97fd9783aa91cc0853de1a889944f699b88e0dafcf9fecd83de6e2c6c9 mistralai-gcp-sdk: source: mistral-google-cloud-source sourceNamespace: mistral-openapi-google-cloud diff --git a/packages/mistralai_azure/.speakeasy/gen.lock b/packages/mistralai_azure/.speakeasy/gen.lock index ef80e828..bce8e3c8 100644 --- a/packages/mistralai_azure/.speakeasy/gen.lock +++ b/packages/mistralai_azure/.speakeasy/gen.lock @@ -165,6 +165,7 @@ generatedFiles: - src/mistralai_azure/models/validationerror.py - src/mistralai_azure/ocr.py - src/mistralai_azure/py.typed + - src/mistralai_azure/sdk.py - src/mistralai_azure/sdkconfiguration.py - src/mistralai_azure/types/__init__.py - src/mistralai_azure/types/basemodel.py diff --git a/packages/mistralai_azure/src/mistralai_azure/sdk.py b/packages/mistralai_azure/src/mistralai_azure/sdk.py index 8379e55f..04bc7743 100644 --- a/packages/mistralai_azure/src/mistralai_azure/sdk.py +++ b/packages/mistralai_azure/src/mistralai_azure/sdk.py @@ -1,27 +1,33 @@ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" -import weakref -from typing import Any, Callable, Dict, Optional, Union, cast - -import httpx - -from mistralai_azure import models, utils -from mistralai_azure._hooks import SDKHooks -from mistralai_azure.chat import Chat -from mistralai_azure.types import UNSET, OptionalNullable - from .basesdk import BaseSDK from .httpclient import AsyncHttpClient, ClientOwner, HttpClient, close_clients from .sdkconfiguration import SDKConfiguration from .utils.logger import Logger, get_default_logger from .utils.retries import RetryConfig +import httpx +import importlib +from mistralai_azure import models, utils +from mistralai_azure._hooks import SDKHooks +from mistralai_azure.types import OptionalNullable, UNSET +from typing import Any, Callable, Dict, Optional, TYPE_CHECKING, Union, cast +import weakref + +if TYPE_CHECKING: + from mistralai_azure.chat import Chat + from mistralai_azure.ocr import Ocr class MistralAzure(BaseSDK): r"""Mistral AI API: Our Chat Completion and Embeddings APIs specification. Create your account on [La Plateforme](https://console.mistral.ai) to get access and read the [docs](https://docs.mistral.ai) to learn how to use it.""" - chat: Chat + chat: "Chat" r"""Chat Completion API.""" + ocr: "Ocr" + _sub_sdk_map = { + "chat": ("mistralai_azure.chat", "Chat"), + "ocr": ("mistralai_azure.ocr", "Ocr"), + } def __init__( self, @@ -101,6 +107,9 @@ def __init__( hooks = SDKHooks() + # pylint: disable=protected-access + self.sdk_configuration.__dict__["_hooks"] = hooks + current_server_url, *_ = self.sdk_configuration.get_server_details() server_url, self.sdk_configuration.client = hooks.sdk_init( current_server_url, client @@ -108,9 +117,6 @@ def __init__( if current_server_url != server_url: self.sdk_configuration.server_url = server_url - # pylint: disable=protected-access - self.sdk_configuration.__dict__["_hooks"] = hooks - weakref.finalize( self, close_clients, @@ -121,10 +127,32 @@ def __init__( self.sdk_configuration.async_client_supplied, ) - self._init_sdks() + def __getattr__(self, name: str): + if name in self._sub_sdk_map: + module_path, class_name = self._sub_sdk_map[name] + try: + module = importlib.import_module(module_path) + klass = getattr(module, class_name) + instance = klass(self.sdk_configuration) + setattr(self, name, instance) + return instance + except ImportError as e: + raise AttributeError( + f"Failed to import module {module_path} for attribute {name}: {e}" + ) from e + except AttributeError as e: + raise AttributeError( + f"Failed to find class {class_name} in module {module_path} for attribute {name}: {e}" + ) from e + + raise AttributeError( + f"'{type(self).__name__}' object has no attribute '{name}'" + ) - def _init_sdks(self): - self.chat = Chat(self.sdk_configuration) + def __dir__(self): + default_attrs = list(super().__dir__()) + lazy_attrs = list(self._sub_sdk_map.keys()) + return sorted(list(set(default_attrs + lazy_attrs))) def __enter__(self): return self