mistralai 1.9.10__py3-none-any.whl → 1.9.11__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
mistralai/libraries.py CHANGED
@@ -8,6 +8,7 @@ from mistralai.accesses import Accesses
8
8
  from mistralai.documents import Documents
9
9
  from mistralai.types import OptionalNullable, UNSET
10
10
  from mistralai.utils import get_security_from_env
11
+ from mistralai.utils.unmarshal_json_response import unmarshal_json_response
11
12
  from typing import Any, Mapping, Optional
12
13
 
13
14
 
@@ -19,14 +20,16 @@ class Libraries(BaseSDK):
19
20
  accesses: Accesses
20
21
  r"""(beta) Libraries API - manage access to a library."""
21
22
 
22
- def __init__(self, sdk_config: SDKConfiguration) -> None:
23
- BaseSDK.__init__(self, sdk_config)
23
+ def __init__(
24
+ self, sdk_config: SDKConfiguration, parent_ref: Optional[object] = None
25
+ ) -> None:
26
+ BaseSDK.__init__(self, sdk_config, parent_ref=parent_ref)
24
27
  self.sdk_configuration = sdk_config
25
28
  self._init_sdks()
26
29
 
27
30
  def _init_sdks(self):
28
- self.documents = Documents(self.sdk_configuration)
29
- self.accesses = Accesses(self.sdk_configuration)
31
+ self.documents = Documents(self.sdk_configuration, parent_ref=self.parent_ref)
32
+ self.accesses = Accesses(self.sdk_configuration, parent_ref=self.parent_ref)
30
33
 
31
34
  def list(
32
35
  self,
@@ -94,26 +97,15 @@ class Libraries(BaseSDK):
94
97
  )
95
98
 
96
99
  if utils.match_response(http_res, "200", "application/json"):
97
- return utils.unmarshal_json(http_res.text, models.ListLibraryOut)
100
+ return unmarshal_json_response(models.ListLibraryOut, http_res)
98
101
  if utils.match_response(http_res, "4XX", "*"):
99
102
  http_res_text = utils.stream_to_text(http_res)
100
- raise models.SDKError(
101
- "API error occurred", http_res.status_code, http_res_text, http_res
102
- )
103
+ raise models.SDKError("API error occurred", http_res, http_res_text)
103
104
  if utils.match_response(http_res, "5XX", "*"):
104
105
  http_res_text = utils.stream_to_text(http_res)
105
- raise models.SDKError(
106
- "API error occurred", http_res.status_code, http_res_text, http_res
107
- )
106
+ raise models.SDKError("API error occurred", http_res, http_res_text)
108
107
 
109
- content_type = http_res.headers.get("Content-Type")
110
- http_res_text = utils.stream_to_text(http_res)
111
- raise models.SDKError(
112
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
113
- http_res.status_code,
114
- http_res_text,
115
- http_res,
116
- )
108
+ raise models.SDKError("Unexpected response received", http_res)
117
109
 
118
110
  async def list_async(
119
111
  self,
@@ -181,26 +173,15 @@ class Libraries(BaseSDK):
181
173
  )
182
174
 
183
175
  if utils.match_response(http_res, "200", "application/json"):
184
- return utils.unmarshal_json(http_res.text, models.ListLibraryOut)
176
+ return unmarshal_json_response(models.ListLibraryOut, http_res)
185
177
  if utils.match_response(http_res, "4XX", "*"):
186
178
  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
- )
179
+ raise models.SDKError("API error occurred", http_res, http_res_text)
190
180
  if utils.match_response(http_res, "5XX", "*"):
191
181
  http_res_text = await utils.stream_to_text_async(http_res)
192
- raise models.SDKError(
193
- "API error occurred", http_res.status_code, http_res_text, http_res
194
- )
182
+ raise models.SDKError("API error occurred", http_res, http_res_text)
195
183
 
196
- content_type = http_res.headers.get("Content-Type")
197
- http_res_text = await utils.stream_to_text_async(http_res)
198
- raise models.SDKError(
199
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
200
- http_res.status_code,
201
- http_res_text,
202
- http_res,
203
- )
184
+ raise models.SDKError("Unexpected response received", http_res)
204
185
 
