mistralai 1.9.9__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.
Files changed (42) hide show
  1. mistralai/_version.py +3 -3
  2. mistralai/accesses.py +43 -108
  3. mistralai/agents.py +29 -68
  4. mistralai/audio.py +8 -3
  5. mistralai/basesdk.py +15 -5
  6. mistralai/batch.py +6 -3
  7. mistralai/beta.py +10 -5
  8. mistralai/chat.py +29 -68
  9. mistralai/classifiers.py +57 -144
  10. mistralai/conversations.py +143 -352
  11. mistralai/documents.py +137 -356
  12. mistralai/embeddings.py +21 -36
  13. mistralai/files.py +47 -176
  14. mistralai/fim.py +29 -68
  15. mistralai/fine_tuning.py +6 -3
  16. mistralai/jobs.py +49 -158
  17. mistralai/libraries.py +71 -178
  18. mistralai/mistral_agents.py +71 -180
  19. mistralai/mistral_jobs.py +41 -128
  20. mistralai/models/__init__.py +36 -3
  21. mistralai/models/apiendpoint.py +5 -0
  22. mistralai/models/embeddingrequest.py +5 -1
  23. mistralai/models/encodingformat.py +7 -0
  24. mistralai/models/httpvalidationerror.py +11 -6
  25. mistralai/models/mistralerror.py +26 -0
  26. mistralai/models/no_response_error.py +13 -0
  27. mistralai/models/responsevalidationerror.py +25 -0
  28. mistralai/models/sdkerror.py +30 -14
  29. mistralai/models/systemmessage.py +7 -3
  30. mistralai/models/systemmessagecontentchunks.py +21 -0
  31. mistralai/models_.py +71 -204
  32. mistralai/ocr.py +15 -36
  33. mistralai/sdk.py +15 -2
  34. mistralai/transcriptions.py +17 -56
  35. mistralai/utils/__init__.py +18 -5
  36. mistralai/utils/eventstreaming.py +10 -0
  37. mistralai/utils/serializers.py +3 -2
  38. mistralai/utils/unmarshal_json_response.py +24 -0
  39. {mistralai-1.9.9.dist-info → mistralai-1.9.11.dist-info}/METADATA +61 -30
  40. {mistralai-1.9.9.dist-info → mistralai-1.9.11.dist-info}/RECORD +42 -36
  41. {mistralai-1.9.9.dist-info → mistralai-1.9.11.dist-info}/WHEEL +1 -1
  42. {mistralai-1.9.9.dist-info → mistralai-1.9.11.dist-info/licenses}/LICENSE +0 -0
mistralai/fine_tuning.py CHANGED
@@ -3,15 +3,18 @@
3
3
  from .basesdk import BaseSDK
4
4
  from .sdkconfiguration import SDKConfiguration
5
5
  from mistralai.jobs import Jobs
6
+ from typing import Optional
6
7
 
7
8
 
8
9
  class FineTuning(BaseSDK):
9
10
  jobs: Jobs
10
11
 
11
- def __init__(self, sdk_config: SDKConfiguration) -> None:
12
- BaseSDK.__init__(self, sdk_config)
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 = Jobs(self.sdk_configuration)
20
+ self.jobs = Jobs(self.sdk_configuration, parent_ref=self.parent_ref)
mistralai/jobs.py CHANGED
@@ -6,6 +6,7 @@ from mistralai import models, utils
6
6
  from mistralai._hooks import HookContext
7
7
  from mistralai.types import OptionalNullable, UNSET
8
8
  from mistralai.utils import get_security_from_env
9
+ from mistralai.utils.unmarshal_json_response import unmarshal_json_response
9
10
  from typing import List, Mapping, Optional, Union
10
11
 
11
12
 
@@ -110,26 +111,15 @@ class Jobs(BaseSDK):
110
111
  )
111
112
 
112
113
  if utils.match_response(http_res, "200", "application/json"):
113
- return utils.unmarshal_json(http_res.text, models.JobsOut)
114
+ return unmarshal_json_response(models.JobsOut, http_res)
114
115
  if utils.match_response(http_res, "4XX", "*"):
115
116
  http_res_text = utils.stream_to_text(http_res)
116
- raise models.SDKError(
117
- "API error occurred", http_res.status_code, http_res_text, http_res
118
- )
117
+ raise models.SDKError("API error occurred", http_res, http_res_text)
119
118
  if utils.match_response(http_res, "5XX", "*"):
120
119
  http_res_text = utils.stream_to_text(http_res)
121
- raise models.SDKError(
122
- "API error occurred", http_res.status_code, http_res_text, http_res
123
- )
120
+ raise models.SDKError("API error occurred", http_res, http_res_text)
124
121
 
