mistralai 1.9.7__py3-none-any.whl → 1.9.10__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mistralai/_version.py +2 -2
- mistralai/embeddings.py +6 -0
- mistralai/models/__init__.py +11 -0
- mistralai/models/apiendpoint.py +5 -0
- mistralai/models/embeddingrequest.py +5 -1
- mistralai/models/encodingformat.py +7 -0
- mistralai/models/systemmessage.py +7 -3
- mistralai/models/systemmessagecontentchunks.py +21 -0
- {mistralai-1.9.7.dist-info → mistralai-1.9.10.dist-info}/METADATA +1 -1
- {mistralai-1.9.7.dist-info → mistralai-1.9.10.dist-info}/RECORD +48 -35
- mistralai_azure/_hooks/types.py +7 -0
- mistralai_azure/_version.py +3 -3
- mistralai_azure/basesdk.py +12 -20
- mistralai_azure/chat.py +16 -0
- mistralai_azure/httpclient.py +6 -16
- mistralai_azure/models/__init__.py +298 -103
- mistralai_azure/models/assistantmessage.py +1 -1
- mistralai_azure/models/chatcompletionrequest.py +20 -3
- mistralai_azure/models/chatcompletionresponse.py +6 -6
- mistralai_azure/models/chatcompletionstreamrequest.py +20 -3
- mistralai_azure/models/completionresponsestreamchoice.py +1 -1
- mistralai_azure/models/deltamessage.py +1 -1
- mistralai_azure/models/documenturlchunk.py +62 -0
- mistralai_azure/models/filechunk.py +23 -0
- mistralai_azure/models/imageurl.py +1 -1
- mistralai_azure/models/jsonschema.py +1 -1
- mistralai_azure/models/mistralpromptmode.py +8 -0
- mistralai_azure/models/ocrimageobject.py +89 -0
- mistralai_azure/models/ocrpagedimensions.py +25 -0
- mistralai_azure/models/ocrpageobject.py +64 -0
- mistralai_azure/models/ocrrequest.py +120 -0
- mistralai_azure/models/ocrresponse.py +68 -0
- mistralai_azure/models/ocrusageinfo.py +57 -0
- mistralai_azure/models/responseformat.py +1 -1
- mistralai_azure/models/toolmessage.py +1 -1
- mistralai_azure/models/usageinfo.py +71 -8
- mistralai_azure/models/usermessage.py +1 -1
- mistralai_azure/ocr.py +271 -0
- mistralai_azure/sdk.py +45 -17
- mistralai_azure/sdkconfiguration.py +0 -7
- mistralai_azure/types/basemodel.py +3 -3
- mistralai_azure/utils/__init__.py +130 -45
- mistralai_azure/utils/datetimes.py +23 -0
- mistralai_azure/utils/enums.py +67 -27
- mistralai_azure/utils/forms.py +49 -28
- mistralai_azure/utils/serializers.py +32 -3
- {mistralai-1.9.7.dist-info → mistralai-1.9.10.dist-info}/LICENSE +0 -0
- {mistralai-1.9.7.dist-info → mistralai-1.9.10.dist-info}/WHEEL +0 -0
|
@@ -1,19 +1,82 @@
|
|
|
1
1
|
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
|
-
from mistralai_azure.types import
|
|
5
|
-
|
|
4
|
+
from mistralai_azure.types import (
|
|
5
|
+
BaseModel,
|
|
6
|
+
Nullable,
|
|
7
|
+
OptionalNullable,
|
|
8
|
+
UNSET,
|
|
9
|
+
UNSET_SENTINEL,
|
|
10
|
+
)
|
|
11
|
+
import pydantic
|
|
12
|
+
from pydantic import ConfigDict, model_serializer
|
|
13
|
+
from typing import Any, Dict, Optional
|
|
14
|
+
from typing_extensions import NotRequired, TypedDict
|
|
6
15
|
|
|
7
16
|
|
|
8
17
|
class UsageInfoTypedDict(TypedDict):
|
|
9
|
-
prompt_tokens: int
|
|
10
|
-
completion_tokens: int
|
|
11
|
-
total_tokens: int
|
|
18
|
+
prompt_tokens: NotRequired[int]
|
|
19
|
+
completion_tokens: NotRequired[int]
|
|
20
|
+
total_tokens: NotRequired[int]
|
|
21
|
+
prompt_audio_seconds: NotRequired[Nullable[int]]
|
|
12
22
|
|
|
13
23
|
|
|
14
24
|
class UsageInfo(BaseModel):
|
|
15
|
-
|
|
25
|
+
model_config = ConfigDict(
|
|
26
|
+
populate_by_name=True, arbitrary_types_allowed=True, extra="allow"
|
|
27
|
+
)
|
|
28
|
+
__pydantic_extra__: Dict[str, Any] = pydantic.Field(init=False)
|
|
16
29
|
|
|
17
|
-
|
|
30
|
+
prompt_tokens: Optional[int] = 0
|
|
18
31
|
|
|
19
|
-
|
|
32
|
+
completion_tokens: Optional[int] = 0
|
|
33
|
+
|
|
34
|
+
total_tokens: Optional[int] = 0
|
|
35
|
+
|
|
36
|
+
prompt_audio_seconds: OptionalNullable[int] = UNSET
|
|
37
|
+
|
|
38
|
+
@property
|
|
39
|
+
def additional_properties(self):
|
|
40
|
+
return self.__pydantic_extra__
|
|
41
|
+
|
|
42
|
+
@additional_properties.setter
|
|
43
|
+
def additional_properties(self, value):
|
|
44
|
+
self.__pydantic_extra__ = value # pyright: ignore[reportIncompatibleVariableOverride]
|
|
45
|
+
|
|
46
|
+
@model_serializer(mode="wrap")
|
|
47
|
+
def serialize_model(self, handler):
|
|
48
|
+
optional_fields = [
|
|
49
|
+
"prompt_tokens",
|
|
50
|
+
"completion_tokens",
|
|
51
|
+
"total_tokens",
|
|
52
|
+
"prompt_audio_seconds",
|
|
53
|
+
]
|
|
54
|
+
nullable_fields = ["prompt_audio_seconds"]
|
|
55
|
+
null_default_fields = []
|
|
56
|
+
|
|
57
|
+
serialized = handler(self)
|
|
58
|
+
|
|
59
|
+
m = {}
|
|
60
|
+
|
|
61
|
+
for n, f in type(self).model_fields.items():
|
|
62
|
+
k = f.alias or n
|
|
63
|
+
val = serialized.get(k)
|
|
64
|
+
serialized.pop(k, None)
|
|
65
|
+
|
|
66
|
+
optional_nullable = k in optional_fields and k in nullable_fields
|
|
67
|
+
is_set = (
|
|
68
|
+
self.__pydantic_fields_set__.intersection({n})
|
|
69
|
+
or k in null_default_fields
|
|
70
|
+
) # pylint: disable=no-member
|
|
71
|
+
|
|
72
|
+
if val is not None and val != UNSET_SENTINEL:
|
|
73
|
+
m[k] = val
|
|
74
|
+
elif val != UNSET_SENTINEL and (
|
|
75
|
+
not k in optional_fields or (optional_nullable and is_set)
|
|
76
|
+
):
|
|
77
|
+
m[k] = val
|
|
78
|
+
|
|
79
|
+
for k, v in serialized.items():
|
|
80
|
+
m[k] = v
|
|
81
|
+
|
|
82
|
+
return m
|
mistralai_azure/ocr.py
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
from .basesdk import BaseSDK
|
|
4
|
+
from mistralai_azure import models, utils
|
|
5
|
+
from mistralai_azure._hooks import HookContext
|
|
6
|
+
from mistralai_azure.types import Nullable, OptionalNullable, UNSET
|
|
7
|
+
from typing import Any, List, Mapping, Optional, Union
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Ocr(BaseSDK):
|
|
11
|
+
def process(
|
|
12
|
+
self,
|
|
13
|
+
*,
|
|
14
|
+
model: Nullable[str],
|
|
15
|
+
document: Union[models.Document, models.DocumentTypedDict],
|
|
16
|
+
id: Optional[str] = None,
|
|
17
|
+
pages: OptionalNullable[List[int]] = UNSET,
|
|
18
|
+
include_image_base64: OptionalNullable[bool] = UNSET,
|
|
19
|
+
image_limit: OptionalNullable[int] = UNSET,
|
|
20
|
+
image_min_size: OptionalNullable[int] = UNSET,
|
|
21
|
+
bbox_annotation_format: OptionalNullable[
|
|
22
|
+
Union[models.ResponseFormat, models.ResponseFormatTypedDict]
|
|
23
|
+
] = UNSET,
|
|
24
|
+
document_annotation_format: OptionalNullable[
|
|
25
|
+
Union[models.ResponseFormat, models.ResponseFormatTypedDict]
|
|
26
|
+
] = UNSET,
|
|
27
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
28
|
+
server_url: Optional[str] = None,
|
|
29
|
+
timeout_ms: Optional[int] = None,
|
|
30
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
|
31
|
+
) -> Optional[models.OCRResponse]:
|
|
32
|
+
r"""OCR
|
|
33
|
+
|
|
34
|
+
:param model:
|
|
35
|
+
:param document: Document to run OCR on
|
|
36
|
+
:param id:
|
|
37
|
+
:param pages: Specific pages user wants to process in various formats: single number, range, or list of both. Starts from 0
|
|
38
|
+
:param include_image_base64: Include image URLs in response
|
|
39
|
+
:param image_limit: Max images to extract
|
|
40
|
+
:param image_min_size: Minimum height and width of image to extract
|
|
41
|
+
:param bbox_annotation_format: Structured output class for extracting useful information from each extracted bounding box / image from document. Only json_schema is valid for this field
|
|
42
|
+
:param document_annotation_format: Structured output class for extracting useful information from the entire document. Only json_schema is valid for this field
|
|
43
|
+
:param retries: Override the default retry configuration for this method
|
|
44
|
+
:param server_url: Override the default server URL for this method
|
|
45
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
46
|
+
:param http_headers: Additional headers to set or replace on requests.
|
|
47
|
+
"""
|
|
48
|
+
base_url = None
|
|
49
|
+
url_variables = None
|
|
50
|
+
if timeout_ms is None:
|
|
51
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
52
|
+
|
|
53
|
+
if server_url is not None:
|
|
54
|
+
base_url = server_url
|
|
55
|
+
else:
|
|
56
|
+
base_url = self._get_url(base_url, url_variables)
|
|
57
|
+
|
|
58
|
+
request = models.OCRRequest(
|
|
59
|
+
model=model,
|
|
60
|
+
id=id,
|
|
61
|
+
document=utils.get_pydantic_model(document, models.Document),
|
|
62
|
+
pages=pages,
|
|
63
|
+
include_image_base64=include_image_base64,
|
|
64
|
+
image_limit=image_limit,
|
|
65
|
+
image_min_size=image_min_size,
|
|
66
|
+
bbox_annotation_format=utils.get_pydantic_model(
|
|
67
|
+
bbox_annotation_format, OptionalNullable[models.ResponseFormat]
|
|
68
|
+
),
|
|
69
|
+
document_annotation_format=utils.get_pydantic_model(
|
|
70
|
+
document_annotation_format, OptionalNullable[models.ResponseFormat]
|
|
71
|
+
),
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
req = self._build_request(
|
|
75
|
+
method="POST",
|
|
76
|
+
path="/ocr",
|
|
77
|
+
base_url=base_url,
|
|
78
|
+
url_variables=url_variables,
|
|
79
|
+
request=request,
|
|
80
|
+
request_body_required=True,
|
|
81
|
+
request_has_path_params=False,
|
|
82
|
+
request_has_query_params=True,
|
|
83
|
+
user_agent_header="user-agent",
|
|
84
|
+
accept_header_value="application/json",
|
|
85
|
+
http_headers=http_headers,
|
|
86
|
+
security=self.sdk_configuration.security,
|
|
87
|
+
get_serialized_body=lambda: utils.serialize_request_body(
|
|
88
|
+
request, False, False, "json", models.OCRRequest
|
|
89
|
+
),
|
|
90
|
+
timeout_ms=timeout_ms,
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
if retries == UNSET:
|
|
94
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
95
|
+
retries = self.sdk_configuration.retry_config
|
|
96
|
+
|
|
97
|
+
retry_config = None
|
|
98
|
+
if isinstance(retries, utils.RetryConfig):
|
|
99
|
+
retry_config = (retries, ["429", "500", "502", "503", "504"])
|
|
100
|
+
|
|
101
|
+
http_res = self.do_request(
|
|
102
|
+
hook_ctx=HookContext(
|
|
103
|
+
config=self.sdk_configuration,
|
|
104
|
+
base_url=base_url or "",
|
|
105
|
+
operation_id="ocr_v1_ocr_post",
|
|
106
|
+
oauth2_scopes=[],
|
|
107
|
+
security_source=self.sdk_configuration.security,
|
|
108
|
+
),
|
|
109
|
+
request=req,
|
|
110
|
+
error_status_codes=["422", "4XX", "5XX"],
|
|
111
|
+
retry_config=retry_config,
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
response_data: Any = None
|
|
115
|
+
if utils.match_response(http_res, "200", "application/json"):
|
|
116
|
+
return utils.unmarshal_json(http_res.text, Optional[models.OCRResponse])
|
|
117
|
+
if utils.match_response(http_res, "422", "application/json"):
|
|
118
|
+
response_data = utils.unmarshal_json(
|
|
119
|
+
http_res.text, models.HTTPValidationErrorData
|
|
120
|
+
)
|
|
121
|
+
raise models.HTTPValidationError(data=response_data)
|
|
122
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
123
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
124
|
+
raise models.SDKError(
|
|
125
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
126
|
+
)
|
|
127
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
128
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
129
|
+
raise models.SDKError(
|
|
130
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
content_type = http_res.headers.get("Content-Type")
|
|
134
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
135
|
+
raise models.SDKError(
|
|
136
|
+
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
137
|
+
http_res.status_code,
|
|
138
|
+
http_res_text,
|
|
139
|
+
http_res,
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
async def process_async(
|
|
143
|
+
self,
|
|
144
|
+
*,
|
|
145
|
+
model: Nullable[str],
|
|
146
|
+
document: Union[models.Document, models.DocumentTypedDict],
|
|
147
|
+
id: Optional[str] = None,
|
|
148
|
+
pages: OptionalNullable[List[int]] = UNSET,
|
|
149
|
+
include_image_base64: OptionalNullable[bool] = UNSET,
|
|
150
|
+
image_limit: OptionalNullable[int] = UNSET,
|
|
151
|
+
image_min_size: OptionalNullable[int] = UNSET,
|
|
152
|
+
bbox_annotation_format: OptionalNullable[
|
|
153
|
+
Union[models.ResponseFormat, models.ResponseFormatTypedDict]
|
|
154
|
+
] = UNSET,
|
|
155
|
+
document_annotation_format: OptionalNullable[
|
|
156
|
+
Union[models.ResponseFormat, models.ResponseFormatTypedDict]
|
|
157
|
+
] = UNSET,
|
|
158
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
159
|
+
server_url: Optional[str] = None,
|
|
160
|
+
timeout_ms: Optional[int] = None,
|
|
161
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
|
162
|
+
) -> Optional[models.OCRResponse]:
|
|
163
|
+
r"""OCR
|
|
164
|
+
|
|
165
|
+
:param model:
|
|
166
|
+
:param document: Document to run OCR on
|
|
167
|
+
:param id:
|
|
168
|
+
:param pages: Specific pages user wants to process in various formats: single number, range, or list of both. Starts from 0
|
|
169
|
+
:param include_image_base64: Include image URLs in response
|
|
170
|
+
:param image_limit: Max images to extract
|
|
171
|
+
:param image_min_size: Minimum height and width of image to extract
|
|
172
|
+
:param bbox_annotation_format: Structured output class for extracting useful information from each extracted bounding box / image from document. Only json_schema is valid for this field
|
|
173
|
+
:param document_annotation_format: Structured output class for extracting useful information from the entire document. Only json_schema is valid for this field
|
|
174
|
+
:param retries: Override the default retry configuration for this method
|
|
175
|
+
:param server_url: Override the default server URL for this method
|
|
176
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
177
|
+
:param http_headers: Additional headers to set or replace on requests.
|
|
178
|
+
"""
|
|
179
|
+
base_url = None
|
|
180
|
+
url_variables = None
|
|
181
|
+
if timeout_ms is None:
|
|
182
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
183
|
+
|
|
184
|
+
if server_url is not None:
|
|
185
|
+
base_url = server_url
|
|
186
|
+
else:
|
|
187
|
+
base_url = self._get_url(base_url, url_variables)
|
|
188
|
+
|
|
189
|
+
request = models.OCRRequest(
|
|
190
|
+
model=model,
|
|
191
|
+
id=id,
|
|
192
|
+
document=utils.get_pydantic_model(document, models.Document),
|
|
193
|
+
pages=pages,
|
|
194
|
+
include_image_base64=include_image_base64,
|
|
195
|
+
image_limit=image_limit,
|
|
196
|
+
image_min_size=image_min_size,
|
|
197
|
+
bbox_annotation_format=utils.get_pydantic_model(
|
|
198
|
+
bbox_annotation_format, OptionalNullable[models.ResponseFormat]
|
|
199
|
+
),
|
|
200
|
+
document_annotation_format=utils.get_pydantic_model(
|
|
201
|
+
document_annotation_format, OptionalNullable[models.ResponseFormat]
|
|
202
|
+
),
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
req = self._build_request_async(
|
|
206
|
+
method="POST",
|
|
207
|
+
path="/ocr",
|
|
208
|
+
base_url=base_url,
|
|
209
|
+
url_variables=url_variables,
|
|
210
|
+
request=request,
|
|
211
|
+
request_body_required=True,
|
|
212
|
+
request_has_path_params=False,
|
|
213
|
+
request_has_query_params=True,
|
|
214
|
+
user_agent_header="user-agent",
|
|
215
|
+
accept_header_value="application/json",
|
|
216
|
+
http_headers=http_headers,
|
|
217
|
+
security=self.sdk_configuration.security,
|
|
218
|
+
get_serialized_body=lambda: utils.serialize_request_body(
|
|
219
|
+
request, False, False, "json", models.OCRRequest
|
|
220
|
+
),
|
|
221
|
+
timeout_ms=timeout_ms,
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
if retries == UNSET:
|
|
225
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
226
|
+
retries = self.sdk_configuration.retry_config
|
|
227
|
+
|
|
228
|
+
retry_config = None
|
|
229
|
+
if isinstance(retries, utils.RetryConfig):
|
|
230
|
+
retry_config = (retries, ["429", "500", "502", "503", "504"])
|
|
231
|
+
|
|
232
|
+
http_res = await self.do_request_async(
|
|
233
|
+
hook_ctx=HookContext(
|
|
234
|
+
config=self.sdk_configuration,
|
|
235
|
+
base_url=base_url or "",
|
|
236
|
+
operation_id="ocr_v1_ocr_post",
|
|
237
|
+
oauth2_scopes=[],
|
|
238
|
+
security_source=self.sdk_configuration.security,
|
|
239
|
+
),
|
|
240
|
+
request=req,
|
|
241
|
+
error_status_codes=["422", "4XX", "5XX"],
|
|
242
|
+
retry_config=retry_config,
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
response_data: Any = None
|
|
246
|
+
if utils.match_response(http_res, "200", "application/json"):
|
|
247
|
+
return utils.unmarshal_json(http_res.text, Optional[models.OCRResponse])
|
|
248
|
+
if utils.match_response(http_res, "422", "application/json"):
|
|
249
|
+
response_data = utils.unmarshal_json(
|
|
250
|
+
http_res.text, models.HTTPValidationErrorData
|
|
251
|
+
)
|
|
252
|
+
raise models.HTTPValidationError(data=response_data)
|
|
253
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
254
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
255
|
+
raise models.SDKError(
|
|
256
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
257
|
+
)
|
|
258
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
259
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
260
|
+
raise models.SDKError(
|
|
261
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
content_type = http_res.headers.get("Content-Type")
|
|
265
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
266
|
+
raise models.SDKError(
|
|
267
|
+
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
268
|
+
http_res.status_code,
|
|
269
|
+
http_res_text,
|
|
270
|
+
http_res,
|
|
271
|
+
)
|
mistralai_azure/sdk.py
CHANGED
|
@@ -1,27 +1,33 @@
|
|
|
1
1
|
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
2
|
|
|
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
|
-
|
|
13
3
|
from .basesdk import BaseSDK
|
|
14
4
|
from .httpclient import AsyncHttpClient, ClientOwner, HttpClient, close_clients
|
|
15
5
|
from .sdkconfiguration import SDKConfiguration
|
|
16
6
|
from .utils.logger import Logger, get_default_logger
|
|
17
7
|
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
|
|
18
19
|
|
|
19
20
|
|
|
20
21
|
class MistralAzure(BaseSDK):
|
|
21
22
|
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."""
|
|
22
23
|
|
|
23
|
-
chat: Chat
|
|
24
|
+
chat: "Chat"
|
|
24
25
|
r"""Chat Completion API."""
|
|
26
|
+
ocr: "Ocr"
|
|
27
|
+
_sub_sdk_map = {
|
|
28
|
+
"chat": ("mistralai_azure.chat", "Chat"),
|
|
29
|
+
"ocr": ("mistralai_azure.ocr", "Ocr"),
|
|
30
|
+
}
|
|
25
31
|
|
|
26
32
|
def __init__(
|
|
27
33
|
self,
|
|
@@ -101,6 +107,9 @@ class MistralAzure(BaseSDK):
|
|
|
101
107
|
|
|
102
108
|
hooks = SDKHooks()
|
|
103
109
|
|
|
110
|
+
# pylint: disable=protected-access
|
|
111
|
+
self.sdk_configuration.__dict__["_hooks"] = hooks
|
|
112
|
+
|
|
104
113
|
current_server_url, *_ = self.sdk_configuration.get_server_details()
|
|
105
114
|
server_url, self.sdk_configuration.client = hooks.sdk_init(
|
|
106
115
|
current_server_url, client
|
|
@@ -108,9 +117,6 @@ class MistralAzure(BaseSDK):
|
|
|
108
117
|
if current_server_url != server_url:
|
|
109
118
|
self.sdk_configuration.server_url = server_url
|
|
110
119
|
|
|
111
|
-
# pylint: disable=protected-access
|
|
112
|
-
self.sdk_configuration.__dict__["_hooks"] = hooks
|
|
113
|
-
|
|
114
120
|
weakref.finalize(
|
|
115
121
|
self,
|
|
116
122
|
close_clients,
|
|
@@ -121,10 +127,32 @@ class MistralAzure(BaseSDK):
|
|
|
121
127
|
self.sdk_configuration.async_client_supplied,
|
|
122
128
|
)
|
|
123
129
|
|
|
124
|
-
|
|
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
|
+
)
|
|
125
151
|
|
|
126
|
-
def
|
|
127
|
-
|
|
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)))
|
|
128
156
|
|
|
129
157
|
def __enter__(self):
|
|
130
158
|
return self
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
2
|
|
|
3
|
-
from ._hooks import SDKHooks
|
|
4
3
|
from ._version import (
|
|
5
4
|
__gen_version__,
|
|
6
5
|
__openapi_doc_version__,
|
|
@@ -42,9 +41,6 @@ class SDKConfiguration:
|
|
|
42
41
|
retry_config: OptionalNullable[RetryConfig] = Field(default_factory=lambda: UNSET)
|
|
43
42
|
timeout_ms: Optional[int] = None
|
|
44
43
|
|
|
45
|
-
def __post_init__(self):
|
|
46
|
-
self._hooks = SDKHooks()
|
|
47
|
-
|
|
48
44
|
def get_server_details(self) -> Tuple[str, Dict[str, str]]:
|
|
49
45
|
if self.server_url is not None and self.server_url:
|
|
50
46
|
return remove_suffix(self.server_url, "/"), {}
|
|
@@ -55,6 +51,3 @@ class SDKConfiguration:
|
|
|
55
51
|
raise ValueError(f'Invalid server "{self.server}"')
|
|
56
52
|
|
|
57
53
|
return SERVERS[self.server], {}
|
|
58
|
-
|
|
59
|
-
def get_hooks(self) -> SDKHooks:
|
|
60
|
-
return self._hooks
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from pydantic import ConfigDict, model_serializer
|
|
4
4
|
from pydantic import BaseModel as PydanticBaseModel
|
|
5
|
-
from typing import TYPE_CHECKING, Literal, Optional, TypeVar, Union
|
|
5
|
+
from typing import TYPE_CHECKING, Literal, Optional, TypeVar, Union
|
|
6
6
|
from typing_extensions import TypeAliasType, TypeAlias
|
|
7
7
|
|
|
8
8
|
|
|
@@ -35,5 +35,5 @@ else:
|
|
|
35
35
|
"OptionalNullable", Union[Optional[Nullable[T]], Unset], type_params=(T,)
|
|
36
36
|
)
|
|
37
37
|
|
|
38
|
-
UnrecognizedInt =
|
|
39
|
-
UnrecognizedStr =
|
|
38
|
+
UnrecognizedInt: TypeAlias = int
|
|
39
|
+
UnrecognizedStr: TypeAlias = str
|