11"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
22
3- import weakref
4- from typing import Any , Callable , Dict , Optional , Union , cast
5-
6- import httpx
7-
8- from mistralai_azure import models , utils
9- from mistralai_azure ._hooks import SDKHooks
10- from mistralai_azure .chat import Chat
11- from mistralai_azure .types import UNSET , OptionalNullable
12-
133from .basesdk import BaseSDK
144from .httpclient import AsyncHttpClient , ClientOwner , HttpClient , close_clients
155from .sdkconfiguration import SDKConfiguration
166from .utils .logger import Logger , get_default_logger
177from .utils .retries import RetryConfig
8+ import httpx
9+ import importlib
10+ from mistralai_azure import models , utils
11+ from mistralai_azure ._hooks import SDKHooks
12+ from mistralai_azure .types import OptionalNullable , UNSET
13+ from typing import Any , Callable , Dict , Optional , TYPE_CHECKING , Union , cast
14+ import weakref
15+
16+ if TYPE_CHECKING :
17+ from mistralai_azure .chat import Chat
18+ from mistralai_azure .ocr import Ocr
1819
1920
2021class MistralAzure (BaseSDK ):
2122 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."""
2223
23- chat : Chat
24+ chat : " Chat"
2425 r"""Chat Completion API."""
26+ ocr : "Ocr"
27+ _sub_sdk_map = {
28+ "chat" : ("mistralai_azure.chat" , "Chat" ),
29+ "ocr" : ("mistralai_azure.ocr" , "Ocr" ),
30+ }
2531
2632 def __init__ (
2733 self ,
@@ -101,16 +107,16 @@ def __init__(
101107
102108 hooks = SDKHooks ()
103109
110+ # pylint: disable=protected-access
111+ self .sdk_configuration .__dict__ ["_hooks" ] = hooks
112+
104113 current_server_url , * _ = self .sdk_configuration .get_server_details ()
105114 server_url , self .sdk_configuration .client = hooks .sdk_init (
106115 current_server_url , client
107116 )
108117 if current_server_url != server_url :
109118 self .sdk_configuration .server_url = server_url
110119
111- # pylint: disable=protected-access
112- self .sdk_configuration .__dict__ ["_hooks" ] = hooks
113-
114120 weakref .finalize (
115121 self ,
116122 close_clients ,
@@ -121,10 +127,32 @@ def __init__(
121127 self .sdk_configuration .async_client_supplied ,
122128 )
123129
124- self ._init_sdks ()
130+ def __getattr__ (self , name : str ):
131+ if name in self ._sub_sdk_map :
132+ module_path , class_name = self ._sub_sdk_map [name ]
133+ try :
134+ module = importlib .import_module (module_path )
135+ klass = getattr (module , class_name )
136+ instance = klass (self .sdk_configuration )
137+ setattr (self , name , instance )
138+ return instance
139+ except ImportError as e :
140+ raise AttributeError (
141+ f"Failed to import module { module_path } for attribute { name } : { e } "
142+ ) from e
143+ except AttributeError as e :
144+ raise AttributeError (
145+ f"Failed to find class { class_name } in module { module_path } for attribute { name } : { e } "
146+ ) from e
147+
148+ raise AttributeError (
149+ f"'{ type (self ).__name__ } ' object has no attribute '{ name } '"
150+ )
125151
126- def _init_sdks (self ):
127- self .chat = Chat (self .sdk_configuration )
152+ def __dir__ (self ):
153+ default_attrs = list (super ().__dir__ ())
154+ lazy_attrs = list (self ._sub_sdk_map .keys ())
155+ return sorted (list (set (default_attrs + lazy_attrs )))
128156
129157 def __enter__ (self ):
130158 return self
0 commit comments