205
186
  def create(
206
187
  self,
@@ -285,31 +266,20 @@ class Libraries(BaseSDK):
285
266
 
286
267
  response_data: Any = None
287
268
  if utils.match_response(http_res, "201", "application/json"):
288
- return utils.unmarshal_json(http_res.text, models.LibraryOut)
269
+ return unmarshal_json_response(models.LibraryOut, http_res)
289
270
  if utils.match_response(http_res, "422", "application/json"):
290
- response_data = utils.unmarshal_json(
291
- http_res.text, models.HTTPValidationErrorData
271
+ response_data = unmarshal_json_response(
272
+ models.HTTPValidationErrorData, http_res
292
273
  )
293
- raise models.HTTPValidationError(data=response_data)
274
+ raise models.HTTPValidationError(response_data, http_res)
294
275
  if utils.match_response(http_res, "4XX", "*"):
295
276
  http_res_text = utils.stream_to_text(http_res)
296
- raise models.SDKError(
297
- "API error occurred", http_res.status_code, http_res_text, http_res
298
- )
277
+ raise models.SDKError("API error occurred", http_res, http_res_text)
299
278
  if utils.match_response(http_res, "5XX", "*"):
300
279
  http_res_text = utils.stream_to_text(http_res)
301
- raise models.SDKError(
302
- "API error occurred", http_res.status_code, http_res_text, http_res
303
- )
280
+ raise models.SDKError("API error occurred", http_res, http_res_text)
304
281
 
305
- content_type = http_res.headers.get("Content-Type")
306
- http_res_text = utils.stream_to_text(http_res)
307
- raise models.SDKError(
308
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
309
- http_res.status_code,
310
- http_res_text,
311
- http_res,
312
- )
282
+ raise models.SDKError("Unexpected response received", http_res)
313
283
 
314
284
  async def create_async(
315
285
  self,
@@ -394,31 +364,20 @@ class Libraries(BaseSDK):
394
364
 
395
365
  response_data: Any = None
396
366
  if utils.match_response(http_res, "201", "application/json"):
397
- return utils.unmarshal_json(http_res.text, models.LibraryOut)
367
+ return unmarshal_json_response(models.LibraryOut, http_res)
398
368
  if utils.match_response(http_res, "422", "application/json"):
399
- response_data = utils.unmarshal_json(
400
- http_res.text, models.HTTPValidationErrorData
369
+ response_data = unmarshal_json_response(
370
+ models.HTTPValidationErrorData, http_res
401
371
  )
402
- raise models.HTTPValidationError(data=response_data)
372
+ raise models.HTTPValidationError(response_data, http_res)
403
373
  if utils.match_response(http_res, "4XX", "*"):
404
374
  http_res_text = await utils.stream_to_text_async(http_res)
405
- raise models.SDKError(
406
- "API error occurred", http_res.status_code, http_res_text, http_res
407
- )
375
+ raise models.SDKError("API error occurred", http_res, http_res_text)
408
376
  if utils.match_response(http_res, "5XX", "*"):
409
377
  http_res_text = await utils.stream_to_text_async(http_res)
410
- raise models.SDKError(
411
- "API error occurred", http_res.status_code, http_res_text, http_res
412
- )
378
+ raise models.SDKError("API error occurred", http_res, http_res_text)
413
379
 
414
- content_type = http_res.headers.get("Content-Type")
415
- http_res_text = await utils.stream_to_text_async(http_res)
416
- raise models.SDKError(
417
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
418
- http_res.status_code,
419
- http_res_text,
420
- http_res,
421
- )
380
+ raise models.SDKError("Unexpected response received", http_res)
422
381
 
423
382
  def get(
424
383
  self,
@@ -494,31 +453,20 @@ class Libraries(BaseSDK):
494
453
 
495
454
  response_data: Any = None
496
455
  if utils.match_response(http_res, "200", "application/json"):
497
- return utils.unmarshal_json(http_res.text, models.LibraryOut)
456
+ return unmarshal_json_response(models.LibraryOut, http_res)
498
457
  if utils.match_response(http_res, "422", "application/json"):
499
- response_data = utils.unmarshal_json(
500
- http_res.text, models.HTTPValidationErrorData
458
+ response_data = unmarshal_json_response(
459
+ models.HTTPValidationErrorData, http_res
501
460
  )
502
- raise models.HTTPValidationError(data=response_data)
461
+ raise models.HTTPValidationError(response_data, http_res)
503
462
  if utils.match_response(http_res, "4XX", "*"):
504
463
  http_res_text = utils.stream_to_text(http_res)
505
- raise models.SDKError(
506
- "API error occurred", http_res.status_code, http_res_text, http_res
507
- )
464
+ raise models.SDKError("API error occurred", http_res, http_res_text)
508
465
  if utils.match_response(http_res, "5XX", "*"):
509
466
  http_res_text = utils.stream_to_text(http_res)
510
- raise models.SDKError(
511
- "API error occurred", http_res.status_code, http_res_text, http_res
512
- )
467
+ raise models.SDKError("API error occurred", http_res, http_res_text)
513
468
 
514
- content_type = http_res.headers.get("Content-Type")
515
- http_res_text = utils.stream_to_text(http_res)
516
- raise models.SDKError(
517
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
518
- http_res.status_code,
519
- http_res_text,
520
- http_res,
521
- )
469
+ raise models.SDKError("Unexpected response received", http_res)
522
470
 
523
471
  async def get_async(
524
472
  self,
@@ -594,31 +542,20 @@ class Libraries(BaseSDK):
594
542
 
595
543
  response_data: Any = None
596
544
  if utils.match_response(http_res, "200", "application/json"):
597
- return utils.unmarshal_json(http_res.text, models.LibraryOut)
545
+ return unmarshal_json_response(models.LibraryOut, http_res)
598
546
  if utils.match_response(http_res, "422", "application/json"):
599
- response_data = utils.unmarshal_json(
600
- http_res.text, models.HTTPValidationErrorData
547
+ response_data = unmarshal_json_response(
548
+ models.HTTPValidationErrorData, http_res
601
549
  )
602
- raise models.HTTPValidationError(data=response_data)
550
+ raise models.HTTPValidationError(response_data, http_res)
603
551
  if utils.match_response(http_res, "4XX", "*"):
604
552
  http_res_text = await utils.stream_to_text_async(http_res)
605
- raise models.SDKError(
606
- "API error occurred", http_res.status_code, http_res_text, http_res
607
- )
553
+ raise models.SDKError("API error occurred", http_res, http_res_text)
608
554
  if utils.match_response(http_res, "5XX", "*"):
609
555
  http_res_text = await utils.stream_to_text_async(http_res)
610
- raise models.SDKError(
611
- "API error occurred", http_res.status_code, http_res_text, http_res
612
- )
556
+ raise models.SDKError("API error occurred", http_res, http_res_text)
613
557
 
614
- content_type = http_res.headers.get("Content-Type")
615
- http_res_text = await utils.stream_to_text_async(http_res)
616
- raise models.SDKError(
617
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
618
- http_res.status_code,
619
- http_res_text,
620
- http_res,
621
- )
558
+ raise models.SDKError("Unexpected response received", http_res)
622
559
 
623
560
  def delete(
624
561
  self,
@@ -694,31 +631,20 @@ class Libraries(BaseSDK):
694
631
 
695
632
  response_data: Any = None
696
633
  if utils.match_response(http_res, "200", "application/json"):
697
- return utils.unmarshal_json(http_res.text, models.LibraryOut)
634
+ return unmarshal_json_response(models.LibraryOut, http_res)
698
635
  if utils.match_response(http_res, "422", "application/json"):
699
- response_data = utils.unmarshal_json(
700
- http_res.text, models.HTTPValidationErrorData
636
+ response_data = unmarshal_json_response(
637
+ models.HTTPValidationErrorData, http_res
701
638
  )
702
- raise models.HTTPValidationError(data=response_data)
639
+ raise models.HTTPValidationError(response_data, http_res)
703
640
  if utils.match_response(http_res, "4XX", "*"):
704
641
  http_res_text = utils.stream_to_text(http_res)
705
- raise models.SDKError(
706
- "API error occurred", http_res.status_code, http_res_text, http_res
707
- )
642
+ raise models.SDKError("API error occurred", http_res, http_res_text)
708
643
  if utils.match_response(http_res, "5XX", "*"):
709
644
  http_res_text = utils.stream_to_text(http_res)
710
- raise models.SDKError(
711
- "API error occurred", http_res.status_code, http_res_text, http_res
712
- )
645
+ raise models.SDKError("API error occurred", http_res, http_res_text)
713
646
 
714
- content_type = http_res.headers.get("Content-Type")
715
- http_res_text = utils.stream_to_text(http_res)
716
- raise models.SDKError(
717
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
718
- http_res.status_code,
719
- http_res_text,
720
- http_res,
721
- )
647
+ raise models.SDKError("Unexpected response received", http_res)
722
648
 
723
649
  async def delete_async(
724
650
  self,
@@ -794,31 +720,20 @@ class Libraries(BaseSDK):
794
720
 
795
721
  response_data: Any = None
796
722
  if utils.match_response(http_res, "200", "application/json"):
797
- return utils.unmarshal_json(http_res.text, models.LibraryOut)
723
+ return unmarshal_json_response(models.LibraryOut, http_res)
798
724
  if utils.match_response(http_res, "422", "application/json"):
799
- response_data = utils.unmarshal_json(
800
- http_res.text, models.HTTPValidationErrorData
725
+ response_data = unmarshal_json_response(
726
+ models.HTTPValidationErrorData, http_res
801
727
  )
802
- raise models.HTTPValidationError(data=response_data)
728
+ raise models.HTTPValidationError(response_data, http_res)
803
729
  if utils.match_response(http_res, "4XX", "*"):
804
730
  http_res_text = await utils.stream_to_text_async(http_res)
805
- raise models.SDKError(
806
- "API error occurred", http_res.status_code, http_res_text, http_res
807
- )
731
+ raise models.SDKError("API error occurred", http_res, http_res_text)
808
732
  if utils.match_response(http_res, "5XX", "*"):
809
733
  http_res_text = await utils.stream_to_text_async(http_res)
810
- raise models.SDKError(
811
- "API error occurred", http_res.status_code, http_res_text, http_res
812
- )
734
+ raise models.SDKError("API error occurred", http_res, http_res_text)
813
735
 
814
- content_type = http_res.headers.get("Content-Type")
815
- http_res_text = await utils.stream_to_text_async(http_res)
816
- raise models.SDKError(
817
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
818
- http_res.status_code,
819
- http_res_text,
820
- http_res,
821
- )
736
+ raise models.SDKError("Unexpected response received", http_res)
822
737
 
823
738
  def update(
824
739
  self,
@@ -905,31 +820,20 @@ class Libraries(BaseSDK):
905
820
 
906
821
  response_data: Any = None
907
822
  if utils.match_response(http_res, "200", "application/json"):
908
- return utils.unmarshal_json(http_res.text, models.LibraryOut)
823
+ return unmarshal_json_response(models.LibraryOut, http_res)
909
824
  if utils.match_response(http_res, "422", "application/json"):
910
- response_data = utils.unmarshal_json(
911
- http_res.text, models.HTTPValidationErrorData
825
+ response_data = unmarshal_json_response(
826
+ models.HTTPValidationErrorData, http_res
912
827
  )
913
- raise models.HTTPValidationError(data=response_data)
828
+ raise models.HTTPValidationError(response_data, http_res)
914
829
  if utils.match_response(http_res, "4XX", "*"):
915
830
  http_res_text = utils.stream_to_text(http_res)
916
- raise models.SDKError(
917
- "API error occurred", http_res.status_code, http_res_text, http_res
918
- )
831
+ raise models.SDKError("API error occurred", http_res, http_res_text)
919
832
  if utils.match_response(http_res, "5XX", "*"):
920
833
  http_res_text = utils.stream_to_text(http_res)
921
- raise models.SDKError(
922
- "API error occurred", http_res.status_code, http_res_text, http_res
923
- )
834
+ raise models.SDKError("API error occurred", http_res, http_res_text)
924
835
 
925
- content_type = http_res.headers.get("Content-Type")
926
- http_res_text = utils.stream_to_text(http_res)
927
- raise models.SDKError(
928
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
929
- http_res.status_code,
930
- http_res_text,
931
- http_res,
932
- )
836
+ raise models.SDKError("Unexpected response received", http_res)
933
837
 
934
838
  async def update_async(
935
839
  self,
@@ -1016,28 +920,17 @@ class Libraries(BaseSDK):
1016
920
 
1017
921
  response_data: Any = None
1018
922
  if utils.match_response(http_res, "200", "application/json"):
1019
- return utils.unmarshal_json(http_res.text, models.LibraryOut)
923
+ return unmarshal_json_response(models.LibraryOut, http_res)
1020
924
  if utils.match_response(http_res, "422", "application/json"):
1021
- response_data = utils.unmarshal_json(
1022
- http_res.text, models.HTTPValidationErrorData
925
+ response_data = unmarshal_json_response(
926
+ models.HTTPValidationErrorData, http_res
1023
927
  )
1024
- raise models.HTTPValidationError(data=response_data)
928
+ raise models.HTTPValidationError(response_data, http_res)
1025
929
  if utils.match_response(http_res, "4XX", "*"):
1026
930
  http_res_text = await utils.stream_to_text_async(http_res)
1027
- raise models.SDKError(
1028
- "API error occurred", http_res.status_code, http_res_text, http_res
1029
- )
931
+ raise models.SDKError("API error occurred", http_res, http_res_text)
1030
932
  if utils.match_response(http_res, "5XX", "*"):
1031
933
  http_res_text = await utils.stream_to_text_async(http_res)
1032
- raise models.SDKError(
1033
- "API error occurred", http_res.status_code, http_res_text, http_res
1034
- )
934
+ raise models.SDKError("API error occurred", http_res, http_res_text)
1035
935
 
1036
- content_type = http_res.headers.get("Content-Type")
1037
- http_res_text = await utils.stream_to_text_async(http_res)
1038
- raise models.SDKError(
1039
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
1040
- http_res.status_code,
1041
- http_res_text,
1042
- http_res,
1043
- )
936
+ raise models.SDKError("Unexpected response received", http_res)