125
- content_type = http_res.headers.get("Content-Type")
126
- http_res_text = utils.stream_to_text(http_res)
127
- raise models.SDKError(
128
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
129
- http_res.status_code,
130
- http_res_text,
131
- http_res,
132
- )
122
+ raise models.SDKError("Unexpected response received", http_res)
133
123
 
134
124
  async def list_async(
135
125
  self,
@@ -231,26 +221,15 @@ class Jobs(BaseSDK):
231
221
  )
232
222
 
233
223
  if utils.match_response(http_res, "200", "application/json"):
234
- return utils.unmarshal_json(http_res.text, models.JobsOut)
224
+ return unmarshal_json_response(models.JobsOut, http_res)
235
225
  if utils.match_response(http_res, "4XX", "*"):
236
226
  http_res_text = await utils.stream_to_text_async(http_res)
237
- raise models.SDKError(
238
- "API error occurred", http_res.status_code, http_res_text, http_res
239
- )
227
+ raise models.SDKError("API error occurred", http_res, http_res_text)
240
228
  if utils.match_response(http_res, "5XX", "*"):
241
229
  http_res_text = await utils.stream_to_text_async(http_res)
242
- raise models.SDKError(
243
- "API error occurred", http_res.status_code, http_res_text, http_res
244
- )
230
+ raise models.SDKError("API error occurred", http_res, http_res_text)
245
231
 
246
- content_type = http_res.headers.get("Content-Type")
247
- http_res_text = await utils.stream_to_text_async(http_res)
248
- raise models.SDKError(
249
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
250
- http_res.status_code,
251
- http_res_text,
252
- http_res,
253
- )
232
+ raise models.SDKError("Unexpected response received", http_res)
254
233
 
255
234
  def create(
256
235
  self,
@@ -383,28 +362,17 @@ class Jobs(BaseSDK):
383
362
  )
384
363
 
385
364
  if utils.match_response(http_res, "200", "application/json"):
