mistralai 1.9.10__py3-none-any.whl → 1.9.11__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 +3 -3
- mistralai/accesses.py +43 -108
- mistralai/agents.py +29 -68
- mistralai/audio.py +8 -3
- mistralai/basesdk.py +15 -5
- mistralai/batch.py +6 -3
- mistralai/beta.py +10 -5
- mistralai/chat.py +29 -68
- mistralai/classifiers.py +57 -144
- mistralai/conversations.py +143 -352
- mistralai/documents.py +137 -356
- mistralai/embeddings.py +15 -36
- mistralai/files.py +47 -176
- mistralai/fim.py +29 -68
- mistralai/fine_tuning.py +6 -3
- mistralai/jobs.py +49 -158
- mistralai/libraries.py +71 -178
- mistralai/mistral_agents.py +71 -180
- mistralai/mistral_jobs.py +41 -128
- mistralai/models/__init__.py +25 -3
- mistralai/models/httpvalidationerror.py +11 -6
- mistralai/models/mistralerror.py +26 -0
- mistralai/models/no_response_error.py +13 -0
- mistralai/models/responsevalidationerror.py +25 -0
- mistralai/models/sdkerror.py +30 -14
- mistralai/models_.py +71 -204
- mistralai/ocr.py +15 -36
- mistralai/sdk.py +15 -2
- mistralai/transcriptions.py +17 -56
- mistralai/utils/__init__.py +18 -5
- mistralai/utils/eventstreaming.py +10 -0
- mistralai/utils/serializers.py +3 -2
- mistralai/utils/unmarshal_json_response.py +24 -0
- {mistralai-1.9.10.dist-info → mistralai-1.9.11.dist-info}/METADATA +61 -30
- {mistralai-1.9.10.dist-info → mistralai-1.9.11.dist-info}/RECORD +37 -33
- {mistralai-1.9.10.dist-info → mistralai-1.9.11.dist-info}/WHEEL +1 -1
- {mistralai-1.9.10.dist-info → mistralai-1.9.11.dist-info/licenses}/LICENSE +0 -0
mistralai/_version.py
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
import importlib.metadata
|
|
4
4
|
|
|
5
5
|
__title__: str = "mistralai"
|
|
6
|
-
__version__: str = "1.9.
|
|
6
|
+
__version__: str = "1.9.11"
|
|
7
7
|
__openapi_doc_version__: str = "1.0.0"
|
|
8
|
-
__gen_version__: str = "2.
|
|
9
|
-
__user_agent__: str = "speakeasy-sdk/python 1.9.
|
|
8
|
+
__gen_version__: str = "2.687.13"
|
|
9
|
+
__user_agent__: str = "speakeasy-sdk/python 1.9.11 2.687.13 1.0.0 mistralai"
|
|
10
10
|
|
|
11
11
|
try:
|
|
12
12
|
if __package__ is not None:
|
mistralai/accesses.py
CHANGED
|
@@ -5,6 +5,7 @@ from mistralai import models, utils
|
|
|
5
5
|
from mistralai._hooks import HookContext
|
|
6
6
|
from mistralai.types import OptionalNullable, UNSET
|
|
7
7
|
from mistralai.utils import get_security_from_env
|
|
8
|
+
from mistralai.utils.unmarshal_json_response import unmarshal_json_response
|
|
8
9
|
from typing import Any, Mapping, Optional
|
|
9
10
|
|
|
10
11
|
|
|
@@ -85,31 +86,20 @@ class Accesses(BaseSDK):
|
|
|
85
86
|
|
|
86
87
|
response_data: Any = None
|
|
87
88
|
if utils.match_response(http_res, "200", "application/json"):
|
|
88
|
-
return
|
|
89
|
+
return unmarshal_json_response(models.ListSharingOut, http_res)
|
|
89
90
|
if utils.match_response(http_res, "422", "application/json"):
|
|
90
|
-
response_data =
|
|
91
|
-
|
|
91
|
+
response_data = unmarshal_json_response(
|
|
92
|
+
models.HTTPValidationErrorData, http_res
|
|
92
93
|
)
|
|
93
|
-
raise models.HTTPValidationError(
|
|
94
|
+
raise models.HTTPValidationError(response_data, http_res)
|
|
94
95
|
if utils.match_response(http_res, "4XX", "*"):
|
|
95
96
|
http_res_text = utils.stream_to_text(http_res)
|
|
96
|
-
raise models.SDKError(
|
|
97
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
98
|
-
)
|
|
97
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
99
98
|
if utils.match_response(http_res, "5XX", "*"):
|
|
100
99
|
http_res_text = utils.stream_to_text(http_res)
|
|
101
|
-
raise models.SDKError(
|
|
102
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
103
|
-
)
|
|
100
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
104
101
|
|
|
105
|
-
|
|
106
|
-
http_res_text = utils.stream_to_text(http_res)
|
|
107
|
-
raise models.SDKError(
|
|
108
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
109
|
-
http_res.status_code,
|
|
110
|
-
http_res_text,
|
|
111
|
-
http_res,
|
|
112
|
-
)
|
|
102
|
+
raise models.SDKError("Unexpected response received", http_res)
|
|
113
103
|
|
|
114
104
|
async def list_async(
|
|
115
105
|
self,
|
|
@@ -185,31 +175,20 @@ class Accesses(BaseSDK):
|
|
|
185
175
|
|
|
186
176
|
response_data: Any = None
|
|
187
177
|
if utils.match_response(http_res, "200", "application/json"):
|
|
188
|
-
return
|
|
178
|
+
return unmarshal_json_response(models.ListSharingOut, http_res)
|
|
189
179
|
if utils.match_response(http_res, "422", "application/json"):
|
|
190
|
-
response_data =
|
|
191
|
-
|
|
180
|
+
response_data = unmarshal_json_response(
|
|
181
|
+
models.HTTPValidationErrorData, http_res
|
|
192
182
|
)
|
|
193
|
-
raise models.HTTPValidationError(
|
|
183
|
+
raise models.HTTPValidationError(response_data, http_res)
|
|
194
184
|
if utils.match_response(http_res, "4XX", "*"):
|
|
195
185
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
196
|
-
raise models.SDKError(
|
|
197
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
198
|
-
)
|
|
186
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
199
187
|
if utils.match_response(http_res, "5XX", "*"):
|
|
200
188
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
201
|
-
raise models.SDKError(
|
|
202
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
203
|
-
)
|
|
189
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
204
190
|
|
|
205
|
-
|
|
206
|
-
http_res_text = await utils.stream_to_text_async(http_res)
|
|
207
|
-
raise models.SDKError(
|
|
208
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
209
|
-
http_res.status_code,
|
|
210
|
-
http_res_text,
|
|
211
|
-
http_res,
|
|
212
|
-
)
|
|
191
|
+
raise models.SDKError("Unexpected response received", http_res)
|
|
213
192
|
|
|
214
193
|
def update_or_create(
|
|
215
194
|
self,
|
|
@@ -302,31 +281,20 @@ class Accesses(BaseSDK):
|
|
|
302
281
|
|
|
303
282
|
response_data: Any = None
|
|
304
283
|
if utils.match_response(http_res, "200", "application/json"):
|
|
305
|
-
return
|
|
284
|
+
return unmarshal_json_response(models.SharingOut, http_res)
|
|
306
285
|
if utils.match_response(http_res, "422", "application/json"):
|
|
307
|
-
response_data =
|
|
308
|
-
|
|
286
|
+
response_data = unmarshal_json_response(
|
|
287
|
+
models.HTTPValidationErrorData, http_res
|
|
309
288
|
)
|
|
310
|
-
raise models.HTTPValidationError(
|
|
289
|
+
raise models.HTTPValidationError(response_data, http_res)
|
|
311
290
|
if utils.match_response(http_res, "4XX", "*"):
|
|
312
291
|
http_res_text = utils.stream_to_text(http_res)
|
|
313
|
-
raise models.SDKError(
|
|
314
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
315
|
-
)
|
|
292
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
316
293
|
if utils.match_response(http_res, "5XX", "*"):
|
|
317
294
|
http_res_text = utils.stream_to_text(http_res)
|
|
318
|
-
raise models.SDKError(
|
|
319
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
320
|
-
)
|
|
295
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
321
296
|
|
|
322
|
-
|
|
323
|
-
http_res_text = utils.stream_to_text(http_res)
|
|
324
|
-
raise models.SDKError(
|
|
325
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
326
|
-
http_res.status_code,
|
|
327
|
-
http_res_text,
|
|
328
|
-
http_res,
|
|
329
|
-
)
|
|
297
|
+
raise models.SDKError("Unexpected response received", http_res)
|
|
330
298
|
|
|
331
299
|
async def update_or_create_async(
|
|
332
300
|
self,
|
|
@@ -419,31 +387,20 @@ class Accesses(BaseSDK):
|
|
|
419
387
|
|
|
420
388
|
response_data: Any = None
|
|
421
389
|
if utils.match_response(http_res, "200", "application/json"):
|
|
422
|
-
return
|
|
390
|
+
return unmarshal_json_response(models.SharingOut, http_res)
|
|
423
391
|
if utils.match_response(http_res, "422", "application/json"):
|
|
424
|
-
response_data =
|
|
425
|
-
|
|
392
|
+
response_data = unmarshal_json_response(
|
|
393
|
+
models.HTTPValidationErrorData, http_res
|
|
426
394
|
)
|
|
427
|
-
raise models.HTTPValidationError(
|
|
395
|
+
raise models.HTTPValidationError(response_data, http_res)
|
|
428
396
|
if utils.match_response(http_res, "4XX", "*"):
|
|
429
397
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
430
|
-
raise models.SDKError(
|
|
431
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
432
|
-
)
|
|
398
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
433
399
|
if utils.match_response(http_res, "5XX", "*"):
|
|
434
400
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
435
|
-
raise models.SDKError(
|
|
436
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
437
|
-
)
|
|
401
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
438
402
|
|
|
439
|
-
|
|
440
|
-
http_res_text = await utils.stream_to_text_async(http_res)
|
|
441
|
-
raise models.SDKError(
|
|
442
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
443
|
-
http_res.status_code,
|
|
444
|
-
http_res_text,
|
|
445
|
-
http_res,
|
|
446
|
-
)
|
|
403
|
+
raise models.SDKError("Unexpected response received", http_res)
|
|
447
404
|
|
|
448
405
|
def delete(
|
|
449
406
|
self,
|
|
@@ -533,31 +490,20 @@ class Accesses(BaseSDK):
|
|
|
533
490
|
|
|
534
491
|
response_data: Any = None
|
|
535
492
|
if utils.match_response(http_res, "200", "application/json"):
|
|
536
|
-
return
|
|
493
|
+
return unmarshal_json_response(models.SharingOut, http_res)
|
|
537
494
|
if utils.match_response(http_res, "422", "application/json"):
|
|
538
|
-
response_data =
|
|
539
|
-
|
|
495
|
+
response_data = unmarshal_json_response(
|
|
496
|
+
models.HTTPValidationErrorData, http_res
|
|
540
497
|
)
|
|
541
|
-
raise models.HTTPValidationError(
|
|
498
|
+
raise models.HTTPValidationError(response_data, http_res)
|
|
542
499
|
if utils.match_response(http_res, "4XX", "*"):
|
|
543
500
|
http_res_text = utils.stream_to_text(http_res)
|
|
544
|
-
raise models.SDKError(
|
|
545
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
546
|
-
)
|
|
501
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
547
502
|
if utils.match_response(http_res, "5XX", "*"):
|
|
548
503
|
http_res_text = utils.stream_to_text(http_res)
|
|
549
|
-
raise models.SDKError(
|
|
550
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
551
|
-
)
|
|
504
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
552
505
|
|
|
553
|
-
|
|
554
|
-
http_res_text = utils.stream_to_text(http_res)
|
|
555
|
-
raise models.SDKError(
|
|
556
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
557
|
-
http_res.status_code,
|
|
558
|
-
http_res_text,
|
|
559
|
-
http_res,
|
|
560
|
-
)
|
|
506
|
+
raise models.SDKError("Unexpected response received", http_res)
|
|
561
507
|
|
|
562
508
|
async def delete_async(
|
|
563
509
|
self,
|
|
@@ -647,28 +593,17 @@ class Accesses(BaseSDK):
|
|
|
647
593
|
|
|
648
594
|
response_data: Any = None
|
|
649
595
|
if utils.match_response(http_res, "200", "application/json"):
|
|
650
|
-
return
|
|
596
|
+
return unmarshal_json_response(models.SharingOut, http_res)
|
|
651
597
|
if utils.match_response(http_res, "422", "application/json"):
|
|
652
|
-
response_data =
|
|
653
|
-
|
|
598
|
+
response_data = unmarshal_json_response(
|
|
599
|
+
models.HTTPValidationErrorData, http_res
|
|
654
600
|
)
|
|
655
|
-
raise models.HTTPValidationError(
|
|
601
|
+
raise models.HTTPValidationError(response_data, http_res)
|
|
656
602
|
if utils.match_response(http_res, "4XX", "*"):
|
|
657
603
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
658
|
-
raise models.SDKError(
|
|
659
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
660
|
-
)
|
|
604
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
661
605
|
if utils.match_response(http_res, "5XX", "*"):
|
|
662
606
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
663
|
-
raise models.SDKError(
|
|
664
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
665
|
-
)
|
|
607
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
666
608
|
|
|
667
|
-
|
|
668
|
-
http_res_text = await utils.stream_to_text_async(http_res)
|
|
669
|
-
raise models.SDKError(
|
|
670
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
671
|
-
http_res.status_code,
|
|
672
|
-
http_res_text,
|
|
673
|
-
http_res,
|
|
674
|
-
)
|
|
609
|
+
raise models.SDKError("Unexpected response received", http_res)
|
mistralai/agents.py
CHANGED
|
@@ -5,6 +5,7 @@ from mistralai import models, utils
|
|
|
5
5
|
from mistralai._hooks import HookContext
|
|
6
6
|
from mistralai.types import OptionalNullable, UNSET
|
|
7
7
|
from mistralai.utils import eventstreaming, get_security_from_env
|
|
8
|
+
from mistralai.utils.unmarshal_json_response import unmarshal_json_response
|
|
8
9
|
from typing import Any, List, Mapping, Optional, Union
|
|
9
10
|
|
|
10
11
|
|
|
@@ -155,31 +156,20 @@ class Agents(BaseSDK):
|
|
|
155
156
|
|
|
156
157
|
response_data: Any = None
|
|
157
158
|
if utils.match_response(http_res, "200", "application/json"):
|
|
158
|
-
return
|
|
159
|
+
return unmarshal_json_response(models.ChatCompletionResponse, http_res)
|
|
159
160
|
if utils.match_response(http_res, "422", "application/json"):
|
|
160
|
-
response_data =
|
|
161
|
-
|
|
161
|
+
response_data = unmarshal_json_response(
|
|
162
|
+
models.HTTPValidationErrorData, http_res
|
|
162
163
|
)
|
|
163
|
-
raise models.HTTPValidationError(
|
|
164
|
+
raise models.HTTPValidationError(response_data, http_res)
|
|
164
165
|
if utils.match_response(http_res, "4XX", "*"):
|
|
165
166
|
http_res_text = utils.stream_to_text(http_res)
|
|
166
|
-
raise models.SDKError(
|
|
167
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
168
|
-
)
|
|
167
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
169
168
|
if utils.match_response(http_res, "5XX", "*"):
|
|
170
169
|
http_res_text = utils.stream_to_text(http_res)
|
|
171
|
-
raise models.SDKError(
|
|
172
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
173
|
-
)
|
|
170
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
174
171
|
|
|
175
|
-
|
|
176
|
-
http_res_text = utils.stream_to_text(http_res)
|
|
177
|
-
raise models.SDKError(
|
|
178
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
179
|
-
http_res.status_code,
|
|
180
|
-
http_res_text,
|
|
181
|
-
http_res,
|
|
182
|
-
)
|
|
172
|
+
raise models.SDKError("Unexpected response received", http_res)
|
|
183
173
|
|
|
184
174
|
async def complete_async(
|
|
185
175
|
self,
|
|
@@ -325,31 +315,20 @@ class Agents(BaseSDK):
|
|
|
325
315
|
|
|
326
316
|
response_data: Any = None
|
|
327
317
|
if utils.match_response(http_res, "200", "application/json"):
|
|
328
|
-
return
|
|
318
|
+
return unmarshal_json_response(models.ChatCompletionResponse, http_res)
|
|
329
319
|
if utils.match_response(http_res, "422", "application/json"):
|
|
330
|
-
response_data =
|
|
331
|
-
|
|
320
|
+
response_data = unmarshal_json_response(
|
|
321
|
+
models.HTTPValidationErrorData, http_res
|
|
332
322
|
)
|
|
333
|
-
raise models.HTTPValidationError(
|
|
323
|
+
raise models.HTTPValidationError(response_data, http_res)
|
|
334
324
|
if utils.match_response(http_res, "4XX", "*"):
|
|
335
325
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
336
|
-
raise models.SDKError(
|
|
337
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
338
|
-
)
|
|
326
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
339
327
|
if utils.match_response(http_res, "5XX", "*"):
|
|
340
328
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
341
|
-
raise models.SDKError(
|
|
342
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
343
|
-
)
|
|
329
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
344
330
|
|
|
345
|
-
|
|
346
|
-
http_res_text = await utils.stream_to_text_async(http_res)
|
|
347
|
-
raise models.SDKError(
|
|
348
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
349
|
-
http_res.status_code,
|
|
350
|
-
http_res_text,
|
|
351
|
-
http_res,
|
|
352
|
-
)
|
|
331
|
+
raise models.SDKError("Unexpected response received", http_res)
|
|
353
332
|
|
|
354
333
|
def stream(
|
|
355
334
|
self,
|
|
@@ -502,32 +481,23 @@ class Agents(BaseSDK):
|
|
|
502
481
|
http_res,
|
|
503
482
|
lambda raw: utils.unmarshal_json(raw, models.CompletionEvent),
|
|
504
483
|
sentinel="[DONE]",
|
|
484
|
+
client_ref=self,
|
|
505
485
|
)
|
|
506
486
|
if utils.match_response(http_res, "422", "application/json"):
|
|
507
487
|
http_res_text = utils.stream_to_text(http_res)
|
|
508
|
-
response_data =
|
|
509
|
-
|
|
488
|
+
response_data = unmarshal_json_response(
|
|
489
|
+
models.HTTPValidationErrorData, http_res, http_res_text
|
|
510
490
|
)
|
|
511
|
-
raise models.HTTPValidationError(
|
|
491
|
+
raise models.HTTPValidationError(response_data, http_res, http_res_text)
|
|
512
492
|
if utils.match_response(http_res, "4XX", "*"):
|
|
513
493
|
http_res_text = utils.stream_to_text(http_res)
|
|
514
|
-
raise models.SDKError(
|
|
515
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
516
|
-
)
|
|
494
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
517
495
|
if utils.match_response(http_res, "5XX", "*"):
|
|
518
496
|
http_res_text = utils.stream_to_text(http_res)
|
|
519
|
-
raise models.SDKError(
|
|
520
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
521
|
-
)
|
|
497
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
522
498
|
|
|
523
|
-
content_type = http_res.headers.get("Content-Type")
|
|
524
499
|
http_res_text = utils.stream_to_text(http_res)
|
|
525
|
-
raise models.SDKError(
|
|
526
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
527
|
-
http_res.status_code,
|
|
528
|
-
http_res_text,
|
|
529
|
-
http_res,
|
|
530
|
-
)
|
|
500
|
+
raise models.SDKError("Unexpected response received", http_res, http_res_text)
|
|
531
501
|
|
|
532
502
|
async def stream_async(
|
|
533
503
|
self,
|
|
@@ -680,29 +650,20 @@ class Agents(BaseSDK):
|
|
|
680
650
|
http_res,
|
|
681
651
|
lambda raw: utils.unmarshal_json(raw, models.CompletionEvent),
|
|
682
652
|
sentinel="[DONE]",
|
|
653
|
+
client_ref=self,
|
|
683
654
|
)
|
|
684
655
|
if utils.match_response(http_res, "422", "application/json"):
|
|
685
656
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
686
|
-
response_data =
|
|
687
|
-
|
|
657
|
+
response_data = unmarshal_json_response(
|
|
658
|
+
models.HTTPValidationErrorData, http_res, http_res_text
|
|
688
659
|
)
|
|
689
|
-
raise models.HTTPValidationError(
|
|
660
|
+
raise models.HTTPValidationError(response_data, http_res, http_res_text)
|
|
690
661
|
if utils.match_response(http_res, "4XX", "*"):
|
|
691
662
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
692
|
-
raise models.SDKError(
|
|
693
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
694
|
-
)
|
|
663
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
695
664
|
if utils.match_response(http_res, "5XX", "*"):
|
|
696
665
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
697
|
-
raise models.SDKError(
|
|
698
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
699
|
-
)
|
|
666
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
700
667
|
|
|
701
|
-
content_type = http_res.headers.get("Content-Type")
|
|
702
668
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
703
|
-
raise models.SDKError(
|
|
704
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
705
|
-
http_res.status_code,
|
|
706
|
-
http_res_text,
|
|
707
|
-
http_res,
|
|
708
|
-
)
|
|
669
|
+
raise models.SDKError("Unexpected response received", http_res, http_res_text)
|
mistralai/audio.py
CHANGED
|
@@ -3,16 +3,21 @@
|
|
|
3
3
|
from .basesdk import BaseSDK
|
|
4
4
|
from .sdkconfiguration import SDKConfiguration
|
|
5
5
|
from mistralai.transcriptions import Transcriptions
|
|
6
|
+
from typing import Optional
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
class Audio(BaseSDK):
|
|
9
10
|
transcriptions: Transcriptions
|
|
10
11
|
r"""API for audio transcription."""
|
|
11
12
|
|
|
12
|
-
def __init__(
|
|
13
|
-
|
|
13
|
+
def __init__(
|
|
14
|
+
self, sdk_config: SDKConfiguration, parent_ref: Optional[object] = None
|
|
15
|
+
) -> None:
|
|
16
|
+
BaseSDK.__init__(self, sdk_config, parent_ref=parent_ref)
|
|
14
17
|
self.sdk_configuration = sdk_config
|
|
15
18
|
self._init_sdks()
|
|
16
19
|
|
|
17
20
|
def _init_sdks(self):
|
|
18
|
-
self.transcriptions = Transcriptions(
|
|
21
|
+
self.transcriptions = Transcriptions(
|
|
22
|
+
self.sdk_configuration, parent_ref=self.parent_ref
|
|
23
|
+
)
|
mistralai/basesdk.py
CHANGED
|
@@ -15,9 +15,19 @@ from urllib.parse import parse_qs, urlparse
|
|
|
15
15
|
|
|
16
16
|
class BaseSDK:
|
|
17
17
|
sdk_configuration: SDKConfiguration
|
|
18
|
+
parent_ref: Optional[object] = None
|
|
19
|
+
"""
|
|
20
|
+
Reference to the root SDK instance, if any. This will prevent it from
|
|
21
|
+
being garbage collected while there are active streams.
|
|
22
|
+
"""
|
|
18
23
|
|
|
19
|
-
def __init__(
|
|
24
|
+
def __init__(
|
|
25
|
+
self,
|
|
26
|
+
sdk_config: SDKConfiguration,
|
|
27
|
+
parent_ref: Optional[object] = None,
|
|
28
|
+
) -> None:
|
|
20
29
|
self.sdk_configuration = sdk_config
|
|
30
|
+
self.parent_ref = parent_ref
|
|
21
31
|
|
|
22
32
|
def _get_url(self, base_url, url_variables):
|
|
23
33
|
sdk_url, sdk_variables = self.sdk_configuration.get_server_details()
|
|
@@ -244,7 +254,7 @@ class BaseSDK:
|
|
|
244
254
|
|
|
245
255
|
if http_res is None:
|
|
246
256
|
logger.debug("Raising no response SDK error")
|
|
247
|
-
raise models.
|
|
257
|
+
raise models.NoResponseError("No response received")
|
|
248
258
|
|
|
249
259
|
logger.debug(
|
|
250
260
|
"Response:\nStatus Code: %s\nURL: %s\nHeaders: %s\nBody: %s",
|
|
@@ -265,7 +275,7 @@ class BaseSDK:
|
|
|
265
275
|
http_res = result
|
|
266
276
|
else:
|
|
267
277
|
logger.debug("Raising unexpected SDK error")
|
|
268
|
-
raise models.SDKError("Unexpected error occurred")
|
|
278
|
+
raise models.SDKError("Unexpected error occurred", http_res)
|
|
269
279
|
|
|
270
280
|
return http_res
|
|
271
281
|
|
|
@@ -316,7 +326,7 @@ class BaseSDK:
|
|
|
316
326
|
|
|
317
327
|
if http_res is None:
|
|
318
328
|
logger.debug("Raising no response SDK error")
|
|
319
|
-
raise models.
|
|
329
|
+
raise models.NoResponseError("No response received")
|
|
320
330
|
|
|
321
331
|
logger.debug(
|
|
322
332
|
"Response:\nStatus Code: %s\nURL: %s\nHeaders: %s\nBody: %s",
|
|
@@ -337,7 +347,7 @@ class BaseSDK:
|
|
|
337
347
|
http_res = result
|
|
338
348
|
else:
|
|
339
349
|
logger.debug("Raising unexpected SDK error")
|
|
340
|
-
raise models.SDKError("Unexpected error occurred")
|
|
350
|
+
raise models.SDKError("Unexpected error occurred", http_res)
|
|
341
351
|
|
|
342
352
|
return http_res
|
|
343
353
|
|
mistralai/batch.py
CHANGED
|
@@ -3,15 +3,18 @@
|
|
|
3
3
|
from .basesdk import BaseSDK
|
|
4
4
|
from .sdkconfiguration import SDKConfiguration
|
|
5
5
|
from mistralai.mistral_jobs import MistralJobs
|
|
6
|
+
from typing import Optional
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
class Batch(BaseSDK):
|
|
9
10
|
jobs: MistralJobs
|
|
10
11
|
|
|
11
|
-
def __init__(
|
|
12
|
-
|
|
12
|
+
def __init__(
|
|
13
|
+
self, sdk_config: SDKConfiguration, parent_ref: Optional[object] = None
|
|
14
|
+
) -> None:
|
|
15
|
+
BaseSDK.__init__(self, sdk_config, parent_ref=parent_ref)
|
|
13
16
|
self.sdk_configuration = sdk_config
|
|
14
17
|
self._init_sdks()
|
|
15
18
|
|
|
16
19
|
def _init_sdks(self):
|
|
17
|
-
self.jobs = MistralJobs(self.sdk_configuration)
|
|
20
|
+
self.jobs = MistralJobs(self.sdk_configuration, parent_ref=self.parent_ref)
|
mistralai/beta.py
CHANGED
|
@@ -5,6 +5,7 @@ from .sdkconfiguration import SDKConfiguration
|
|
|
5
5
|
from mistralai.conversations import Conversations
|
|
6
6
|
from mistralai.libraries import Libraries
|
|
7
7
|
from mistralai.mistral_agents import MistralAgents
|
|
8
|
+
from typing import Optional
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
class Beta(BaseSDK):
|
|
@@ -15,12 +16,16 @@ class Beta(BaseSDK):
|
|
|
15
16
|
libraries: Libraries
|
|
16
17
|
r"""(beta) Libraries API to create and manage libraries - index your documents to enhance agent capabilities."""
|
|
17
18
|
|
|
18
|
-
def __init__(
|
|
19
|
-
|
|
19
|
+
def __init__(
|
|
20
|
+
self, sdk_config: SDKConfiguration, parent_ref: Optional[object] = None
|
|
21
|
+
) -> None:
|
|
22
|
+
BaseSDK.__init__(self, sdk_config, parent_ref=parent_ref)
|
|
20
23
|
self.sdk_configuration = sdk_config
|
|
21
24
|
self._init_sdks()
|
|
22
25
|
|
|
23
26
|
def _init_sdks(self):
|
|
24
|
-
self.conversations = Conversations(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
self.conversations = Conversations(
|
|
28
|
+
self.sdk_configuration, parent_ref=self.parent_ref
|
|
29
|
+
)
|
|
30
|
+
self.agents = MistralAgents(self.sdk_configuration, parent_ref=self.parent_ref)
|
|
31
|
+
self.libraries = Libraries(self.sdk_configuration, parent_ref=self.parent_ref)
|