mistralai 1.10.0__py3-none-any.whl → 1.11.1__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/tracing.py +28 -3
- mistralai/_version.py +3 -3
- mistralai/accesses.py +22 -12
- mistralai/agents.py +88 -44
- mistralai/basesdk.py +6 -0
- mistralai/chat.py +96 -40
- mistralai/classifiers.py +48 -23
- mistralai/conversations.py +186 -64
- mistralai/documents.py +72 -26
- mistralai/embeddings.py +24 -9
- mistralai/extra/README.md +1 -1
- mistralai/extra/mcp/auth.py +10 -11
- mistralai/extra/mcp/base.py +17 -16
- mistralai/extra/mcp/sse.py +13 -15
- mistralai/extra/mcp/stdio.py +5 -6
- mistralai/extra/observability/otel.py +47 -68
- mistralai/extra/run/context.py +33 -43
- mistralai/extra/run/result.py +29 -30
- mistralai/extra/run/tools.py +8 -9
- mistralai/extra/struct_chat.py +15 -8
- mistralai/extra/utils/response_format.py +5 -3
- mistralai/files.py +58 -24
- mistralai/fim.py +20 -12
- mistralai/httpclient.py +0 -1
- mistralai/jobs.py +65 -26
- mistralai/libraries.py +20 -10
- mistralai/mistral_agents.py +438 -30
- mistralai/mistral_jobs.py +62 -17
- mistralai/models/__init__.py +46 -1
- mistralai/models/agent.py +1 -1
- mistralai/models/agentconversation.py +1 -1
- mistralai/models/agenthandoffdoneevent.py +1 -1
- mistralai/models/agenthandoffentry.py +3 -2
- mistralai/models/agenthandoffstartedevent.py +1 -1
- mistralai/models/agents_api_v1_agents_get_versionop.py +21 -0
- mistralai/models/agents_api_v1_agents_list_versionsop.py +33 -0
- mistralai/models/agents_api_v1_agents_listop.py +5 -1
- mistralai/models/agents_api_v1_conversations_listop.py +1 -1
- mistralai/models/agentscompletionrequest.py +2 -5
- mistralai/models/agentscompletionstreamrequest.py +2 -5
- mistralai/models/archiveftmodelout.py +1 -1
- mistralai/models/assistantmessage.py +1 -1
- mistralai/models/audiochunk.py +1 -1
- mistralai/models/audioencoding.py +18 -0
- mistralai/models/audioformat.py +17 -0
- mistralai/models/basemodelcard.py +1 -1
- mistralai/models/batchjobin.py +18 -9
- mistralai/models/batchjobout.py +6 -1
- mistralai/models/batchjobsout.py +1 -1
- mistralai/models/batchrequest.py +48 -0
- mistralai/models/chatcompletionchoice.py +10 -5
- mistralai/models/chatcompletionrequest.py +2 -5
- mistralai/models/chatcompletionstreamrequest.py +2 -5
- mistralai/models/classificationrequest.py +37 -3
- mistralai/models/classifierdetailedjobout.py +4 -2
- mistralai/models/classifierftmodelout.py +3 -2
- mistralai/models/classifierjobout.py +4 -2
- mistralai/models/codeinterpretertool.py +1 -1
- mistralai/models/completiondetailedjobout.py +5 -2
- mistralai/models/completionftmodelout.py +3 -2
- mistralai/models/completionjobout.py +5 -2
- mistralai/models/completionresponsestreamchoice.py +9 -8
- mistralai/models/conversationappendrequest.py +4 -1
- mistralai/models/conversationappendstreamrequest.py +4 -1
- mistralai/models/conversationhistory.py +2 -1
- mistralai/models/conversationmessages.py +1 -1
- mistralai/models/conversationrequest.py +5 -1
- mistralai/models/conversationresponse.py +2 -1
- mistralai/models/conversationrestartrequest.py +4 -1
- mistralai/models/conversationrestartstreamrequest.py +4 -1
- mistralai/models/conversationstreamrequest.py +5 -1
- mistralai/models/documentlibrarytool.py +1 -1
- mistralai/models/documenturlchunk.py +1 -1
- mistralai/models/embeddingdtype.py +7 -1
- mistralai/models/embeddingrequest.py +11 -3
- mistralai/models/encodingformat.py +4 -1
- mistralai/models/entitytype.py +8 -1
- mistralai/models/filepurpose.py +8 -1
- mistralai/models/files_api_routes_list_filesop.py +4 -11
- mistralai/models/files_api_routes_upload_fileop.py +2 -6
- mistralai/models/fileschema.py +3 -5
- mistralai/models/finetuneablemodeltype.py +4 -1
- mistralai/models/ftclassifierlossfunction.py +4 -1
- mistralai/models/ftmodelcard.py +1 -1
- mistralai/models/functioncallentry.py +3 -2
- mistralai/models/functioncallevent.py +1 -1
- mistralai/models/functionresultentry.py +3 -2
- mistralai/models/functiontool.py +1 -1
- mistralai/models/githubrepositoryin.py +1 -1
- mistralai/models/githubrepositoryout.py +1 -1
- mistralai/models/httpvalidationerror.py +4 -2
- mistralai/models/imagegenerationtool.py +1 -1
- mistralai/models/imageurlchunk.py +1 -1
- mistralai/models/jobs_api_routes_batch_get_batch_jobop.py +40 -3
- mistralai/models/jobsout.py +1 -1
- mistralai/models/legacyjobmetadataout.py +1 -1
- mistralai/models/messageinputentry.py +9 -3
- mistralai/models/messageoutputentry.py +6 -3
- mistralai/models/messageoutputevent.py +4 -2
- mistralai/models/mistralerror.py +11 -7
- mistralai/models/mistralpromptmode.py +1 -1
- mistralai/models/modelconversation.py +1 -1
- mistralai/models/no_response_error.py +5 -1
- mistralai/models/ocrrequest.py +11 -1
- mistralai/models/ocrtableobject.py +4 -1
- mistralai/models/referencechunk.py +1 -1
- mistralai/models/requestsource.py +5 -1
- mistralai/models/responsedoneevent.py +1 -1
- mistralai/models/responseerrorevent.py +1 -1
- mistralai/models/responseformats.py +5 -1
- mistralai/models/responsestartedevent.py +1 -1
- mistralai/models/responsevalidationerror.py +2 -0
- mistralai/models/retrievefileout.py +3 -5
- mistralai/models/sampletype.py +7 -1
- mistralai/models/sdkerror.py +2 -0
- mistralai/models/shareenum.py +7 -1
- mistralai/models/sharingdelete.py +2 -4
- mistralai/models/sharingin.py +3 -5
- mistralai/models/source.py +8 -1
- mistralai/models/systemmessage.py +1 -1
- mistralai/models/textchunk.py +1 -1
- mistralai/models/thinkchunk.py +1 -1
- mistralai/models/timestampgranularity.py +1 -1
- mistralai/models/tool.py +2 -6
- mistralai/models/toolcall.py +2 -6
- mistralai/models/toolchoice.py +2 -6
- mistralai/models/toolchoiceenum.py +6 -1
- mistralai/models/toolexecutiondeltaevent.py +2 -1
- mistralai/models/toolexecutiondoneevent.py +2 -1
- mistralai/models/toolexecutionentry.py +4 -2
- mistralai/models/toolexecutionstartedevent.py +2 -1
- mistralai/models/toolfilechunk.py +13 -5
- mistralai/models/toolmessage.py +1 -1
- mistralai/models/toolreferencechunk.py +15 -5
- mistralai/models/tooltypes.py +1 -1
- mistralai/models/transcriptionsegmentchunk.py +1 -1
- mistralai/models/transcriptionstreamdone.py +1 -1
- mistralai/models/transcriptionstreamlanguage.py +1 -1
- mistralai/models/transcriptionstreamsegmentdelta.py +1 -1
- mistralai/models/transcriptionstreamtextdelta.py +1 -1
- mistralai/models/unarchiveftmodelout.py +1 -1
- mistralai/models/uploadfileout.py +3 -5
- mistralai/models/usermessage.py +1 -1
- mistralai/models/wandbintegration.py +1 -1
- mistralai/models/wandbintegrationout.py +1 -1
- mistralai/models/websearchpremiumtool.py +1 -1
- mistralai/models/websearchtool.py +1 -1
- mistralai/models_.py +24 -12
- mistralai/ocr.py +38 -10
- mistralai/sdk.py +2 -2
- mistralai/transcriptions.py +28 -12
- mistralai/types/basemodel.py +41 -3
- mistralai/utils/__init__.py +0 -3
- mistralai/utils/annotations.py +32 -8
- mistralai/utils/enums.py +60 -0
- mistralai/utils/forms.py +21 -10
- mistralai/utils/queryparams.py +14 -2
- mistralai/utils/requestbodies.py +3 -3
- mistralai/utils/retries.py +69 -5
- mistralai/utils/serializers.py +0 -20
- mistralai/utils/unmarshal_json_response.py +15 -1
- {mistralai-1.10.0.dist-info → mistralai-1.11.1.dist-info}/METADATA +144 -159
- mistralai-1.11.1.dist-info/RECORD +495 -0
- {mistralai-1.10.0.dist-info → mistralai-1.11.1.dist-info}/WHEEL +1 -1
- mistralai_azure/_version.py +3 -3
- mistralai_azure/basesdk.py +21 -5
- mistralai_azure/chat.py +82 -109
- mistralai_azure/httpclient.py +0 -1
- mistralai_azure/models/__init__.py +66 -4
- mistralai_azure/models/assistantmessage.py +1 -1
- mistralai_azure/models/chatcompletionchoice.py +10 -7
- mistralai_azure/models/chatcompletionrequest.py +24 -10
- mistralai_azure/models/chatcompletionstreamrequest.py +24 -10
- mistralai_azure/models/completionresponsestreamchoice.py +11 -7
- mistralai_azure/models/documenturlchunk.py +1 -1
- mistralai_azure/models/httpvalidationerror.py +15 -8
- mistralai_azure/models/imageurlchunk.py +1 -1
- mistralai_azure/models/mistralazureerror.py +30 -0
- mistralai_azure/models/mistralpromptmode.py +1 -1
- mistralai_azure/models/no_response_error.py +17 -0
- mistralai_azure/models/ocrpageobject.py +32 -5
- mistralai_azure/models/ocrrequest.py +20 -1
- mistralai_azure/models/ocrtableobject.py +34 -0
- mistralai_azure/models/prediction.py +4 -0
- mistralai_azure/models/referencechunk.py +1 -1
- mistralai_azure/models/responseformat.py +4 -2
- mistralai_azure/models/responseformats.py +5 -2
- mistralai_azure/models/responsevalidationerror.py +27 -0
- mistralai_azure/models/sdkerror.py +32 -14
- mistralai_azure/models/systemmessage.py +8 -4
- mistralai_azure/models/systemmessagecontentchunks.py +21 -0
- mistralai_azure/models/textchunk.py +1 -1
- mistralai_azure/models/thinkchunk.py +35 -0
- mistralai_azure/models/tool.py +2 -6
- mistralai_azure/models/toolcall.py +2 -6
- mistralai_azure/models/toolchoice.py +2 -6
- mistralai_azure/models/toolchoiceenum.py +6 -1
- mistralai_azure/models/toolmessage.py +1 -1
- mistralai_azure/models/tooltypes.py +1 -1
- mistralai_azure/models/usermessage.py +1 -1
- mistralai_azure/ocr.py +39 -40
- mistralai_azure/types/basemodel.py +41 -3
- mistralai_azure/utils/__init__.py +18 -8
- mistralai_azure/utils/annotations.py +32 -8
- mistralai_azure/utils/enums.py +60 -0
- mistralai_azure/utils/eventstreaming.py +10 -0
- mistralai_azure/utils/forms.py +21 -10
- mistralai_azure/utils/queryparams.py +14 -2
- mistralai_azure/utils/requestbodies.py +3 -3
- mistralai_azure/utils/retries.py +69 -5
- mistralai_azure/utils/serializers.py +3 -22
- mistralai_azure/utils/unmarshal_json_response.py +38 -0
- mistralai_gcp/_hooks/types.py +7 -0
- mistralai_gcp/_version.py +4 -4
- mistralai_gcp/basesdk.py +33 -25
- mistralai_gcp/chat.py +98 -109
- mistralai_gcp/fim.py +62 -85
- mistralai_gcp/httpclient.py +6 -17
- mistralai_gcp/models/__init__.py +321 -116
- mistralai_gcp/models/assistantmessage.py +2 -2
- mistralai_gcp/models/chatcompletionchoice.py +10 -7
- mistralai_gcp/models/chatcompletionrequest.py +38 -7
- mistralai_gcp/models/chatcompletionresponse.py +6 -6
- mistralai_gcp/models/chatcompletionstreamrequest.py +38 -7
- mistralai_gcp/models/completionresponsestreamchoice.py +12 -8
- mistralai_gcp/models/deltamessage.py +1 -1
- mistralai_gcp/models/fimcompletionrequest.py +9 -10
- mistralai_gcp/models/fimcompletionresponse.py +6 -6
- mistralai_gcp/models/fimcompletionstreamrequest.py +9 -10
- mistralai_gcp/models/httpvalidationerror.py +15 -8
- mistralai_gcp/models/imageurl.py +1 -1
- mistralai_gcp/models/imageurlchunk.py +1 -1
- mistralai_gcp/models/jsonschema.py +1 -1
- mistralai_gcp/models/mistralgcperror.py +30 -0
- mistralai_gcp/models/mistralpromptmode.py +8 -0
- mistralai_gcp/models/no_response_error.py +17 -0
- mistralai_gcp/models/prediction.py +4 -0
- mistralai_gcp/models/referencechunk.py +1 -1
- mistralai_gcp/models/responseformat.py +5 -3
- mistralai_gcp/models/responseformats.py +5 -2
- mistralai_gcp/models/responsevalidationerror.py +27 -0
- mistralai_gcp/models/sdkerror.py +32 -14
- mistralai_gcp/models/systemmessage.py +8 -4
- mistralai_gcp/models/systemmessagecontentchunks.py +21 -0
- mistralai_gcp/models/textchunk.py +1 -1
- mistralai_gcp/models/thinkchunk.py +35 -0
- mistralai_gcp/models/tool.py +2 -6
- mistralai_gcp/models/toolcall.py +2 -6
- mistralai_gcp/models/toolchoice.py +2 -6
- mistralai_gcp/models/toolchoiceenum.py +6 -1
- mistralai_gcp/models/toolmessage.py +2 -2
- mistralai_gcp/models/tooltypes.py +1 -1
- mistralai_gcp/models/usageinfo.py +71 -8
- mistralai_gcp/models/usermessage.py +2 -2
- mistralai_gcp/sdk.py +12 -10
- mistralai_gcp/sdkconfiguration.py +0 -7
- mistralai_gcp/types/basemodel.py +41 -3
- mistralai_gcp/utils/__init__.py +141 -46
- mistralai_gcp/utils/annotations.py +32 -8
- mistralai_gcp/utils/datetimes.py +23 -0
- mistralai_gcp/utils/enums.py +125 -25
- mistralai_gcp/utils/eventstreaming.py +10 -0
- mistralai_gcp/utils/forms.py +62 -30
- mistralai_gcp/utils/queryparams.py +14 -2
- mistralai_gcp/utils/requestbodies.py +3 -3
- mistralai_gcp/utils/retries.py +69 -5
- mistralai_gcp/utils/serializers.py +33 -23
- mistralai_gcp/utils/unmarshal_json_response.py +38 -0
- mistralai-1.10.0.dist-info/RECORD +0 -475
- {mistralai-1.10.0.dist-info → mistralai-1.11.1.dist-info}/licenses/LICENSE +0 -0
mistralai/models_.py
CHANGED
|
@@ -51,6 +51,7 @@ class Models(BaseSDK):
|
|
|
51
51
|
accept_header_value="application/json",
|
|
52
52
|
http_headers=http_headers,
|
|
53
53
|
security=self.sdk_configuration.security,
|
|
54
|
+
allow_empty_value=None,
|
|
54
55
|
timeout_ms=timeout_ms,
|
|
55
56
|
)
|
|
56
57
|
|
|
@@ -67,7 +68,7 @@ class Models(BaseSDK):
|
|
|
67
68
|
config=self.sdk_configuration,
|
|
68
69
|
base_url=base_url or "",
|
|
69
70
|
operation_id="list_models_v1_models_get",
|
|
70
|
-
oauth2_scopes=
|
|
71
|
+
oauth2_scopes=None,
|
|
71
72
|
security_source=get_security_from_env(
|
|
72
73
|
self.sdk_configuration.security, models.Security
|
|
73
74
|
),
|
|
@@ -127,6 +128,7 @@ class Models(BaseSDK):
|
|
|
127
128
|
accept_header_value="application/json",
|
|
128
129
|
http_headers=http_headers,
|
|
129
130
|
security=self.sdk_configuration.security,
|
|
131
|
+
allow_empty_value=None,
|
|
130
132
|
timeout_ms=timeout_ms,
|
|
131
133
|
)
|
|
132
134
|
|
|
@@ -143,7 +145,7 @@ class Models(BaseSDK):
|
|
|
143
145
|
config=self.sdk_configuration,
|
|
144
146
|
base_url=base_url or "",
|
|
145
147
|
operation_id="list_models_v1_models_get",
|
|
146
|
-
oauth2_scopes=
|
|
148
|
+
oauth2_scopes=None,
|
|
147
149
|
security_source=get_security_from_env(
|
|
148
150
|
self.sdk_configuration.security, models.Security
|
|
149
151
|
),
|
|
@@ -210,6 +212,7 @@ class Models(BaseSDK):
|
|
|
210
212
|
accept_header_value="application/json",
|
|
211
213
|
http_headers=http_headers,
|
|
212
214
|
security=self.sdk_configuration.security,
|
|
215
|
+
allow_empty_value=None,
|
|
213
216
|
timeout_ms=timeout_ms,
|
|
214
217
|
)
|
|
215
218
|
|
|
@@ -226,7 +229,7 @@ class Models(BaseSDK):
|
|
|
226
229
|
config=self.sdk_configuration,
|
|
227
230
|
base_url=base_url or "",
|
|
228
231
|
operation_id="retrieve_model_v1_models__model_id__get",
|
|
229
|
-
oauth2_scopes=
|
|
232
|
+
oauth2_scopes=None,
|
|
230
233
|
security_source=get_security_from_env(
|
|
231
234
|
self.sdk_configuration.security, models.Security
|
|
232
235
|
),
|
|
@@ -302,6 +305,7 @@ class Models(BaseSDK):
|
|
|
302
305
|
accept_header_value="application/json",
|
|
303
306
|
http_headers=http_headers,
|
|
304
307
|
security=self.sdk_configuration.security,
|
|
308
|
+
allow_empty_value=None,
|
|
305
309
|
timeout_ms=timeout_ms,
|
|
306
310
|
)
|
|
307
311
|
|
|
@@ -318,7 +322,7 @@ class Models(BaseSDK):
|
|
|
318
322
|
config=self.sdk_configuration,
|
|
319
323
|
base_url=base_url or "",
|
|
320
324
|
operation_id="retrieve_model_v1_models__model_id__get",
|
|
321
|
-
oauth2_scopes=
|
|
325
|
+
oauth2_scopes=None,
|
|
322
326
|
security_source=get_security_from_env(
|
|
323
327
|
self.sdk_configuration.security, models.Security
|
|
324
328
|
),
|
|
@@ -394,6 +398,7 @@ class Models(BaseSDK):
|
|
|
394
398
|
accept_header_value="application/json",
|
|
395
399
|
http_headers=http_headers,
|
|
396
400
|
security=self.sdk_configuration.security,
|
|
401
|
+
allow_empty_value=None,
|
|
397
402
|
timeout_ms=timeout_ms,
|
|
398
403
|
)
|
|
399
404
|
|
|
@@ -410,7 +415,7 @@ class Models(BaseSDK):
|
|
|
410
415
|
config=self.sdk_configuration,
|
|
411
416
|
base_url=base_url or "",
|
|
412
417
|
operation_id="delete_model_v1_models__model_id__delete",
|
|
413
|
-
oauth2_scopes=
|
|
418
|
+
oauth2_scopes=None,
|
|
414
419
|
security_source=get_security_from_env(
|
|
415
420
|
self.sdk_configuration.security, models.Security
|
|
416
421
|
),
|
|
@@ -483,6 +488,7 @@ class Models(BaseSDK):
|
|
|
483
488
|
accept_header_value="application/json",
|
|
484
489
|
http_headers=http_headers,
|
|
485
490
|
security=self.sdk_configuration.security,
|
|
491
|
+
allow_empty_value=None,
|
|
486
492
|
timeout_ms=timeout_ms,
|
|
487
493
|
)
|
|
488
494
|
|
|
@@ -499,7 +505,7 @@ class Models(BaseSDK):
|
|
|
499
505
|
config=self.sdk_configuration,
|
|
500
506
|
base_url=base_url or "",
|
|
501
507
|
operation_id="delete_model_v1_models__model_id__delete",
|
|
502
|
-
oauth2_scopes=
|
|
508
|
+
oauth2_scopes=None,
|
|
503
509
|
security_source=get_security_from_env(
|
|
504
510
|
self.sdk_configuration.security, models.Security
|
|
505
511
|
),
|
|
@@ -583,6 +589,7 @@ class Models(BaseSDK):
|
|
|
583
589
|
get_serialized_body=lambda: utils.serialize_request_body(
|
|
584
590
|
request.update_ft_model_in, False, False, "json", models.UpdateFTModelIn
|
|
585
591
|
),
|
|
592
|
+
allow_empty_value=None,
|
|
586
593
|
timeout_ms=timeout_ms,
|
|
587
594
|
)
|
|
588
595
|
|
|
@@ -599,7 +606,7 @@ class Models(BaseSDK):
|
|
|
599
606
|
config=self.sdk_configuration,
|
|
600
607
|
base_url=base_url or "",
|
|
601
608
|
operation_id="jobs_api_routes_fine_tuning_update_fine_tuned_model",
|
|
602
|
-
oauth2_scopes=
|
|
609
|
+
oauth2_scopes=None,
|
|
603
610
|
security_source=get_security_from_env(
|
|
604
611
|
self.sdk_configuration.security, models.Security
|
|
605
612
|
),
|
|
@@ -679,6 +686,7 @@ class Models(BaseSDK):
|
|
|
679
686
|
get_serialized_body=lambda: utils.serialize_request_body(
|
|
680
687
|
request.update_ft_model_in, False, False, "json", models.UpdateFTModelIn
|
|
681
688
|
),
|
|
689
|
+
allow_empty_value=None,
|
|
682
690
|
timeout_ms=timeout_ms,
|
|
683
691
|
)
|
|
684
692
|
|
|
@@ -695,7 +703,7 @@ class Models(BaseSDK):
|
|
|
695
703
|
config=self.sdk_configuration,
|
|
696
704
|
base_url=base_url or "",
|
|
697
705
|
operation_id="jobs_api_routes_fine_tuning_update_fine_tuned_model",
|
|
698
|
-
oauth2_scopes=
|
|
706
|
+
oauth2_scopes=None,
|
|
699
707
|
security_source=get_security_from_env(
|
|
700
708
|
self.sdk_configuration.security, models.Security
|
|
701
709
|
),
|
|
@@ -764,6 +772,7 @@ class Models(BaseSDK):
|
|
|
764
772
|
accept_header_value="application/json",
|
|
765
773
|
http_headers=http_headers,
|
|
766
774
|
security=self.sdk_configuration.security,
|
|
775
|
+
allow_empty_value=None,
|
|
767
776
|
timeout_ms=timeout_ms,
|
|
768
777
|
)
|
|
769
778
|
|
|
@@ -780,7 +789,7 @@ class Models(BaseSDK):
|
|
|
780
789
|
config=self.sdk_configuration,
|
|
781
790
|
base_url=base_url or "",
|
|
782
791
|
operation_id="jobs_api_routes_fine_tuning_archive_fine_tuned_model",
|
|
783
|
-
oauth2_scopes=
|
|
792
|
+
oauth2_scopes=None,
|
|
784
793
|
security_source=get_security_from_env(
|
|
785
794
|
self.sdk_configuration.security, models.Security
|
|
786
795
|
),
|
|
@@ -847,6 +856,7 @@ class Models(BaseSDK):
|
|
|
847
856
|
accept_header_value="application/json",
|
|
848
857
|
http_headers=http_headers,
|
|
849
858
|
security=self.sdk_configuration.security,
|
|
859
|
+
allow_empty_value=None,
|
|
850
860
|
timeout_ms=timeout_ms,
|
|
851
861
|
)
|
|
852
862
|
|
|
@@ -863,7 +873,7 @@ class Models(BaseSDK):
|
|
|
863
873
|
config=self.sdk_configuration,
|
|
864
874
|
base_url=base_url or "",
|
|
865
875
|
operation_id="jobs_api_routes_fine_tuning_archive_fine_tuned_model",
|
|
866
|
-
oauth2_scopes=
|
|
876
|
+
oauth2_scopes=None,
|
|
867
877
|
security_source=get_security_from_env(
|
|
868
878
|
self.sdk_configuration.security, models.Security
|
|
869
879
|
),
|
|
@@ -930,6 +940,7 @@ class Models(BaseSDK):
|
|
|
930
940
|
accept_header_value="application/json",
|
|
931
941
|
http_headers=http_headers,
|
|
932
942
|
security=self.sdk_configuration.security,
|
|
943
|
+
allow_empty_value=None,
|
|
933
944
|
timeout_ms=timeout_ms,
|
|
934
945
|
)
|
|
935
946
|
|
|
@@ -946,7 +957,7 @@ class Models(BaseSDK):
|
|
|
946
957
|
config=self.sdk_configuration,
|
|
947
958
|
base_url=base_url or "",
|
|
948
959
|
operation_id="jobs_api_routes_fine_tuning_unarchive_fine_tuned_model",
|
|
949
|
-
oauth2_scopes=
|
|
960
|
+
oauth2_scopes=None,
|
|
950
961
|
security_source=get_security_from_env(
|
|
951
962
|
self.sdk_configuration.security, models.Security
|
|
952
963
|
),
|
|
@@ -1013,6 +1024,7 @@ class Models(BaseSDK):
|
|
|
1013
1024
|
accept_header_value="application/json",
|
|
1014
1025
|
http_headers=http_headers,
|
|
1015
1026
|
security=self.sdk_configuration.security,
|
|
1027
|
+
allow_empty_value=None,
|
|
1016
1028
|
timeout_ms=timeout_ms,
|
|
1017
1029
|
)
|
|
1018
1030
|
|
|
@@ -1029,7 +1041,7 @@ class Models(BaseSDK):
|
|
|
1029
1041
|
config=self.sdk_configuration,
|
|
1030
1042
|
base_url=base_url or "",
|
|
1031
1043
|
operation_id="jobs_api_routes_fine_tuning_unarchive_fine_tuned_model",
|
|
1032
|
-
oauth2_scopes=
|
|
1044
|
+
oauth2_scopes=None,
|
|
1033
1045
|
security_source=get_security_from_env(
|
|
1034
1046
|
self.sdk_configuration.security, models.Security
|
|
1035
1047
|
),
|
mistralai/ocr.py
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
from .basesdk import BaseSDK
|
|
4
4
|
from mistralai import models, utils
|
|
5
5
|
from mistralai._hooks import HookContext
|
|
6
|
+
from mistralai.models import (
|
|
7
|
+
ocrrequest as models_ocrrequest,
|
|
8
|
+
responseformat as models_responseformat,
|
|
9
|
+
)
|
|
6
10
|
from mistralai.types import Nullable, OptionalNullable, UNSET
|
|
7
11
|
from mistralai.utils import get_security_from_env
|
|
8
12
|
from mistralai.utils.unmarshal_json_response import unmarshal_json_response
|
|
@@ -16,19 +20,28 @@ class Ocr(BaseSDK):
|
|
|
16
20
|
self,
|
|
17
21
|
*,
|
|
18
22
|
model: Nullable[str],
|
|
19
|
-
document: Union[
|
|
23
|
+
document: Union[
|
|
24
|
+
models_ocrrequest.Document, models_ocrrequest.DocumentTypedDict
|
|
25
|
+
],
|
|
20
26
|
id: Optional[str] = None,
|
|
21
27
|
pages: OptionalNullable[List[int]] = UNSET,
|
|
22
28
|
include_image_base64: OptionalNullable[bool] = UNSET,
|
|
23
29
|
image_limit: OptionalNullable[int] = UNSET,
|
|
24
30
|
image_min_size: OptionalNullable[int] = UNSET,
|
|
25
31
|
bbox_annotation_format: OptionalNullable[
|
|
26
|
-
Union[
|
|
32
|
+
Union[
|
|
33
|
+
models_responseformat.ResponseFormat,
|
|
34
|
+
models_responseformat.ResponseFormatTypedDict,
|
|
35
|
+
]
|
|
27
36
|
] = UNSET,
|
|
28
37
|
document_annotation_format: OptionalNullable[
|
|
29
|
-
Union[
|
|
38
|
+
Union[
|
|
39
|
+
models_responseformat.ResponseFormat,
|
|
40
|
+
models_responseformat.ResponseFormatTypedDict,
|
|
41
|
+
]
|
|
30
42
|
] = UNSET,
|
|
31
|
-
|
|
43
|
+
document_annotation_prompt: OptionalNullable[str] = UNSET,
|
|
44
|
+
table_format: OptionalNullable[models_ocrrequest.TableFormat] = UNSET,
|
|
32
45
|
extract_header: Optional[bool] = None,
|
|
33
46
|
extract_footer: Optional[bool] = None,
|
|
34
47
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
@@ -47,6 +60,7 @@ class Ocr(BaseSDK):
|
|
|
47
60
|
:param image_min_size: Minimum height and width of image to extract
|
|
48
61
|
: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
|
|
49
62
|
:param document_annotation_format: Structured output class for extracting useful information from the entire document. Only json_schema is valid for this field
|
|
63
|
+
:param document_annotation_prompt: Optional prompt to guide the model in extracting structured output from the entire document. A document_annotation_format must be provided.
|
|
50
64
|
:param table_format:
|
|
51
65
|
:param extract_header:
|
|
52
66
|
:param extract_footer:
|
|
@@ -79,6 +93,7 @@ class Ocr(BaseSDK):
|
|
|
79
93
|
document_annotation_format=utils.get_pydantic_model(
|
|
80
94
|
document_annotation_format, OptionalNullable[models.ResponseFormat]
|
|
81
95
|
),
|
|
96
|
+
document_annotation_prompt=document_annotation_prompt,
|
|
82
97
|
table_format=table_format,
|
|
83
98
|
extract_header=extract_header,
|
|
84
99
|
extract_footer=extract_footer,
|
|
@@ -100,6 +115,7 @@ class Ocr(BaseSDK):
|
|
|
100
115
|
get_serialized_body=lambda: utils.serialize_request_body(
|
|
101
116
|
request, False, False, "json", models.OCRRequest
|
|
102
117
|
),
|
|
118
|
+
allow_empty_value=None,
|
|
103
119
|
timeout_ms=timeout_ms,
|
|
104
120
|
)
|
|
105
121
|
|
|
@@ -116,7 +132,7 @@ class Ocr(BaseSDK):
|
|
|
116
132
|
config=self.sdk_configuration,
|
|
117
133
|
base_url=base_url or "",
|
|
118
134
|
operation_id="ocr_v1_ocr_post",
|
|
119
|
-
oauth2_scopes=
|
|
135
|
+
oauth2_scopes=None,
|
|
120
136
|
security_source=get_security_from_env(
|
|
121
137
|
self.sdk_configuration.security, models.Security
|
|
122
138
|
),
|
|
@@ -147,19 +163,28 @@ class Ocr(BaseSDK):
|
|
|
147
163
|
self,
|
|
148
164
|
*,
|
|
149
165
|
model: Nullable[str],
|
|
150
|
-
document: Union[
|
|
166
|
+
document: Union[
|
|
167
|
+
models_ocrrequest.Document, models_ocrrequest.DocumentTypedDict
|
|
168
|
+
],
|
|
151
169
|
id: Optional[str] = None,
|
|
152
170
|
pages: OptionalNullable[List[int]] = UNSET,
|
|
153
171
|
include_image_base64: OptionalNullable[bool] = UNSET,
|
|
154
172
|
image_limit: OptionalNullable[int] = UNSET,
|
|
155
173
|
image_min_size: OptionalNullable[int] = UNSET,
|
|
156
174
|
bbox_annotation_format: OptionalNullable[
|
|
157
|
-
Union[
|
|
175
|
+
Union[
|
|
176
|
+
models_responseformat.ResponseFormat,
|
|
177
|
+
models_responseformat.ResponseFormatTypedDict,
|
|
178
|
+
]
|
|
158
179
|
] = UNSET,
|
|
159
180
|
document_annotation_format: OptionalNullable[
|
|
160
|
-
Union[
|
|
181
|
+
Union[
|
|
182
|
+
models_responseformat.ResponseFormat,
|
|
183
|
+
models_responseformat.ResponseFormatTypedDict,
|
|
184
|
+
]
|
|
161
185
|
] = UNSET,
|
|
162
|
-
|
|
186
|
+
document_annotation_prompt: OptionalNullable[str] = UNSET,
|
|
187
|
+
table_format: OptionalNullable[models_ocrrequest.TableFormat] = UNSET,
|
|
163
188
|
extract_header: Optional[bool] = None,
|
|
164
189
|
extract_footer: Optional[bool] = None,
|
|
165
190
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
@@ -178,6 +203,7 @@ class Ocr(BaseSDK):
|
|
|
178
203
|
:param image_min_size: Minimum height and width of image to extract
|
|
179
204
|
: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
|
|
180
205
|
:param document_annotation_format: Structured output class for extracting useful information from the entire document. Only json_schema is valid for this field
|
|
206
|
+
:param document_annotation_prompt: Optional prompt to guide the model in extracting structured output from the entire document. A document_annotation_format must be provided.
|
|
181
207
|
:param table_format:
|
|
182
208
|
:param extract_header:
|
|
183
209
|
:param extract_footer:
|
|
@@ -210,6 +236,7 @@ class Ocr(BaseSDK):
|
|
|
210
236
|
document_annotation_format=utils.get_pydantic_model(
|
|
211
237
|
document_annotation_format, OptionalNullable[models.ResponseFormat]
|
|
212
238
|
),
|
|
239
|
+
document_annotation_prompt=document_annotation_prompt,
|
|
213
240
|
table_format=table_format,
|
|
214
241
|
extract_header=extract_header,
|
|
215
242
|
extract_footer=extract_footer,
|
|
@@ -231,6 +258,7 @@ class Ocr(BaseSDK):
|
|
|
231
258
|
get_serialized_body=lambda: utils.serialize_request_body(
|
|
232
259
|
request, False, False, "json", models.OCRRequest
|
|
233
260
|
),
|
|
261
|
+
allow_empty_value=None,
|
|
234
262
|
timeout_ms=timeout_ms,
|
|
235
263
|
)
|
|
236
264
|
|
|
@@ -247,7 +275,7 @@ class Ocr(BaseSDK):
|
|
|
247
275
|
config=self.sdk_configuration,
|
|
248
276
|
base_url=base_url or "",
|
|
249
277
|
operation_id="ocr_v1_ocr_post",
|
|
250
|
-
oauth2_scopes=
|
|
278
|
+
oauth2_scopes=None,
|
|
251
279
|
security_source=get_security_from_env(
|
|
252
280
|
self.sdk_configuration.security, models.Security
|
|
253
281
|
),
|
mistralai/sdk.py
CHANGED
|
@@ -92,7 +92,7 @@ class Mistral(BaseSDK):
|
|
|
92
92
|
"""
|
|
93
93
|
client_supplied = True
|
|
94
94
|
if client is None:
|
|
95
|
-
client = httpx.Client()
|
|
95
|
+
client = httpx.Client(follow_redirects=True)
|
|
96
96
|
client_supplied = False
|
|
97
97
|
|
|
98
98
|
assert issubclass(
|
|
@@ -101,7 +101,7 @@ class Mistral(BaseSDK):
|
|
|
101
101
|
|
|
102
102
|
async_client_supplied = True
|
|
103
103
|
if async_client is None:
|
|
104
|
-
async_client = httpx.AsyncClient()
|
|
104
|
+
async_client = httpx.AsyncClient(follow_redirects=True)
|
|
105
105
|
async_client_supplied = False
|
|
106
106
|
|
|
107
107
|
if debug_logger is None:
|
mistralai/transcriptions.py
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
from .basesdk import BaseSDK
|
|
4
4
|
from mistralai import models, utils
|
|
5
5
|
from mistralai._hooks import HookContext
|
|
6
|
+
from mistralai.models import (
|
|
7
|
+
file as models_file,
|
|
8
|
+
timestampgranularity as models_timestampgranularity,
|
|
9
|
+
)
|
|
6
10
|
from mistralai.types import OptionalNullable, UNSET
|
|
7
11
|
from mistralai.utils import eventstreaming, get_security_from_env
|
|
8
12
|
from mistralai.utils.unmarshal_json_response import unmarshal_json_response
|
|
@@ -16,12 +20,14 @@ class Transcriptions(BaseSDK):
|
|
|
16
20
|
self,
|
|
17
21
|
*,
|
|
18
22
|
model: str,
|
|
19
|
-
file: Optional[Union[
|
|
23
|
+
file: Optional[Union[models_file.File, models_file.FileTypedDict]] = None,
|
|
20
24
|
file_url: OptionalNullable[str] = UNSET,
|
|
21
25
|
file_id: OptionalNullable[str] = UNSET,
|
|
22
26
|
language: OptionalNullable[str] = UNSET,
|
|
23
27
|
temperature: OptionalNullable[float] = UNSET,
|
|
24
|
-
timestamp_granularities: Optional[
|
|
28
|
+
timestamp_granularities: Optional[
|
|
29
|
+
List[models_timestampgranularity.TimestampGranularity]
|
|
30
|
+
] = None,
|
|
25
31
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
26
32
|
server_url: Optional[str] = None,
|
|
27
33
|
timeout_ms: Optional[int] = None,
|
|
@@ -77,6 +83,7 @@ class Transcriptions(BaseSDK):
|
|
|
77
83
|
get_serialized_body=lambda: utils.serialize_request_body(
|
|
78
84
|
request, False, False, "multipart", models.AudioTranscriptionRequest
|
|
79
85
|
),
|
|
86
|
+
allow_empty_value=None,
|
|
80
87
|
timeout_ms=timeout_ms,
|
|
81
88
|
)
|
|
82
89
|
|
|
@@ -93,7 +100,7 @@ class Transcriptions(BaseSDK):
|
|
|
93
100
|
config=self.sdk_configuration,
|
|
94
101
|
base_url=base_url or "",
|
|
95
102
|
operation_id="audio_api_v1_transcriptions_post",
|
|
96
|
-
oauth2_scopes=
|
|
103
|
+
oauth2_scopes=None,
|
|
97
104
|
security_source=get_security_from_env(
|
|
98
105
|
self.sdk_configuration.security, models.Security
|
|
99
106
|
),
|
|
@@ -118,12 +125,14 @@ class Transcriptions(BaseSDK):
|
|
|
118
125
|
self,
|
|
119
126
|
*,
|
|
120
127
|
model: str,
|
|
121
|
-
file: Optional[Union[
|
|
128
|
+
file: Optional[Union[models_file.File, models_file.FileTypedDict]] = None,
|
|
122
129
|
file_url: OptionalNullable[str] = UNSET,
|
|
123
130
|
file_id: OptionalNullable[str] = UNSET,
|
|
124
131
|
language: OptionalNullable[str] = UNSET,
|
|
125
132
|
temperature: OptionalNullable[float] = UNSET,
|
|
126
|
-
timestamp_granularities: Optional[
|
|
133
|
+
timestamp_granularities: Optional[
|
|
134
|
+
List[models_timestampgranularity.TimestampGranularity]
|
|
135
|
+
] = None,
|
|
127
136
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
128
137
|
server_url: Optional[str] = None,
|
|
129
138
|
timeout_ms: Optional[int] = None,
|
|
@@ -179,6 +188,7 @@ class Transcriptions(BaseSDK):
|
|
|
179
188
|
get_serialized_body=lambda: utils.serialize_request_body(
|
|
180
189
|
request, False, False, "multipart", models.AudioTranscriptionRequest
|
|
181
190
|
),
|
|
191
|
+
allow_empty_value=None,
|
|
182
192
|
timeout_ms=timeout_ms,
|
|
183
193
|
)
|
|
184
194
|
|
|
@@ -195,7 +205,7 @@ class Transcriptions(BaseSDK):
|
|
|
195
205
|
config=self.sdk_configuration,
|
|
196
206
|
base_url=base_url or "",
|
|
197
207
|
operation_id="audio_api_v1_transcriptions_post",
|
|
198
|
-
oauth2_scopes=
|
|
208
|
+
oauth2_scopes=None,
|
|
199
209
|
security_source=get_security_from_env(
|
|
200
210
|
self.sdk_configuration.security, models.Security
|
|
201
211
|
),
|
|
@@ -220,12 +230,14 @@ class Transcriptions(BaseSDK):
|
|
|
220
230
|
self,
|
|
221
231
|
*,
|
|
222
232
|
model: str,
|
|
223
|
-
file: Optional[Union[
|
|
233
|
+
file: Optional[Union[models_file.File, models_file.FileTypedDict]] = None,
|
|
224
234
|
file_url: OptionalNullable[str] = UNSET,
|
|
225
235
|
file_id: OptionalNullable[str] = UNSET,
|
|
226
236
|
language: OptionalNullable[str] = UNSET,
|
|
227
237
|
temperature: OptionalNullable[float] = UNSET,
|
|
228
|
-
timestamp_granularities: Optional[
|
|
238
|
+
timestamp_granularities: Optional[
|
|
239
|
+
List[models_timestampgranularity.TimestampGranularity]
|
|
240
|
+
] = None,
|
|
229
241
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
230
242
|
server_url: Optional[str] = None,
|
|
231
243
|
timeout_ms: Optional[int] = None,
|
|
@@ -285,6 +297,7 @@ class Transcriptions(BaseSDK):
|
|
|
285
297
|
"multipart",
|
|
286
298
|
models.AudioTranscriptionRequestStream,
|
|
287
299
|
),
|
|
300
|
+
allow_empty_value=None,
|
|
288
301
|
timeout_ms=timeout_ms,
|
|
289
302
|
)
|
|
290
303
|
|
|
@@ -301,7 +314,7 @@ class Transcriptions(BaseSDK):
|
|
|
301
314
|
config=self.sdk_configuration,
|
|
302
315
|
base_url=base_url or "",
|
|
303
316
|
operation_id="audio_api_v1_transcriptions_post_stream",
|
|
304
|
-
oauth2_scopes=
|
|
317
|
+
oauth2_scopes=None,
|
|
305
318
|
security_source=get_security_from_env(
|
|
306
319
|
self.sdk_configuration.security, models.Security
|
|
307
320
|
),
|
|
@@ -332,12 +345,14 @@ class Transcriptions(BaseSDK):
|
|
|
332
345
|
self,
|
|
333
346
|
*,
|
|
334
347
|
model: str,
|
|
335
|
-
file: Optional[Union[
|
|
348
|
+
file: Optional[Union[models_file.File, models_file.FileTypedDict]] = None,
|
|
336
349
|
file_url: OptionalNullable[str] = UNSET,
|
|
337
350
|
file_id: OptionalNullable[str] = UNSET,
|
|
338
351
|
language: OptionalNullable[str] = UNSET,
|
|
339
352
|
temperature: OptionalNullable[float] = UNSET,
|
|
340
|
-
timestamp_granularities: Optional[
|
|
353
|
+
timestamp_granularities: Optional[
|
|
354
|
+
List[models_timestampgranularity.TimestampGranularity]
|
|
355
|
+
] = None,
|
|
341
356
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
342
357
|
server_url: Optional[str] = None,
|
|
343
358
|
timeout_ms: Optional[int] = None,
|
|
@@ -397,6 +412,7 @@ class Transcriptions(BaseSDK):
|
|
|
397
412
|
"multipart",
|
|
398
413
|
models.AudioTranscriptionRequestStream,
|
|
399
414
|
),
|
|
415
|
+
allow_empty_value=None,
|
|
400
416
|
timeout_ms=timeout_ms,
|
|
401
417
|
)
|
|
402
418
|
|
|
@@ -413,7 +429,7 @@ class Transcriptions(BaseSDK):
|
|
|
413
429
|
config=self.sdk_configuration,
|
|
414
430
|
base_url=base_url or "",
|
|
415
431
|
operation_id="audio_api_v1_transcriptions_post_stream",
|
|
416
|
-
oauth2_scopes=
|
|
432
|
+
oauth2_scopes=None,
|
|
417
433
|
security_source=get_security_from_env(
|
|
418
434
|
self.sdk_configuration.security, models.Security
|
|
419
435
|
),
|
mistralai/types/basemodel.py
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
from pydantic import ConfigDict, model_serializer
|
|
4
4
|
from pydantic import BaseModel as PydanticBaseModel
|
|
5
|
-
from
|
|
5
|
+
from pydantic_core import core_schema
|
|
6
|
+
from typing import TYPE_CHECKING, Any, Literal, Optional, TypeVar, Union
|
|
6
7
|
from typing_extensions import TypeAliasType, TypeAlias
|
|
7
8
|
|
|
8
9
|
|
|
@@ -35,5 +36,42 @@ else:
|
|
|
35
36
|
"OptionalNullable", Union[Optional[Nullable[T]], Unset], type_params=(T,)
|
|
36
37
|
)
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
UnrecognizedStr:
|
|
39
|
+
|
|
40
|
+
class UnrecognizedStr(str):
|
|
41
|
+
@classmethod
|
|
42
|
+
def __get_pydantic_core_schema__(cls, _source_type: Any, _handler: Any) -> core_schema.CoreSchema:
|
|
43
|
+
# Make UnrecognizedStr only work in lax mode, not strict mode
|
|
44
|
+
# This makes it a "fallback" option when more specific types (like Literals) don't match
|
|
45
|
+
def validate_lax(v: Any) -> 'UnrecognizedStr':
|
|
46
|
+
if isinstance(v, cls):
|
|
47
|
+
return v
|
|
48
|
+
return cls(str(v))
|
|
49
|
+
|
|
50
|
+
# Use lax_or_strict_schema where strict always fails
|
|
51
|
+
# This forces Pydantic to prefer other union members in strict mode
|
|
52
|
+
# and only fall back to UnrecognizedStr in lax mode
|
|
53
|
+
return core_schema.lax_or_strict_schema(
|
|
54
|
+
lax_schema=core_schema.chain_schema([
|
|
55
|
+
core_schema.str_schema(),
|
|
56
|
+
core_schema.no_info_plain_validator_function(validate_lax)
|
|
57
|
+
]),
|
|
58
|
+
strict_schema=core_schema.none_schema(), # Always fails in strict mode
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class UnrecognizedInt(int):
|
|
63
|
+
@classmethod
|
|
64
|
+
def __get_pydantic_core_schema__(cls, _source_type: Any, _handler: Any) -> core_schema.CoreSchema:
|
|
65
|
+
# Make UnrecognizedInt only work in lax mode, not strict mode
|
|
66
|
+
# This makes it a "fallback" option when more specific types (like Literals) don't match
|
|
67
|
+
def validate_lax(v: Any) -> 'UnrecognizedInt':
|
|
68
|
+
if isinstance(v, cls):
|
|
69
|
+
return v
|
|
70
|
+
return cls(int(v))
|
|
71
|
+
return core_schema.lax_or_strict_schema(
|
|
72
|
+
lax_schema=core_schema.chain_schema([
|
|
73
|
+
core_schema.int_schema(),
|
|
74
|
+
core_schema.no_info_plain_validator_function(validate_lax)
|
|
75
|
+
]),
|
|
76
|
+
strict_schema=core_schema.none_schema(), # Always fails in strict mode
|
|
77
|
+
)
|
mistralai/utils/__init__.py
CHANGED
|
@@ -42,7 +42,6 @@ if TYPE_CHECKING:
|
|
|
42
42
|
validate_decimal,
|
|
43
43
|
validate_float,
|
|
44
44
|
validate_int,
|
|
45
|
-
validate_open_enum,
|
|
46
45
|
)
|
|
47
46
|
from .url import generate_url, template_url, remove_suffix
|
|
48
47
|
from .values import (
|
|
@@ -104,7 +103,6 @@ __all__ = [
|
|
|
104
103
|
"validate_const",
|
|
105
104
|
"validate_float",
|
|
106
105
|
"validate_int",
|
|
107
|
-
"validate_open_enum",
|
|
108
106
|
"cast_partial",
|
|
109
107
|
]
|
|
110
108
|
|
|
@@ -158,7 +156,6 @@ _dynamic_imports: dict[str, str] = {
|
|
|
158
156
|
"validate_const": ".serializers",
|
|
159
157
|
"validate_float": ".serializers",
|
|
160
158
|
"validate_int": ".serializers",
|
|
161
|
-
"validate_open_enum": ".serializers",
|
|
162
159
|
"cast_partial": ".values",
|
|
163
160
|
}
|
|
164
161
|
|
mistralai/utils/annotations.py
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
from enum import Enum
|
|
4
4
|
from typing import Any, Optional
|
|
5
5
|
|
|
6
|
+
|
|
6
7
|
def get_discriminator(model: Any, fieldname: str, key: str) -> str:
|
|
7
8
|
"""
|
|
8
9
|
Recursively search for the discriminator attribute in a model.
|
|
@@ -25,31 +26,54 @@ def get_discriminator(model: Any, fieldname: str, key: str) -> str:
|
|
|
25
26
|
|
|
26
27
|
if isinstance(field, dict):
|
|
27
28
|
if key in field:
|
|
28
|
-
return f
|
|
29
|
+
return f"{field[key]}"
|
|
29
30
|
|
|
30
31
|
if hasattr(field, fieldname):
|
|
31
32
|
attr = getattr(field, fieldname)
|
|
32
33
|
if isinstance(attr, Enum):
|
|
33
|
-
return f
|
|
34
|
-
return f
|
|
34
|
+
return f"{attr.value}"
|
|
35
|
+
return f"{attr}"
|
|
35
36
|
|
|
36
37
|
if hasattr(field, upper_fieldname):
|
|
37
38
|
attr = getattr(field, upper_fieldname)
|
|
38
39
|
if isinstance(attr, Enum):
|
|
39
|
-
return f
|
|
40
|
-
return f
|
|
40
|
+
return f"{attr.value}"
|
|
41
|
+
return f"{attr}"
|
|
41
42
|
|
|
42
43
|
return None
|
|
43
44
|
|
|
45
|
+
def search_nested_discriminator(obj: Any) -> Optional[str]:
|
|
46
|
+
"""Recursively search for discriminator in nested structures."""
|
|
47
|
+
# First try direct field lookup
|
|
48
|
+
discriminator = get_field_discriminator(obj)
|
|
49
|
+
if discriminator is not None:
|
|
50
|
+
return discriminator
|
|
51
|
+
|
|
52
|
+
# If it's a dict, search in nested values
|
|
53
|
+
if isinstance(obj, dict):
|
|
54
|
+
for value in obj.values():
|
|
55
|
+
if isinstance(value, list):
|
|
56
|
+
# Search in list items
|
|
57
|
+
for item in value:
|
|
58
|
+
nested_discriminator = search_nested_discriminator(item)
|
|
59
|
+
if nested_discriminator is not None:
|
|
60
|
+
return nested_discriminator
|
|
61
|
+
elif isinstance(value, dict):
|
|
62
|
+
# Search in nested dict
|
|
63
|
+
nested_discriminator = search_nested_discriminator(value)
|
|
64
|
+
if nested_discriminator is not None:
|
|
65
|
+
return nested_discriminator
|
|
66
|
+
|
|
67
|
+
return None
|
|
44
68
|
|
|
45
69
|
if isinstance(model, list):
|
|
46
70
|
for field in model:
|
|
47
|
-
discriminator =
|
|
71
|
+
discriminator = search_nested_discriminator(field)
|
|
48
72
|
if discriminator is not None:
|
|
49
73
|
return discriminator
|
|
50
74
|
|
|
51
|
-
discriminator =
|
|
75
|
+
discriminator = search_nested_discriminator(model)
|
|
52
76
|
if discriminator is not None:
|
|
53
77
|
return discriminator
|
|
54
78
|
|
|
55
|
-
raise ValueError(f
|
|
79
|
+
raise ValueError(f"Could not find discriminator field {fieldname} in {model}")
|