386
- return utils.unmarshal_json(
387
- http_res.text, models.JobsAPIRoutesFineTuningCreateFineTuningJobResponse
365
+ return unmarshal_json_response(
366
+ models.JobsAPIRoutesFineTuningCreateFineTuningJobResponse, http_res
388
367
  )
389
368
  if utils.match_response(http_res, "4XX", "*"):
390
369
  http_res_text = utils.stream_to_text(http_res)
391
- raise models.SDKError(
392
- "API error occurred", http_res.status_code, http_res_text, http_res
393
- )
370
+ raise models.SDKError("API error occurred", http_res, http_res_text)
394
371
  if utils.match_response(http_res, "5XX", "*"):
395
372
  http_res_text = utils.stream_to_text(http_res)
396
- raise models.SDKError(
397
- "API error occurred", http_res.status_code, http_res_text, http_res
398
- )
373
+ raise models.SDKError("API error occurred", http_res, http_res_text)
399
374
 
400
- content_type = http_res.headers.get("Content-Type")
401
- http_res_text = utils.stream_to_text(http_res)
402
- raise models.SDKError(
403
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
404
- http_res.status_code,
405
- http_res_text,
406
- http_res,
407
- )
375
+ raise models.SDKError("Unexpected response received", http_res)
408
376
 
409
377
  async def create_async(
410
378
  self,
@@ -537,28 +505,17 @@ class Jobs(BaseSDK):
537
505
  )
538
506
 
539
507
  if utils.match_response(http_res, "200", "application/json"):
540
- return utils.unmarshal_json(
541
- http_res.text, models.JobsAPIRoutesFineTuningCreateFineTuningJobResponse
508
+ return unmarshal_json_response(
509
+ models.JobsAPIRoutesFineTuningCreateFineTuningJobResponse, http_res
542
510
  )
543
511
  if utils.match_response(http_res, "4XX", "*"):
544
512
  http_res_text = await utils.stream_to_text_async(http_res)
545
- raise models.SDKError(
546
- "API error occurred", http_res.status_code, http_res_text, http_res
547
- )
513
+ raise models.SDKError("API error occurred", http_res, http_res_text)
548
514
  if utils.match_response(http_res, "5XX", "*"):
549
515
  http_res_text = await utils.stream_to_text_async(http_res)
550
- raise models.SDKError(
551
- "API error occurred", http_res.status_code, http_res_text, http_res
552
- )
516
+ raise models.SDKError("API error occurred", http_res, http_res_text)
553
517
 
554
- content_type = http_res.headers.get("Content-Type")
555
- http_res_text = await utils.stream_to_text_async(http_res)
556
- raise models.SDKError(
557
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
558
- http_res.status_code,
559
- http_res_text,
560
- http_res,
561
- )
518
+ raise models.SDKError("Unexpected response received", http_res)
562
519
 
563
520
  def get(
564
521
  self,
@@ -633,28 +590,17 @@ class Jobs(BaseSDK):
633
590
  )
634
591
 
635
592
  if utils.match_response(http_res, "200", "application/json"):
636
- return utils.unmarshal_json(
637
- http_res.text, models.JobsAPIRoutesFineTuningGetFineTuningJobResponse
593
+ return unmarshal_json_response(
594
+ models.JobsAPIRoutesFineTuningGetFineTuningJobResponse, http_res
638
595
  )
639
596
  if utils.match_response(http_res, "4XX", "*"):
640
597
  http_res_text = utils.stream_to_text(http_res)
641
- raise models.SDKError(
642
- "API error occurred", http_res.status_code, http_res_text, http_res
643
- )
598
+ raise models.SDKError("API error occurred", http_res, http_res_text)
644
599
  if utils.match_response(http_res, "5XX", "*"):
645
600
  http_res_text = utils.stream_to_text(http_res)
646
- raise models.SDKError(
647
- "API error occurred", http_res.status_code, http_res_text, http_res
648
- )
601
+ raise models.SDKError("API error occurred", http_res, http_res_text)
649
602
 
650
- content_type = http_res.headers.get("Content-Type")
651
- http_res_text = utils.stream_to_text(http_res)
652
- raise models.SDKError(
653
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
654
- http_res.status_code,
655
- http_res_text,
656
- http_res,
657
- )
603
+ raise models.SDKError("Unexpected response received", http_res)
658
604
 
659
605
  async def get_async(
660
606
  self,
@@ -729,28 +675,17 @@ class Jobs(BaseSDK):
729
675
  )
730
676
 
731
677
  if utils.match_response(http_res, "200", "application/json"):
732
- return utils.unmarshal_json(
733
- http_res.text, models.JobsAPIRoutesFineTuningGetFineTuningJobResponse
678
+ return unmarshal_json_response(
679
+ models.JobsAPIRoutesFineTuningGetFineTuningJobResponse, http_res
734
680
  )
735
681
  if utils.match_response(http_res, "4XX", "*"):
736
682
  http_res_text = await utils.stream_to_text_async(http_res)
737
- raise models.SDKError(
738
- "API error occurred", http_res.status_code, http_res_text, http_res
739
- )
683
+ raise models.SDKError("API error occurred", http_res, http_res_text)
740
684
  if utils.match_response(http_res, "5XX", "*"):
741
685
  http_res_text = await utils.stream_to_text_async(http_res)
742
- raise models.SDKError(
743
- "API error occurred", http_res.status_code, http_res_text, http_res
744
- )
686
+ raise models.SDKError("API error occurred", http_res, http_res_text)
745
687
 
746
- content_type = http_res.headers.get("Content-Type")
747
- http_res_text = await utils.stream_to_text_async(http_res)
748
- raise models.SDKError(
749
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
750
- http_res.status_code,
751
- http_res_text,
752
- http_res,
753
- )
688
+ raise models.SDKError("Unexpected response received", http_res)
754
689
 
755
690
  def cancel(
756
691
  self,
@@ -825,28 +760,17 @@ class Jobs(BaseSDK):
825
760
  )
826
761
 
827
762
  if utils.match_response(http_res, "200", "application/json"):
828
- return utils.unmarshal_json(
829
- http_res.text, models.JobsAPIRoutesFineTuningCancelFineTuningJobResponse
763
+ return unmarshal_json_response(
764
+ models.JobsAPIRoutesFineTuningCancelFineTuningJobResponse, http_res
830
765
  )
831
766
  if utils.match_response(http_res, "4XX", "*"):
832
767
  http_res_text = utils.stream_to_text(http_res)
833
- raise models.SDKError(
834
- "API error occurred", http_res.status_code, http_res_text, http_res
835
- )
768
+ raise models.SDKError("API error occurred", http_res, http_res_text)
836
769
  if utils.match_response(http_res, "5XX", "*"):
837
770
  http_res_text = utils.stream_to_text(http_res)
838
- raise models.SDKError(
839
- "API error occurred", http_res.status_code, http_res_text, http_res
840
- )
771
+ raise models.SDKError("API error occurred", http_res, http_res_text)
841
772
 
842
- content_type = http_res.headers.get("Content-Type")
843
- http_res_text = utils.stream_to_text(http_res)
844
- raise models.SDKError(
845
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
846
- http_res.status_code,
847
- http_res_text,
848
- http_res,
849
- )
773
+ raise models.SDKError("Unexpected response received", http_res)
850
774
 
851
775
  async def cancel_async(
852
776
  self,
@@ -921,28 +845,17 @@ class Jobs(BaseSDK):
921
845
  )
922
846
 
923
847
  if utils.match_response(http_res, "200", "application/json"):
924
- return utils.unmarshal_json(
925
- http_res.text, models.JobsAPIRoutesFineTuningCancelFineTuningJobResponse
848
+ return unmarshal_json_response(
849
+ models.JobsAPIRoutesFineTuningCancelFineTuningJobResponse, http_res
926
850
  )
927
851
  if utils.match_response(http_res, "4XX", "*"):
928
852
  http_res_text = await utils.stream_to_text_async(http_res)
929
- raise models.SDKError(
930
- "API error occurred", http_res.status_code, http_res_text, http_res
931
- )
853
+ raise models.SDKError("API error occurred", http_res, http_res_text)
932
854
  if utils.match_response(http_res, "5XX", "*"):
933
855
  http_res_text = await utils.stream_to_text_async(http_res)
934
- raise models.SDKError(
935
- "API error occurred", http_res.status_code, http_res_text, http_res
936
- )
856
+ raise models.SDKError("API error occurred", http_res, http_res_text)
937
857
 
938
- content_type = http_res.headers.get("Content-Type")
939
- http_res_text = await utils.stream_to_text_async(http_res)
940
- raise models.SDKError(
941
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
942
- http_res.status_code,
943
- http_res_text,
944
- http_res,
945
- )
858
+ raise models.SDKError("Unexpected response received", http_res)
946
859
 
947
860
  def start(
948
861
  self,
@@ -1017,28 +930,17 @@ class Jobs(BaseSDK):
1017
930
  )
1018
931
 
1019
932
  if utils.match_response(http_res, "200", "application/json"):
1020
- return utils.unmarshal_json(
1021
- http_res.text, models.JobsAPIRoutesFineTuningStartFineTuningJobResponse
933
+ return unmarshal_json_response(
934
+ models.JobsAPIRoutesFineTuningStartFineTuningJobResponse, http_res
1022
935
  )
1023
936
  if utils.match_response(http_res, "4XX", "*"):
1024
937
  http_res_text = utils.stream_to_text(http_res)
1025
- raise models.SDKError(
1026
- "API error occurred", http_res.status_code, http_res_text, http_res
1027
- )
938
+ raise models.SDKError("API error occurred", http_res, http_res_text)
1028
939
  if utils.match_response(http_res, "5XX", "*"):
1029
940
  http_res_text = utils.stream_to_text(http_res)
1030
- raise models.SDKError(
1031
- "API error occurred", http_res.status_code, http_res_text, http_res
1032
- )
941
+ raise models.SDKError("API error occurred", http_res, http_res_text)
1033
942
 
1034
- content_type = http_res.headers.get("Content-Type")
1035
- http_res_text = utils.stream_to_text(http_res)
1036
- raise models.SDKError(
1037
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
1038
- http_res.status_code,
1039
- http_res_text,
1040
- http_res,
1041
- )
943
+ raise models.SDKError("Unexpected response received", http_res)
1042
944
 
1043
945
  async def start_async(
1044
946
  self,
@@ -1113,25 +1015,14 @@ class Jobs(BaseSDK):
1113
1015
  )
1114
1016
 
1115
1017
  if utils.match_response(http_res, "200", "application/json"):
1116
- return utils.unmarshal_json(
1117
- http_res.text, models.JobsAPIRoutesFineTuningStartFineTuningJobResponse
1018
+ return unmarshal_json_response(
1019
+ models.JobsAPIRoutesFineTuningStartFineTuningJobResponse, http_res
1118
1020
  )
1119
1021
  if utils.match_response(http_res, "4XX", "*"):
1120
1022
  http_res_text = await utils.stream_to_text_async(http_res)
1121
- raise models.SDKError(
1122
- "API error occurred", http_res.status_code, http_res_text, http_res
1123
- )
1023
+ raise models.SDKError("API error occurred", http_res, http_res_text)
1124
1024
  if utils.match_response(http_res, "5XX", "*"):
1125
1025
  http_res_text = await utils.stream_to_text_async(http_res)
1126
- raise models.SDKError(
1127
- "API error occurred", http_res.status_code, http_res_text, http_res
1128
- )
1026
+ raise models.SDKError("API error occurred", http_res, http_res_text)
1129
1027
 
1130
- content_type = http_res.headers.get("Content-Type")
1131
- http_res_text = await utils.stream_to_text_async(http_res)
1132
- raise models.SDKError(
1133
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
1134
- http_res.status_code,
1135
- http_res_text,
1136
- http_res,
1137
- )
1028
+ raise models.SDKError("Unexpected response received", http_res)