Skip to content

Commit 049014b

Browse files
authored
Fix: update base azure sdk file to include OCR (#267)
1 parent 16d470c commit 049014b

File tree

3 files changed

+47
-18
lines changed

3 files changed

+47
-18
lines changed

.speakeasy/workflow.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ targets:
2626
sourceRevisionDigest: sha256:670c460702ec74f7077491464a6dc5ee9d873969c80e812c48dbf4deb160e470
2727
sourceBlobDigest: sha256:5a3ebfa4cb00a015bb7bb03ec7442fc7e0b9c17ca66ab35d3045290b2ad87eac
2828
codeSamplesNamespace: mistral-openapi-azure-code-samples
29-
codeSamplesRevisionDigest: sha256:a4ace4b17dee92b180a2fede7742bd93fa1a83a9f96e4f61531289cafc50f6ad
29+
codeSamplesRevisionDigest: sha256:e6802c97fd9783aa91cc0853de1a889944f699b88e0dafcf9fecd83de6e2c6c9
3030
mistralai-gcp-sdk:
3131
source: mistral-google-cloud-source
3232
sourceNamespace: mistral-openapi-google-cloud

packages/mistralai_azure/.speakeasy/gen.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ generatedFiles:
165165
- src/mistralai_azure/models/validationerror.py
166166
- src/mistralai_azure/ocr.py
167167
- src/mistralai_azure/py.typed
168+
- src/mistralai_azure/sdk.py
168169
- src/mistralai_azure/sdkconfiguration.py
169170
- src/mistralai_azure/types/__init__.py
170171
- src/mistralai_azure/types/basemodel.py

packages/mistralai_azure/src/mistralai_azure/sdk.py

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
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-
133
from .basesdk import BaseSDK
144
from .httpclient import AsyncHttpClient, ClientOwner, HttpClient, close_clients
155
from .sdkconfiguration import SDKConfiguration
166
from .utils.logger import Logger, get_default_logger
177
from .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

2021
class 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

Comments
 (0)