mistralai 1.9.10__py3-none-any.whl → 1.10.0__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/_hooks/registration.py +5 -0
- mistralai/_hooks/tracing.py +50 -0
- mistralai/_version.py +3 -3
- mistralai/accesses.py +51 -116
- mistralai/agents.py +58 -85
- mistralai/audio.py +8 -3
- mistralai/basesdk.py +15 -5
- mistralai/batch.py +6 -3
- mistralai/beta.py +10 -5
- mistralai/chat.py +70 -97
- mistralai/classifiers.py +57 -144
- mistralai/conversations.py +435 -412
- mistralai/documents.py +156 -359
- mistralai/embeddings.py +21 -42
- mistralai/extra/observability/__init__.py +15 -0
- mistralai/extra/observability/otel.py +393 -0
- mistralai/extra/run/tools.py +28 -16
- mistralai/files.py +53 -176
- mistralai/fim.py +46 -73
- mistralai/fine_tuning.py +6 -3
- mistralai/jobs.py +49 -158
- mistralai/libraries.py +71 -178
- mistralai/mistral_agents.py +298 -179
- mistralai/mistral_jobs.py +51 -138
- mistralai/models/__init__.py +94 -5
- mistralai/models/agent.py +15 -2
- mistralai/models/agentconversation.py +11 -3
- mistralai/models/agentcreationrequest.py +6 -2
- mistralai/models/agents_api_v1_agents_deleteop.py +16 -0
- mistralai/models/agents_api_v1_agents_getop.py +40 -3
- mistralai/models/agents_api_v1_agents_listop.py +72 -2
- mistralai/models/agents_api_v1_conversations_deleteop.py +18 -0
- mistralai/models/agents_api_v1_conversations_listop.py +39 -2
- mistralai/models/agentscompletionrequest.py +21 -6
- mistralai/models/agentscompletionstreamrequest.py +21 -6
- mistralai/models/agentupdaterequest.py +18 -2
- mistralai/models/audiotranscriptionrequest.py +2 -0
- mistralai/models/batchjobin.py +10 -0
- mistralai/models/chatcompletionrequest.py +22 -5
- mistralai/models/chatcompletionstreamrequest.py +22 -5
- mistralai/models/conversationrequest.py +15 -4
- mistralai/models/conversationrestartrequest.py +50 -2
- mistralai/models/conversationrestartstreamrequest.py +50 -2
- mistralai/models/conversationstreamrequest.py +15 -4
- mistralai/models/documentout.py +26 -10
- mistralai/models/documentupdatein.py +24 -3
- mistralai/models/embeddingrequest.py +8 -8
- mistralai/models/files_api_routes_list_filesop.py +7 -0
- mistralai/models/fimcompletionrequest.py +8 -9
- mistralai/models/fimcompletionstreamrequest.py +8 -9
- mistralai/models/httpvalidationerror.py +11 -6
- mistralai/models/libraries_documents_list_v1op.py +15 -2
- mistralai/models/libraryout.py +10 -7
- mistralai/models/listfilesout.py +35 -4
- mistralai/models/mistralerror.py +26 -0
- mistralai/models/modelcapabilities.py +13 -4
- mistralai/models/modelconversation.py +8 -2
- mistralai/models/no_response_error.py +13 -0
- mistralai/models/ocrpageobject.py +26 -5
- mistralai/models/ocrrequest.py +17 -1
- mistralai/models/ocrtableobject.py +31 -0
- mistralai/models/prediction.py +4 -0
- mistralai/models/requestsource.py +7 -0
- mistralai/models/responseformat.py +4 -2
- mistralai/models/responseformats.py +0 -1
- mistralai/models/responsevalidationerror.py +25 -0
- mistralai/models/sdkerror.py +30 -14
- mistralai/models/sharingdelete.py +36 -5
- mistralai/models/sharingin.py +36 -5
- mistralai/models/sharingout.py +3 -3
- mistralai/models/toolexecutiondeltaevent.py +13 -4
- mistralai/models/toolexecutiondoneevent.py +13 -4
- mistralai/models/toolexecutionentry.py +9 -4
- mistralai/models/toolexecutionstartedevent.py +13 -4
- mistralai/models_.py +67 -212
- mistralai/ocr.py +33 -36
- mistralai/sdk.py +15 -2
- mistralai/transcriptions.py +21 -60
- 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.10.0.dist-info}/METADATA +89 -40
- {mistralai-1.9.10.dist-info → mistralai-1.10.0.dist-info}/RECORD +86 -75
- {mistralai-1.9.10.dist-info → mistralai-1.10.0.dist-info}/WHEEL +1 -1
- {mistralai-1.9.10.dist-info → mistralai-1.10.0.dist-info/licenses}/LICENSE +0 -0
mistralai/models_.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
|
|
|
@@ -72,37 +73,20 @@ class Models(BaseSDK):
|
|
|
72
73
|
),
|
|
73
74
|
),
|
|
74
75
|
request=req,
|
|
75
|
-
error_status_codes=["
|
|
76
|
+
error_status_codes=["4XX", "5XX"],
|
|
76
77
|
retry_config=retry_config,
|
|
77
78
|
)
|
|
78
79
|
|
|
79
|
-
response_data: Any = None
|
|
80
80
|
if utils.match_response(http_res, "200", "application/json"):
|
|
81
|
-
return
|
|
82
|
-
if utils.match_response(http_res, "422", "application/json"):
|
|
83
|
-
response_data = utils.unmarshal_json(
|
|
84
|
-
http_res.text, models.HTTPValidationErrorData
|
|
85
|
-
)
|
|
86
|
-
raise models.HTTPValidationError(data=response_data)
|
|
81
|
+
return unmarshal_json_response(models.ModelList, http_res)
|
|
87
82
|
if utils.match_response(http_res, "4XX", "*"):
|
|
88
83
|
http_res_text = utils.stream_to_text(http_res)
|
|
89
|
-
raise models.SDKError(
|
|
90
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
91
|
-
)
|
|
84
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
92
85
|
if utils.match_response(http_res, "5XX", "*"):
|
|
93
86
|
http_res_text = utils.stream_to_text(http_res)
|
|
94
|
-
raise models.SDKError(
|
|
95
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
96
|
-
)
|
|
87
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
97
88
|
|
|
98
|
-
|
|
99
|
-
http_res_text = utils.stream_to_text(http_res)
|
|
100
|
-
raise models.SDKError(
|
|
101
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
102
|
-
http_res.status_code,
|
|
103
|
-
http_res_text,
|
|
104
|
-
http_res,
|
|
105
|
-
)
|
|
89
|
+
raise models.SDKError("Unexpected response received", http_res)
|
|
106
90
|
|
|
107
91
|
async def list_async(
|
|
108
92
|
self,
|
|
@@ -165,37 +149,20 @@ class Models(BaseSDK):
|
|
|
165
149
|
),
|
|
166
150
|
),
|
|
167
151
|
request=req,
|
|
168
|
-
error_status_codes=["
|
|
152
|
+
error_status_codes=["4XX", "5XX"],
|
|
169
153
|
retry_config=retry_config,
|
|
170
154
|
)
|
|
171
155
|
|
|
172
|
-
response_data: Any = None
|
|
173
156
|
if utils.match_response(http_res, "200", "application/json"):
|
|
174
|
-
return
|
|
175
|
-
if utils.match_response(http_res, "422", "application/json"):
|
|
176
|
-
response_data = utils.unmarshal_json(
|
|
177
|
-
http_res.text, models.HTTPValidationErrorData
|
|
178
|
-
)
|
|
179
|
-
raise models.HTTPValidationError(data=response_data)
|
|
157
|
+
return unmarshal_json_response(models.ModelList, http_res)
|
|
180
158
|
if utils.match_response(http_res, "4XX", "*"):
|
|
181
159
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
182
|
-
raise models.SDKError(
|
|
183
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
184
|
-
)
|
|
160
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
185
161
|
if utils.match_response(http_res, "5XX", "*"):
|
|
186
162
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
187
|
-
raise models.SDKError(
|
|
188
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
189
|
-
)
|
|
163
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
190
164
|
|
|
191
|
-
|
|
192
|
-
http_res_text = await utils.stream_to_text_async(http_res)
|
|
193
|
-
raise models.SDKError(
|
|
194
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
195
|
-
http_res.status_code,
|
|
196
|
-
http_res_text,
|
|
197
|
-
http_res,
|
|
198
|
-
)
|
|
165
|
+
raise models.SDKError("Unexpected response received", http_res)
|
|
199
166
|
|
|
200
167
|
def retrieve(
|
|
201
168
|
self,
|
|
@@ -271,34 +238,23 @@ class Models(BaseSDK):
|
|
|
271
238
|
|
|
272
239
|
response_data: Any = None
|
|
273
240
|
if utils.match_response(http_res, "200", "application/json"):
|
|
274
|
-
return
|
|
275
|
-
http_res.text,
|
|
241
|
+
return unmarshal_json_response(
|
|
276
242
|
models.RetrieveModelV1ModelsModelIDGetResponseRetrieveModelV1ModelsModelIDGet,
|
|
243
|
+
http_res,
|
|
277
244
|
)
|
|
278
245
|
if utils.match_response(http_res, "422", "application/json"):
|
|
279
|
-
response_data =
|
|
280
|
-
|
|
246
|
+
response_data = unmarshal_json_response(
|
|
247
|
+
models.HTTPValidationErrorData, http_res
|
|
281
248
|
)
|
|
282
|
-
raise models.HTTPValidationError(
|
|
249
|
+
raise models.HTTPValidationError(response_data, http_res)
|
|
283
250
|
if utils.match_response(http_res, "4XX", "*"):
|
|
284
251
|
http_res_text = utils.stream_to_text(http_res)
|
|
285
|
-
raise models.SDKError(
|
|
286
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
287
|
-
)
|
|
252
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
288
253
|
if utils.match_response(http_res, "5XX", "*"):
|
|
289
254
|
http_res_text = utils.stream_to_text(http_res)
|
|
290
|
-
raise models.SDKError(
|
|
291
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
292
|
-
)
|
|
255
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
293
256
|
|
|
294
|
-
|
|
295
|
-
http_res_text = utils.stream_to_text(http_res)
|
|
296
|
-
raise models.SDKError(
|
|
297
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
298
|
-
http_res.status_code,
|
|
299
|
-
http_res_text,
|
|
300
|
-
http_res,
|
|
301
|
-
)
|
|
257
|
+
raise models.SDKError("Unexpected response received", http_res)
|
|
302
258
|
|
|
303
259
|
async def retrieve_async(
|
|
304
260
|
self,
|
|
@@ -374,34 +330,23 @@ class Models(BaseSDK):
|
|
|
374
330
|
|
|
375
331
|
response_data: Any = None
|
|
376
332
|
if utils.match_response(http_res, "200", "application/json"):
|
|
377
|
-
return
|
|
378
|
-
http_res.text,
|
|
333
|
+
return unmarshal_json_response(
|
|
379
334
|
models.RetrieveModelV1ModelsModelIDGetResponseRetrieveModelV1ModelsModelIDGet,
|
|
335
|
+
http_res,
|
|
380
336
|
)
|
|
381
337
|
if utils.match_response(http_res, "422", "application/json"):
|
|
382
|
-
response_data =
|
|
383
|
-
|
|
338
|
+
response_data = unmarshal_json_response(
|
|
339
|
+
models.HTTPValidationErrorData, http_res
|
|
384
340
|
)
|
|
385
|
-
raise models.HTTPValidationError(
|
|
341
|
+
raise models.HTTPValidationError(response_data, http_res)
|
|
386
342
|
if utils.match_response(http_res, "4XX", "*"):
|
|
387
343
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
388
|
-
raise models.SDKError(
|
|
389
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
390
|
-
)
|
|
344
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
391
345
|
if utils.match_response(http_res, "5XX", "*"):
|
|
392
346
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
393
|
-
raise models.SDKError(
|
|
394
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
395
|
-
)
|
|
347
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
396
348
|
|
|
397
|
-
|
|
398
|
-
http_res_text = await utils.stream_to_text_async(http_res)
|
|
399
|
-
raise models.SDKError(
|
|
400
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
401
|
-
http_res.status_code,
|
|
402
|
-
http_res_text,
|
|
403
|
-
http_res,
|
|
404
|
-
)
|
|
349
|
+
raise models.SDKError("Unexpected response received", http_res)
|
|
405
350
|
|
|
406
351
|
def delete(
|
|
407
352
|
self,
|
|
@@ -477,31 +422,20 @@ class Models(BaseSDK):
|
|
|
477
422
|
|
|
478
423
|
response_data: Any = None
|
|
479
424
|
if utils.match_response(http_res, "200", "application/json"):
|
|
480
|
-
return
|
|
425
|
+
return unmarshal_json_response(models.DeleteModelOut, http_res)
|
|
481
426
|
if utils.match_response(http_res, "422", "application/json"):
|
|
482
|
-
response_data =
|
|
483
|
-
|
|
427
|
+
response_data = unmarshal_json_response(
|
|
428
|
+
models.HTTPValidationErrorData, http_res
|
|
484
429
|
)
|
|
485
|
-
raise models.HTTPValidationError(
|
|
430
|
+
raise models.HTTPValidationError(response_data, http_res)
|
|
486
431
|
if utils.match_response(http_res, "4XX", "*"):
|
|
487
432
|
http_res_text = utils.stream_to_text(http_res)
|
|
488
|
-
raise models.SDKError(
|
|
489
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
490
|
-
)
|
|
433
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
491
434
|
if utils.match_response(http_res, "5XX", "*"):
|
|
492
435
|
http_res_text = utils.stream_to_text(http_res)
|
|
493
|
-
raise models.SDKError(
|
|
494
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
495
|
-
)
|
|
436
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
496
437
|
|
|
497
|
-
|
|
498
|
-
http_res_text = utils.stream_to_text(http_res)
|
|
499
|
-
raise models.SDKError(
|
|
500
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
501
|
-
http_res.status_code,
|
|
502
|
-
http_res_text,
|
|
503
|
-
http_res,
|
|
504
|
-
)
|
|
438
|
+
raise models.SDKError("Unexpected response received", http_res)
|
|
505
439
|
|
|
506
440
|
async def delete_async(
|
|
507
441
|
self,
|
|
@@ -577,31 +511,20 @@ class Models(BaseSDK):
|
|
|
577
511
|
|
|
578
512
|
response_data: Any = None
|
|
579
513
|
if utils.match_response(http_res, "200", "application/json"):
|
|
580
|
-
return
|
|
514
|
+
return unmarshal_json_response(models.DeleteModelOut, http_res)
|
|
581
515
|
if utils.match_response(http_res, "422", "application/json"):
|
|
582
|
-
response_data =
|
|
583
|
-
|
|
516
|
+
response_data = unmarshal_json_response(
|
|
517
|
+
models.HTTPValidationErrorData, http_res
|
|
584
518
|
)
|
|
585
|
-
raise models.HTTPValidationError(
|
|
519
|
+
raise models.HTTPValidationError(response_data, http_res)
|
|
586
520
|
if utils.match_response(http_res, "4XX", "*"):
|
|
587
521
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
588
|
-
raise models.SDKError(
|
|
589
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
590
|
-
)
|
|
522
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
591
523
|
if utils.match_response(http_res, "5XX", "*"):
|
|
592
524
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
593
|
-
raise models.SDKError(
|
|
594
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
595
|
-
)
|
|
525
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
596
526
|
|
|
597
|
-
|
|
598
|
-
http_res_text = await utils.stream_to_text_async(http_res)
|
|
599
|
-
raise models.SDKError(
|
|
600
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
601
|
-
http_res.status_code,
|
|
602
|
-
http_res_text,
|
|
603
|
-
http_res,
|
|
604
|
-
)
|
|
527
|
+
raise models.SDKError("Unexpected response received", http_res)
|
|
605
528
|
|
|
606
529
|
def update(
|
|
607
530
|
self,
|
|
@@ -687,29 +610,17 @@ class Models(BaseSDK):
|
|
|
687
610
|
)
|
|
688
611
|
|
|
689
612
|
if utils.match_response(http_res, "200", "application/json"):
|
|
690
|
-
return
|
|
691
|
-
|
|
692
|
-
models.JobsAPIRoutesFineTuningUpdateFineTunedModelResponse,
|
|
613
|
+
return unmarshal_json_response(
|
|
614
|
+
models.JobsAPIRoutesFineTuningUpdateFineTunedModelResponse, http_res
|
|
693
615
|
)
|
|
694
616
|
if utils.match_response(http_res, "4XX", "*"):
|
|
695
617
|
http_res_text = utils.stream_to_text(http_res)
|
|
696
|
-
raise models.SDKError(
|
|
697
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
698
|
-
)
|
|
618
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
699
619
|
if utils.match_response(http_res, "5XX", "*"):
|
|
700
620
|
http_res_text = utils.stream_to_text(http_res)
|
|
701
|
-
raise models.SDKError(
|
|
702
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
703
|
-
)
|
|
621
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
704
622
|
|
|
705
|
-
|
|
706
|
-
http_res_text = utils.stream_to_text(http_res)
|
|
707
|
-
raise models.SDKError(
|
|
708
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
709
|
-
http_res.status_code,
|
|
710
|
-
http_res_text,
|
|
711
|
-
http_res,
|
|
712
|
-
)
|
|
623
|
+
raise models.SDKError("Unexpected response received", http_res)
|
|
713
624
|
|
|
714
625
|
async def update_async(
|
|
715
626
|
self,
|
|
@@ -795,29 +706,17 @@ class Models(BaseSDK):
|
|
|
795
706
|
)
|
|
796
707
|
|
|
797
708
|
if utils.match_response(http_res, "200", "application/json"):
|
|
798
|
-
return
|
|
799
|
-
|
|
800
|
-
models.JobsAPIRoutesFineTuningUpdateFineTunedModelResponse,
|
|
709
|
+
return unmarshal_json_response(
|
|
710
|
+
models.JobsAPIRoutesFineTuningUpdateFineTunedModelResponse, http_res
|
|
801
711
|
)
|
|
802
712
|
if utils.match_response(http_res, "4XX", "*"):
|
|
803
713
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
804
|
-
raise models.SDKError(
|
|
805
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
806
|
-
)
|
|
714
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
807
715
|
if utils.match_response(http_res, "5XX", "*"):
|
|
808
716
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
809
|
-
raise models.SDKError(
|
|
810
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
811
|
-
)
|
|
717
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
812
718
|
|
|
813
|
-
|
|
814
|
-
http_res_text = await utils.stream_to_text_async(http_res)
|
|
815
|
-
raise models.SDKError(
|
|
816
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
817
|
-
http_res.status_code,
|
|
818
|
-
http_res_text,
|
|
819
|
-
http_res,
|
|
820
|
-
)
|
|
719
|
+
raise models.SDKError("Unexpected response received", http_res)
|
|
821
720
|
|
|
822
721
|
def archive(
|
|
823
722
|
self,
|
|
@@ -892,26 +791,15 @@ class Models(BaseSDK):
|
|
|
892
791
|
)
|
|
893
792
|
|
|
894
793
|
if utils.match_response(http_res, "200", "application/json"):
|
|
895
|
-
return
|
|
794
|
+
return unmarshal_json_response(models.ArchiveFTModelOut, http_res)
|
|
896
795
|
if utils.match_response(http_res, "4XX", "*"):
|
|
897
796
|
http_res_text = utils.stream_to_text(http_res)
|
|
898
|
-
raise models.SDKError(
|
|
899
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
900
|
-
)
|
|
797
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
901
798
|
if utils.match_response(http_res, "5XX", "*"):
|
|
902
799
|
http_res_text = utils.stream_to_text(http_res)
|
|
903
|
-
raise models.SDKError(
|
|
904
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
905
|
-
)
|
|
800
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
906
801
|
|
|
907
|
-
|
|
908
|
-
http_res_text = utils.stream_to_text(http_res)
|
|
909
|
-
raise models.SDKError(
|
|
910
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
911
|
-
http_res.status_code,
|
|
912
|
-
http_res_text,
|
|
913
|
-
http_res,
|
|
914
|
-
)
|
|
802
|
+
raise models.SDKError("Unexpected response received", http_res)
|
|
915
803
|
|
|
916
804
|
async def archive_async(
|
|
917
805
|
self,
|
|
@@ -986,26 +874,15 @@ class Models(BaseSDK):
|
|
|
986
874
|
)
|
|
987
875
|
|
|
988
876
|
if utils.match_response(http_res, "200", "application/json"):
|
|
989
|
-
return
|
|
877
|
+
return unmarshal_json_response(models.ArchiveFTModelOut, http_res)
|
|
990
878
|
if utils.match_response(http_res, "4XX", "*"):
|
|
991
879
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
992
|
-
raise models.SDKError(
|
|
993
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
994
|
-
)
|
|
880
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
995
881
|
if utils.match_response(http_res, "5XX", "*"):
|
|
996
882
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
997
|
-
raise models.SDKError(
|
|
998
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
999
|
-
)
|
|
883
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
1000
884
|
|
|
1001
|
-
|
|
1002
|
-
http_res_text = await utils.stream_to_text_async(http_res)
|
|
1003
|
-
raise models.SDKError(
|
|
1004
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
1005
|
-
http_res.status_code,
|
|
1006
|
-
http_res_text,
|
|
1007
|
-
http_res,
|
|
1008
|
-
)
|
|
885
|
+
raise models.SDKError("Unexpected response received", http_res)
|
|
1009
886
|
|
|
1010
887
|
def unarchive(
|
|
1011
888
|
self,
|
|
@@ -1080,26 +957,15 @@ class Models(BaseSDK):
|
|
|
1080
957
|
)
|
|
1081
958
|
|
|
1082
959
|
if utils.match_response(http_res, "200", "application/json"):
|
|
1083
|
-
return
|
|
960
|
+
return unmarshal_json_response(models.UnarchiveFTModelOut, http_res)
|
|
1084
961
|
if utils.match_response(http_res, "4XX", "*"):
|
|
1085
962
|
http_res_text = utils.stream_to_text(http_res)
|
|
1086
|
-
raise models.SDKError(
|
|
1087
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
1088
|
-
)
|
|
963
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
1089
964
|
if utils.match_response(http_res, "5XX", "*"):
|
|
1090
965
|
http_res_text = utils.stream_to_text(http_res)
|
|
1091
|
-
raise models.SDKError(
|
|
1092
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
1093
|
-
)
|
|
966
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
1094
967
|
|
|
1095
|
-
|
|
1096
|
-
http_res_text = utils.stream_to_text(http_res)
|
|
1097
|
-
raise models.SDKError(
|
|
1098
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
1099
|
-
http_res.status_code,
|
|
1100
|
-
http_res_text,
|
|
1101
|
-
http_res,
|
|
1102
|
-
)
|
|
968
|
+
raise models.SDKError("Unexpected response received", http_res)
|
|
1103
969
|
|
|
1104
970
|
async def unarchive_async(
|
|
1105
971
|
self,
|
|
@@ -1174,23 +1040,12 @@ class Models(BaseSDK):
|
|
|
1174
1040
|
)
|
|
1175
1041
|
|
|
1176
1042
|
if utils.match_response(http_res, "200", "application/json"):
|
|
1177
|
-
return
|
|
1043
|
+
return unmarshal_json_response(models.UnarchiveFTModelOut, http_res)
|
|
1178
1044
|
if utils.match_response(http_res, "4XX", "*"):
|
|
1179
1045
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
1180
|
-
raise models.SDKError(
|
|
1181
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
1182
|
-
)
|
|
1046
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
1183
1047
|
if utils.match_response(http_res, "5XX", "*"):
|
|
1184
1048
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
1185
|
-
raise models.SDKError(
|
|
1186
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
1187
|
-
)
|
|
1049
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
1188
1050
|
|
|
1189
|
-
|
|
1190
|
-
http_res_text = await utils.stream_to_text_async(http_res)
|
|
1191
|
-
raise models.SDKError(
|
|
1192
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
1193
|
-
http_res.status_code,
|
|
1194
|
-
http_res_text,
|
|
1195
|
-
http_res,
|
|
1196
|
-
)
|
|
1051
|
+
raise models.SDKError("Unexpected response received", http_res)
|
mistralai/ocr.py
CHANGED
|
@@ -5,6 +5,7 @@ from mistralai import models, utils
|
|
|
5
5
|
from mistralai._hooks import HookContext
|
|
6
6
|
from mistralai.types import Nullable, 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, List, Mapping, Optional, Union
|
|
9
10
|
|
|
10
11
|
|
|
@@ -27,6 +28,9 @@ class Ocr(BaseSDK):
|
|
|
27
28
|
document_annotation_format: OptionalNullable[
|
|
28
29
|
Union[models.ResponseFormat, models.ResponseFormatTypedDict]
|
|
29
30
|
] = UNSET,
|
|
31
|
+
table_format: OptionalNullable[models.TableFormat] = UNSET,
|
|
32
|
+
extract_header: Optional[bool] = None,
|
|
33
|
+
extract_footer: Optional[bool] = None,
|
|
30
34
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
31
35
|
server_url: Optional[str] = None,
|
|
32
36
|
timeout_ms: Optional[int] = None,
|
|
@@ -43,6 +47,9 @@ class Ocr(BaseSDK):
|
|
|
43
47
|
:param image_min_size: Minimum height and width of image to extract
|
|
44
48
|
: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
|
|
45
49
|
:param document_annotation_format: Structured output class for extracting useful information from the entire document. Only json_schema is valid for this field
|
|
50
|
+
:param table_format:
|
|
51
|
+
:param extract_header:
|
|
52
|
+
:param extract_footer:
|
|
46
53
|
:param retries: Override the default retry configuration for this method
|
|
47
54
|
:param server_url: Override the default server URL for this method
|
|
48
55
|
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
@@ -72,6 +79,9 @@ class Ocr(BaseSDK):
|
|
|
72
79
|
document_annotation_format=utils.get_pydantic_model(
|
|
73
80
|
document_annotation_format, OptionalNullable[models.ResponseFormat]
|
|
74
81
|
),
|
|
82
|
+
table_format=table_format,
|
|
83
|
+
extract_header=extract_header,
|
|
84
|
+
extract_footer=extract_footer,
|
|
75
85
|
)
|
|
76
86
|
|
|
77
87
|
req = self._build_request(
|
|
@@ -118,31 +128,20 @@ class Ocr(BaseSDK):
|
|
|
118
128
|
|
|
119
129
|
response_data: Any = None
|
|
120
130
|
if utils.match_response(http_res, "200", "application/json"):
|
|
121
|
-
return
|
|
131
|
+
return unmarshal_json_response(models.OCRResponse, http_res)
|
|
122
132
|
if utils.match_response(http_res, "422", "application/json"):
|
|
123
|
-
response_data =
|
|
124
|
-
|
|
133
|
+
response_data = unmarshal_json_response(
|
|
134
|
+
models.HTTPValidationErrorData, http_res
|
|
125
135
|
)
|
|
126
|
-
raise models.HTTPValidationError(
|
|
136
|
+
raise models.HTTPValidationError(response_data, http_res)
|
|
127
137
|
if utils.match_response(http_res, "4XX", "*"):
|
|
128
138
|
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
|
-
)
|
|
139
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
132
140
|
if utils.match_response(http_res, "5XX", "*"):
|
|
133
141
|
http_res_text = utils.stream_to_text(http_res)
|
|
134
|
-
raise models.SDKError(
|
|
135
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
136
|
-
)
|
|
142
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
137
143
|
|
|
138
|
-
|
|
139
|
-
http_res_text = utils.stream_to_text(http_res)
|
|
140
|
-
raise models.SDKError(
|
|
141
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
142
|
-
http_res.status_code,
|
|
143
|
-
http_res_text,
|
|
144
|
-
http_res,
|
|
145
|
-
)
|
|
144
|
+
raise models.SDKError("Unexpected response received", http_res)
|
|
146
145
|
|
|
147
146
|
async def process_async(
|
|
148
147
|
self,
|
|
@@ -160,6 +159,9 @@ class Ocr(BaseSDK):
|
|
|
160
159
|
document_annotation_format: OptionalNullable[
|
|
161
160
|
Union[models.ResponseFormat, models.ResponseFormatTypedDict]
|
|
162
161
|
] = UNSET,
|
|
162
|
+
table_format: OptionalNullable[models.TableFormat] = UNSET,
|
|
163
|
+
extract_header: Optional[bool] = None,
|
|
164
|
+
extract_footer: Optional[bool] = None,
|
|
163
165
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
164
166
|
server_url: Optional[str] = None,
|
|
165
167
|
timeout_ms: Optional[int] = None,
|
|
@@ -176,6 +178,9 @@ class Ocr(BaseSDK):
|
|
|
176
178
|
:param image_min_size: Minimum height and width of image to extract
|
|
177
179
|
: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
|
|
178
180
|
:param document_annotation_format: Structured output class for extracting useful information from the entire document. Only json_schema is valid for this field
|
|
181
|
+
:param table_format:
|
|
182
|
+
:param extract_header:
|
|
183
|
+
:param extract_footer:
|
|
179
184
|
:param retries: Override the default retry configuration for this method
|
|
180
185
|
:param server_url: Override the default server URL for this method
|
|
181
186
|
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
@@ -205,6 +210,9 @@ class Ocr(BaseSDK):
|
|
|
205
210
|
document_annotation_format=utils.get_pydantic_model(
|
|
206
211
|
document_annotation_format, OptionalNullable[models.ResponseFormat]
|
|
207
212
|
),
|
|
213
|
+
table_format=table_format,
|
|
214
|
+
extract_header=extract_header,
|
|
215
|
+
extract_footer=extract_footer,
|
|
208
216
|
)
|
|
209
217
|
|
|
210
218
|
req = self._build_request_async(
|
|
@@ -251,28 +259,17 @@ class Ocr(BaseSDK):
|
|
|
251
259
|
|
|
252
260
|
response_data: Any = None
|
|
253
261
|
if utils.match_response(http_res, "200", "application/json"):
|
|
254
|
-
return
|
|
262
|
+
return unmarshal_json_response(models.OCRResponse, http_res)
|
|
255
263
|
if utils.match_response(http_res, "422", "application/json"):
|
|
256
|
-
response_data =
|
|
257
|
-
|
|
264
|
+
response_data = unmarshal_json_response(
|
|
265
|
+
models.HTTPValidationErrorData, http_res
|
|
258
266
|
)
|
|
259
|
-
raise models.HTTPValidationError(
|
|
267
|
+
raise models.HTTPValidationError(response_data, http_res)
|
|
260
268
|
if utils.match_response(http_res, "4XX", "*"):
|
|
261
269
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
262
|
-
raise models.SDKError(
|
|
263
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
264
|
-
)
|
|
270
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
265
271
|
if utils.match_response(http_res, "5XX", "*"):
|
|
266
272
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
267
|
-
raise models.SDKError(
|
|
268
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
269
|
-
)
|
|
273
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
270
274
|
|
|
271
|
-
|
|
272
|
-
http_res_text = await utils.stream_to_text_async(http_res)
|
|
273
|
-
raise models.SDKError(
|
|
274
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
275
|
-
http_res.status_code,
|
|
276
|
-
http_res_text,
|
|
277
|
-
http_res,
|
|
278
|
-
)
|
|
275
|
+
raise models.SDKError("Unexpected response received", http_res)
|
mistralai/sdk.py
CHANGED
|
@@ -10,6 +10,7 @@ import importlib
|
|
|
10
10
|
from mistralai import models, utils
|
|
11
11
|
from mistralai._hooks import SDKHooks
|
|
12
12
|
from mistralai.types import OptionalNullable, UNSET
|
|
13
|
+
import sys
|
|
13
14
|
from typing import Any, Callable, Dict, Optional, TYPE_CHECKING, Union, cast
|
|
14
15
|
import weakref
|
|
15
16
|
|
|
@@ -135,6 +136,7 @@ class Mistral(BaseSDK):
|
|
|
135
136
|
timeout_ms=timeout_ms,
|
|
136
137
|
debug_logger=debug_logger,
|
|
137
138
|
),
|
|
139
|
+
parent_ref=self,
|
|
138
140
|
)
|
|
139
141
|
|
|
140
142
|
hooks = SDKHooks()
|
|
@@ -159,13 +161,24 @@ class Mistral(BaseSDK):
|
|
|
159
161
|
self.sdk_configuration.async_client_supplied,
|
|
160
162
|
)
|
|
161
163
|
|
|
164
|
+
def dynamic_import(self, modname, retries=3):
|
|
165
|
+
for attempt in range(retries):
|
|
166
|
+
try:
|
|
167
|
+
return importlib.import_module(modname)
|
|
168
|
+
except KeyError:
|
|
169
|
+
# Clear any half-initialized module and retry
|
|
170
|
+
sys.modules.pop(modname, None)
|
|
171
|
+
if attempt == retries - 1:
|
|
172
|
+
break
|
|
173
|
+
raise KeyError(f"Failed to import module '{modname}' after {retries} attempts")
|
|
174
|
+
|
|
162
175
|
def __getattr__(self, name: str):
|
|
163
176
|
if name in self._sub_sdk_map:
|
|
164
177
|
module_path, class_name = self._sub_sdk_map[name]
|
|
165
178
|
try:
|
|
166
|
-
module =
|
|
179
|
+
module = self.dynamic_import(module_path)
|
|
167
180
|
klass = getattr(module, class_name)
|
|
168
|
-
instance = klass(self.sdk_configuration)
|
|
181
|
+
instance = klass(self.sdk_configuration, parent_ref=self)
|
|
169
182
|
setattr(self, name, instance)
|
|
170
183
|
return instance
|
|
171
184
|
except ImportError as e:
|