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/embeddings.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, Union
9
10
 
10
11
 
@@ -102,31 +103,20 @@ class Embeddings(BaseSDK):
102
103
 
103
104
  response_data: Any = None
104
105
  if utils.match_response(http_res, "200", "application/json"):
105
- return utils.unmarshal_json(http_res.text, models.EmbeddingResponse)
106
+ return unmarshal_json_response(models.EmbeddingResponse, http_res)
106
107
  if utils.match_response(http_res, "422", "application/json"):
107
- response_data = utils.unmarshal_json(
108
- http_res.text, models.HTTPValidationErrorData
108
+ response_data = unmarshal_json_response(
109
+ models.HTTPValidationErrorData, http_res
109
110
  )
110
- raise models.HTTPValidationError(data=response_data)
111
+ raise models.HTTPValidationError(response_data, http_res)
111
112
  if utils.match_response(http_res, "4XX", "*"):
112
113
  http_res_text = utils.stream_to_text(http_res)
113
- raise models.SDKError(
114
- "API error occurred", http_res.status_code, http_res_text, http_res
115
- )
114
+ raise models.SDKError("API error occurred", http_res, http_res_text)
116
115
  if utils.match_response(http_res, "5XX", "*"):
117
116
  http_res_text = utils.stream_to_text(http_res)
118
- raise models.SDKError(
119
- "API error occurred", http_res.status_code, http_res_text, http_res
120
- )
117
+ raise models.SDKError("API error occurred", http_res, http_res_text)
121
118
 
122
- content_type = http_res.headers.get("Content-Type")
123
- http_res_text = utils.stream_to_text(http_res)
124
- raise models.SDKError(
125
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
126
- http_res.status_code,
127
- http_res_text,
128
- http_res,
129
- )
119
+ raise models.SDKError("Unexpected response received", http_res)
130
120
 
131
121
  async def create_async(
132
122
  self,
@@ -219,28 +209,17 @@ class Embeddings(BaseSDK):
219
209
 
220
210
  response_data: Any = None
221
211
  if utils.match_response(http_res, "200", "application/json"):
222
- return utils.unmarshal_json(http_res.text, models.EmbeddingResponse)
212
+ return unmarshal_json_response(models.EmbeddingResponse, http_res)
223
213
  if utils.match_response(http_res, "422", "application/json"):
224
- response_data = utils.unmarshal_json(
225
- http_res.text, models.HTTPValidationErrorData
214
+ response_data = unmarshal_json_response(
215
+ models.HTTPValidationErrorData, http_res
226
216
  )
227
- raise models.HTTPValidationError(data=response_data)
217
+ raise models.HTTPValidationError(response_data, http_res)
228
218
  if utils.match_response(http_res, "4XX", "*"):
229
219
  http_res_text = await utils.stream_to_text_async(http_res)
230
- raise models.SDKError(
231
- "API error occurred", http_res.status_code, http_res_text, http_res
232
- )
220
+ raise models.SDKError("API error occurred", http_res, http_res_text)
233
221
  if utils.match_response(http_res, "5XX", "*"):
234
222
  http_res_text = await utils.stream_to_text_async(http_res)
235
- raise models.SDKError(
236
- "API error occurred", http_res.status_code, http_res_text, http_res
237
- )
223
+ raise models.SDKError("API error occurred", http_res, http_res_text)
238
224
 
239
- content_type = http_res.headers.get("Content-Type")
240
- http_res_text = await utils.stream_to_text_async(http_res)
241
- raise models.SDKError(
242
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
243
- http_res.status_code,
244
- http_res_text,
245
- http_res,
246
- )
225
+ raise models.SDKError("Unexpected response received", http_res)
mistralai/files.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
 
@@ -99,26 +100,15 @@ class Files(BaseSDK):
99
100
  )
100
101
 
101
102
  if utils.match_response(http_res, "200", "application/json"):
102
- return utils.unmarshal_json(http_res.text, models.UploadFileOut)
103
+ return unmarshal_json_response(models.UploadFileOut, http_res)
103
104
  if utils.match_response(http_res, "4XX", "*"):
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
  if utils.match_response(http_res, "5XX", "*"):
109
108
  http_res_text = utils.stream_to_text(http_res)
110
- raise models.SDKError(
111
- "API error occurred", http_res.status_code, http_res_text, http_res
112
- )
109
+ raise models.SDKError("API error occurred", http_res, http_res_text)
113
110
 
114
- content_type = http_res.headers.get("Content-Type")
115
- http_res_text = utils.stream_to_text(http_res)
116
- raise models.SDKError(
117
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
118
- http_res.status_code,
119
- http_res_text,
120
- http_res,
121
- )
111
+ raise models.SDKError("Unexpected response received", http_res)
122
112
 
123
113
  async def upload_async(
124
114
  self,
@@ -207,26 +197,15 @@ class Files(BaseSDK):
207
197
  )
208
198
 
209
199
  if utils.match_response(http_res, "200", "application/json"):
210
- return utils.unmarshal_json(http_res.text, models.UploadFileOut)
200
+ return unmarshal_json_response(models.UploadFileOut, http_res)
211
201
  if utils.match_response(http_res, "4XX", "*"):
212
202
  http_res_text = await utils.stream_to_text_async(http_res)
213
- raise models.SDKError(
214
- "API error occurred", http_res.status_code, http_res_text, http_res
215
- )
203
+ raise models.SDKError("API error occurred", http_res, http_res_text)
216
204
  if utils.match_response(http_res, "5XX", "*"):
217
205
  http_res_text = await utils.stream_to_text_async(http_res)
218
- raise models.SDKError(
219
- "API error occurred", http_res.status_code, http_res_text, http_res
220
- )
206
+ raise models.SDKError("API error occurred", http_res, http_res_text)
221
207
 
222
- content_type = http_res.headers.get("Content-Type")
223
- http_res_text = await utils.stream_to_text_async(http_res)
224
- raise models.SDKError(
225
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
226
- http_res.status_code,
227
- http_res_text,
228
- http_res,
229
- )
208
+ raise models.SDKError("Unexpected response received", http_res)
230
209
 
231
210
  def list(
232
211
  self,
@@ -316,26 +295,15 @@ class Files(BaseSDK):
316
295
  )
317
296
 
318
297
  if utils.match_response(http_res, "200", "application/json"):
319
- return utils.unmarshal_json(http_res.text, models.ListFilesOut)
298
+ return unmarshal_json_response(models.ListFilesOut, http_res)
320
299
  if utils.match_response(http_res, "4XX", "*"):
321
300
  http_res_text = utils.stream_to_text(http_res)
322
- raise models.SDKError(
323
- "API error occurred", http_res.status_code, http_res_text, http_res
324
- )
301
+ raise models.SDKError("API error occurred", http_res, http_res_text)
325
302
  if utils.match_response(http_res, "5XX", "*"):
326
303
  http_res_text = utils.stream_to_text(http_res)
327
- raise models.SDKError(
328
- "API error occurred", http_res.status_code, http_res_text, http_res
329
- )
304
+ raise models.SDKError("API error occurred", http_res, http_res_text)
330
305
 
331
- content_type = http_res.headers.get("Content-Type")
332
- http_res_text = utils.stream_to_text(http_res)
333
- raise models.SDKError(
334
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
335
- http_res.status_code,
336
- http_res_text,
337
- http_res,
338
- )
306
+ raise models.SDKError("Unexpected response received", http_res)
339
307
 
340
308
  async def list_async(
341
309
  self,
@@ -425,26 +393,15 @@ class Files(BaseSDK):
425
393
  )
426
394
 
427
395
  if utils.match_response(http_res, "200", "application/json"):
428
- return utils.unmarshal_json(http_res.text, models.ListFilesOut)
396
+ return unmarshal_json_response(models.ListFilesOut, http_res)
429
397
  if utils.match_response(http_res, "4XX", "*"):
430
398
  http_res_text = await utils.stream_to_text_async(http_res)
431
- raise models.SDKError(
432
- "API error occurred", http_res.status_code, http_res_text, http_res
433
- )
399
+ raise models.SDKError("API error occurred", http_res, http_res_text)
434
400
  if utils.match_response(http_res, "5XX", "*"):
435
401
  http_res_text = await utils.stream_to_text_async(http_res)
436
- raise models.SDKError(
437
- "API error occurred", http_res.status_code, http_res_text, http_res
438
- )
402
+ raise models.SDKError("API error occurred", http_res, http_res_text)
439
403
 
440
- content_type = http_res.headers.get("Content-Type")
441
- http_res_text = await utils.stream_to_text_async(http_res)
442
- raise models.SDKError(
443
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
444
- http_res.status_code,
445
- http_res_text,
446
- http_res,
447
- )
404
+ raise models.SDKError("Unexpected response received", http_res)
448
405
 
449
406
  def retrieve(
450
407
  self,
@@ -519,26 +476,15 @@ class Files(BaseSDK):
519
476
  )
520
477
 
521
478
  if utils.match_response(http_res, "200", "application/json"):
522
- return utils.unmarshal_json(http_res.text, models.RetrieveFileOut)
479
+ return unmarshal_json_response(models.RetrieveFileOut, http_res)
523
480
  if utils.match_response(http_res, "4XX", "*"):
524
481
  http_res_text = utils.stream_to_text(http_res)
525
- raise models.SDKError(
526
- "API error occurred", http_res.status_code, http_res_text, http_res
527
- )
482
+ raise models.SDKError("API error occurred", http_res, http_res_text)
528
483
  if utils.match_response(http_res, "5XX", "*"):
529
484
  http_res_text = utils.stream_to_text(http_res)
530
- raise models.SDKError(
531
- "API error occurred", http_res.status_code, http_res_text, http_res
532
- )
485
+ raise models.SDKError("API error occurred", http_res, http_res_text)
533
486
 
534
- content_type = http_res.headers.get("Content-Type")
535
- http_res_text = utils.stream_to_text(http_res)
536
- raise models.SDKError(
537
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
538
- http_res.status_code,
539
- http_res_text,
540
- http_res,
541
- )
487
+ raise models.SDKError("Unexpected response received", http_res)
542
488
 
543
489
  async def retrieve_async(
544
490
  self,
@@ -613,26 +559,15 @@ class Files(BaseSDK):
613
559
  )
614
560
 
615
561
  if utils.match_response(http_res, "200", "application/json"):
616
- return utils.unmarshal_json(http_res.text, models.RetrieveFileOut)
562
+ return unmarshal_json_response(models.RetrieveFileOut, http_res)
617
563
  if utils.match_response(http_res, "4XX", "*"):
618
564
  http_res_text = await utils.stream_to_text_async(http_res)
619
- raise models.SDKError(
620
- "API error occurred", http_res.status_code, http_res_text, http_res
621
- )
565
+ raise models.SDKError("API error occurred", http_res, http_res_text)
622
566
  if utils.match_response(http_res, "5XX", "*"):
623
567
  http_res_text = await utils.stream_to_text_async(http_res)
624
- raise models.SDKError(
625
- "API error occurred", http_res.status_code, http_res_text, http_res
626
- )
568
+ raise models.SDKError("API error occurred", http_res, http_res_text)
627
569
 
628
- content_type = http_res.headers.get("Content-Type")
629
- http_res_text = await utils.stream_to_text_async(http_res)
630
- raise models.SDKError(
631
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
632
- http_res.status_code,
633
- http_res_text,
634
- http_res,
635
- )
570
+ raise models.SDKError("Unexpected response received", http_res)
636
571
 
637
572
  def delete(
638
573
  self,
@@ -707,26 +642,15 @@ class Files(BaseSDK):
707
642
  )
708
643
 
709
644
  if utils.match_response(http_res, "200", "application/json"):
710
- return utils.unmarshal_json(http_res.text, models.DeleteFileOut)
645
+ return unmarshal_json_response(models.DeleteFileOut, http_res)
711
646
  if utils.match_response(http_res, "4XX", "*"):
712
647
  http_res_text = utils.stream_to_text(http_res)
713
- raise models.SDKError(
714
- "API error occurred", http_res.status_code, http_res_text, http_res
715
- )
648
+ raise models.SDKError("API error occurred", http_res, http_res_text)
716
649
  if utils.match_response(http_res, "5XX", "*"):
717
650
  http_res_text = utils.stream_to_text(http_res)
718
- raise models.SDKError(
719
- "API error occurred", http_res.status_code, http_res_text, http_res
720
- )
651
+ raise models.SDKError("API error occurred", http_res, http_res_text)
721
652
 
722
- content_type = http_res.headers.get("Content-Type")
723
- http_res_text = utils.stream_to_text(http_res)
724
- raise models.SDKError(
725
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
726
- http_res.status_code,
727
- http_res_text,
728
- http_res,
729
- )
653
+ raise models.SDKError("Unexpected response received", http_res)
730
654
 
731
655
  async def delete_async(
732
656
  self,
@@ -801,26 +725,15 @@ class Files(BaseSDK):
801
725
  )
802
726
 
803
727
  if utils.match_response(http_res, "200", "application/json"):
804
- return utils.unmarshal_json(http_res.text, models.DeleteFileOut)
728
+ return unmarshal_json_response(models.DeleteFileOut, http_res)
805
729
  if utils.match_response(http_res, "4XX", "*"):
806
730
  http_res_text = await utils.stream_to_text_async(http_res)
807
- raise models.SDKError(
808
- "API error occurred", http_res.status_code, http_res_text, http_res
809
- )
731
+ raise models.SDKError("API error occurred", http_res, http_res_text)
810
732
  if utils.match_response(http_res, "5XX", "*"):
811
733
  http_res_text = await utils.stream_to_text_async(http_res)
812
- raise models.SDKError(
813
- "API error occurred", http_res.status_code, http_res_text, http_res
814
- )
734
+ raise models.SDKError("API error occurred", http_res, http_res_text)
815
735
 
816
- content_type = http_res.headers.get("Content-Type")
817
- http_res_text = await utils.stream_to_text_async(http_res)
818
- raise models.SDKError(
819
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
820
- http_res.status_code,
821
- http_res_text,
822
- http_res,
823
- )
736
+ raise models.SDKError("Unexpected response received", http_res)
824
737
 
825
738
  def download(
826
739
  self,
@@ -899,23 +812,13 @@ class Files(BaseSDK):
899
812
  return http_res
900
813
  if utils.match_response(http_res, "4XX", "*"):
901
814
  http_res_text = utils.stream_to_text(http_res)
902
- raise models.SDKError(
903
- "API error occurred", http_res.status_code, http_res_text, http_res
904
- )
815
+ raise models.SDKError("API error occurred", http_res, http_res_text)
905
816
  if utils.match_response(http_res, "5XX", "*"):
906
817
  http_res_text = utils.stream_to_text(http_res)
907
- raise models.SDKError(
908
- "API error occurred", http_res.status_code, http_res_text, http_res
909
- )
818
+ raise models.SDKError("API error occurred", http_res, http_res_text)
910
819
 
911
- content_type = http_res.headers.get("Content-Type")
912
820
  http_res_text = utils.stream_to_text(http_res)
913
- raise models.SDKError(
914
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
915
- http_res.status_code,
916
- http_res_text,
917
- http_res,
918
- )
821
+ raise models.SDKError("Unexpected response received", http_res, http_res_text)
919
822
 
920
823
  async def download_async(
921
824
  self,
@@ -994,23 +897,13 @@ class Files(BaseSDK):
994
897
  return http_res
995
898
  if utils.match_response(http_res, "4XX", "*"):
996
899
  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
- )
900
+ raise models.SDKError("API error occurred", http_res, http_res_text)
1000
901
  if utils.match_response(http_res, "5XX", "*"):
1001
902
  http_res_text = await utils.stream_to_text_async(http_res)
1002
- raise models.SDKError(
1003
- "API error occurred", http_res.status_code, http_res_text, http_res
1004
- )
903
+ raise models.SDKError("API error occurred", http_res, http_res_text)
1005
904
 
1006
- content_type = http_res.headers.get("Content-Type")
1007
905
  http_res_text = await utils.stream_to_text_async(http_res)
1008
- raise models.SDKError(
1009
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
1010
- http_res.status_code,
1011
- http_res_text,
1012
- http_res,
1013
- )
906
+ raise models.SDKError("Unexpected response received", http_res, http_res_text)
1014
907
 
1015
908
  def get_signed_url(
1016
909
  self,
@@ -1086,26 +979,15 @@ class Files(BaseSDK):
1086
979
  )
1087
980
 
1088
981
  if utils.match_response(http_res, "200", "application/json"):
1089
- return utils.unmarshal_json(http_res.text, models.FileSignedURL)
982
+ return unmarshal_json_response(models.FileSignedURL, http_res)
1090
983
  if utils.match_response(http_res, "4XX", "*"):
1091
984
  http_res_text = utils.stream_to_text(http_res)
1092
- raise models.SDKError(
1093
- "API error occurred", http_res.status_code, http_res_text, http_res
1094
- )
985
+ raise models.SDKError("API error occurred", http_res, http_res_text)
1095
986
  if utils.match_response(http_res, "5XX", "*"):
1096
987
  http_res_text = utils.stream_to_text(http_res)
1097
- raise models.SDKError(
1098
- "API error occurred", http_res.status_code, http_res_text, http_res
1099
- )
988
+ raise models.SDKError("API error occurred", http_res, http_res_text)
1100
989
 
1101
- content_type = http_res.headers.get("Content-Type")
1102
- http_res_text = utils.stream_to_text(http_res)
1103
- raise models.SDKError(
1104
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
1105
- http_res.status_code,
1106
- http_res_text,
1107
- http_res,
1108
- )
990
+ raise models.SDKError("Unexpected response received", http_res)
1109
991
 
1110
992
  async def get_signed_url_async(
1111
993
  self,
@@ -1181,23 +1063,12 @@ class Files(BaseSDK):
1181
1063
  )
1182
1064
 
1183
1065
  if utils.match_response(http_res, "200", "application/json"):
1184
- return utils.unmarshal_json(http_res.text, models.FileSignedURL)
1066
+ return unmarshal_json_response(models.FileSignedURL, http_res)
1185
1067
  if utils.match_response(http_res, "4XX", "*"):
1186
1068
  http_res_text = await utils.stream_to_text_async(http_res)
1187
- raise models.SDKError(
1188
- "API error occurred", http_res.status_code, http_res_text, http_res
1189
- )
1069
+ raise models.SDKError("API error occurred", http_res, http_res_text)
1190
1070
  if utils.match_response(http_res, "5XX", "*"):
1191
1071
  http_res_text = await utils.stream_to_text_async(http_res)
1192
- raise models.SDKError(
1193
- "API error occurred", http_res.status_code, http_res_text, http_res
1194
- )
1072
+ raise models.SDKError("API error occurred", http_res, http_res_text)
1195
1073
 
1196
- content_type = http_res.headers.get("Content-Type")
1197
- http_res_text = await utils.stream_to_text_async(http_res)
1198
- raise models.SDKError(
1199
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
1200
- http_res.status_code,
1201
- http_res_text,
1202
- http_res,
1203
- )
1074
+ raise models.SDKError("Unexpected response received", http_res)
mistralai/fim.py CHANGED
@@ -5,6 +5,7 @@ from mistralai import models, utils
5
5
  from mistralai._hooks import HookContext
6
6
  from mistralai.types import OptionalNullable, UNSET
7
7
  from mistralai.utils import eventstreaming, get_security_from_env
8
+ from mistralai.utils.unmarshal_json_response import unmarshal_json_response
8
9
  from typing import Any, Mapping, Optional, Union
9
10
 
10
11
 
@@ -120,31 +121,20 @@ class Fim(BaseSDK):
120
121
 
121
122
  response_data: Any = None
122
123
  if utils.match_response(http_res, "200", "application/json"):
123
- return utils.unmarshal_json(http_res.text, models.FIMCompletionResponse)
124
+ return unmarshal_json_response(models.FIMCompletionResponse, http_res)
124
125
  if utils.match_response(http_res, "422", "application/json"):
125
- response_data = utils.unmarshal_json(
126
- http_res.text, models.HTTPValidationErrorData
126
+ response_data = unmarshal_json_response(
127
+ models.HTTPValidationErrorData, http_res
127
128
  )
128
- raise models.HTTPValidationError(data=response_data)
129
+ raise models.HTTPValidationError(response_data, http_res)
129
130
  if utils.match_response(http_res, "4XX", "*"):
130
131
  http_res_text = utils.stream_to_text(http_res)
131
- raise models.SDKError(
132
- "API error occurred", http_res.status_code, http_res_text, http_res
133
- )
132
+ raise models.SDKError("API error occurred", http_res, http_res_text)
134
133
  if utils.match_response(http_res, "5XX", "*"):
135
134
  http_res_text = utils.stream_to_text(http_res)
136
- raise models.SDKError(
137
- "API error occurred", http_res.status_code, http_res_text, http_res
138
- )
135
+ raise models.SDKError("API error occurred", http_res, http_res_text)
139
136
 
140
- content_type = http_res.headers.get("Content-Type")
141
- http_res_text = utils.stream_to_text(http_res)
142
- raise models.SDKError(
143
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
144
- http_res.status_code,
145
- http_res_text,
146
- http_res,
147
- )
137
+ raise models.SDKError("Unexpected response received", http_res)
148
138
 
149
139
  async def complete_async(
150
140
  self,
@@ -255,31 +245,20 @@ class Fim(BaseSDK):
255
245
 
256
246
  response_data: Any = None
257
247
  if utils.match_response(http_res, "200", "application/json"):
258
- return utils.unmarshal_json(http_res.text, models.FIMCompletionResponse)
248
+ return unmarshal_json_response(models.FIMCompletionResponse, http_res)
259
249
  if utils.match_response(http_res, "422", "application/json"):
260
- response_data = utils.unmarshal_json(
261
- http_res.text, models.HTTPValidationErrorData
250
+ response_data = unmarshal_json_response(
251
+ models.HTTPValidationErrorData, http_res
262
252
  )
263
- raise models.HTTPValidationError(data=response_data)
253
+ raise models.HTTPValidationError(response_data, http_res)
264
254
  if utils.match_response(http_res, "4XX", "*"):
265
255
  http_res_text = await utils.stream_to_text_async(http_res)
266
- raise models.SDKError(
267
- "API error occurred", http_res.status_code, http_res_text, http_res
268
- )
256
+ raise models.SDKError("API error occurred", http_res, http_res_text)
269
257
  if utils.match_response(http_res, "5XX", "*"):
270
258
  http_res_text = await utils.stream_to_text_async(http_res)
271
- raise models.SDKError(
272
- "API error occurred", http_res.status_code, http_res_text, http_res
273
- )
259
+ raise models.SDKError("API error occurred", http_res, http_res_text)
274
260
 
275
- content_type = http_res.headers.get("Content-Type")
276
- http_res_text = await utils.stream_to_text_async(http_res)
277
- raise models.SDKError(
278
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
279
- http_res.status_code,
280
- http_res_text,
281
- http_res,
282
- )
261
+ raise models.SDKError("Unexpected response received", http_res)
283
262
 
284
263
  def stream(
285
264
  self,
@@ -395,32 +374,23 @@ class Fim(BaseSDK):
395
374
  http_res,
396
375
  lambda raw: utils.unmarshal_json(raw, models.CompletionEvent),
397
376
  sentinel="[DONE]",
377
+ client_ref=self,
398
378
  )
399
379
  if utils.match_response(http_res, "422", "application/json"):
400
380
  http_res_text = utils.stream_to_text(http_res)
401
- response_data = utils.unmarshal_json(
402
- http_res_text, models.HTTPValidationErrorData
381
+ response_data = unmarshal_json_response(
382
+ models.HTTPValidationErrorData, http_res, http_res_text
403
383
  )
404
- raise models.HTTPValidationError(data=response_data)
384
+ raise models.HTTPValidationError(response_data, http_res, http_res_text)
405
385
  if utils.match_response(http_res, "4XX", "*"):
406
386
  http_res_text = utils.stream_to_text(http_res)
407
- raise models.SDKError(
408
- "API error occurred", http_res.status_code, http_res_text, http_res
409
- )
387
+ raise models.SDKError("API error occurred", http_res, http_res_text)
410
388
  if utils.match_response(http_res, "5XX", "*"):
411
389
  http_res_text = utils.stream_to_text(http_res)
412
- raise models.SDKError(
413
- "API error occurred", http_res.status_code, http_res_text, http_res
414
- )
390
+ raise models.SDKError("API error occurred", http_res, http_res_text)
415
391
 
416
- content_type = http_res.headers.get("Content-Type")
417
392
  http_res_text = utils.stream_to_text(http_res)
418
- raise models.SDKError(
419
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
420
- http_res.status_code,
421
- http_res_text,
422
- http_res,
423
- )
393
+ raise models.SDKError("Unexpected response received", http_res, http_res_text)
424
394
 
425
395
  async def stream_async(
426
396
  self,
@@ -536,29 +506,20 @@ class Fim(BaseSDK):
536
506
  http_res,
537
507
  lambda raw: utils.unmarshal_json(raw, models.CompletionEvent),
538
508
  sentinel="[DONE]",
509
+ client_ref=self,
539
510
  )
540
511
  if utils.match_response(http_res, "422", "application/json"):
541
512
  http_res_text = await utils.stream_to_text_async(http_res)
542
- response_data = utils.unmarshal_json(
543
- http_res_text, models.HTTPValidationErrorData
513
+ response_data = unmarshal_json_response(
514
+ models.HTTPValidationErrorData, http_res, http_res_text
544
515
  )
545
- raise models.HTTPValidationError(data=response_data)
516
+ raise models.HTTPValidationError(response_data, http_res, http_res_text)
546
517
  if utils.match_response(http_res, "4XX", "*"):
547
518
  http_res_text = await utils.stream_to_text_async(http_res)
548
- raise models.SDKError(
549
- "API error occurred", http_res.status_code, http_res_text, http_res
550
- )
519
+ raise models.SDKError("API error occurred", http_res, http_res_text)
551
520
  if utils.match_response(http_res, "5XX", "*"):
552
521
  http_res_text = await utils.stream_to_text_async(http_res)
553
- raise models.SDKError(
554
- "API error occurred", http_res.status_code, http_res_text, http_res
555
- )
522
+ raise models.SDKError("API error occurred", http_res, http_res_text)
556
523
 
557
- content_type = http_res.headers.get("Content-Type")
558
524
  http_res_text = await utils.stream_to_text_async(http_res)
559
- raise models.SDKError(
560
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
561
- http_res.status_code,
562
- http_res_text,
563
- http_res,
564
- )
525
+ raise models.SDKError("Unexpected response received", http_res, http_res_text)
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)