google-genai 1.19.0__py3-none-any.whl → 1.21.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
google/genai/tunings.py CHANGED
@@ -15,14 +15,15 @@
15
15
 
16
16
  # Code generated by the Google Gen AI SDK generator DO NOT EDIT.
17
17
 
18
+ import json
18
19
  import logging
19
20
  from typing import Any, Optional, Union
20
21
  from urllib.parse import urlencode
22
+
21
23
  from . import _api_module
22
24
  from . import _common
23
25
  from . import _transformers as t
24
26
  from . import types
25
- from ._api_client import BaseApiClient
26
27
  from ._common import get_value_by_path as getv
27
28
  from ._common import set_value_by_path as setv
28
29
  from .pagers import AsyncPager, Pager
@@ -31,7 +32,6 @@ logger = logging.getLogger('google_genai.tunings')
31
32
 
32
33
 
33
34
  def _GetTuningJobParameters_to_mldev(
34
- api_client: BaseApiClient,
35
35
  from_object: Union[dict[str, Any], object],
36
36
  parent_object: Optional[dict[str, Any]] = None,
37
37
  ) -> dict[str, Any]:
@@ -46,7 +46,6 @@ def _GetTuningJobParameters_to_mldev(
46
46
 
47
47
 
48
48
  def _ListTuningJobsConfig_to_mldev(
49
- api_client: BaseApiClient,
50
49
  from_object: Union[dict[str, Any], object],
51
50
  parent_object: Optional[dict[str, Any]] = None,
52
51
  ) -> dict[str, Any]:
@@ -71,7 +70,6 @@ def _ListTuningJobsConfig_to_mldev(
71
70
 
72
71
 
73
72
  def _ListTuningJobsParameters_to_mldev(
74
- api_client: BaseApiClient,
75
73
  from_object: Union[dict[str, Any], object],
76
74
  parent_object: Optional[dict[str, Any]] = None,
77
75
  ) -> dict[str, Any]:
@@ -81,7 +79,7 @@ def _ListTuningJobsParameters_to_mldev(
81
79
  to_object,
82
80
  ['config'],
83
81
  _ListTuningJobsConfig_to_mldev(
84
- api_client, getv(from_object, ['config']), to_object
82
+ getv(from_object, ['config']), to_object
85
83
  ),
86
84
  )
87
85
 
@@ -89,7 +87,6 @@ def _ListTuningJobsParameters_to_mldev(
89
87
 
90
88
 
91
89
  def _TuningExample_to_mldev(
92
- api_client: BaseApiClient,
93
90
  from_object: Union[dict[str, Any], object],
94
91
  parent_object: Optional[dict[str, Any]] = None,
95
92
  ) -> dict[str, Any]:
@@ -104,7 +101,6 @@ def _TuningExample_to_mldev(
104
101
 
105
102
 
106
103
  def _TuningDataset_to_mldev(
107
- api_client: BaseApiClient,
108
104
  from_object: Union[dict[str, Any], object],
109
105
  parent_object: Optional[dict[str, Any]] = None,
110
106
  ) -> dict[str, Any]:
@@ -117,7 +113,7 @@ def _TuningDataset_to_mldev(
117
113
  to_object,
118
114
  ['examples', 'examples'],
119
115
  [
120
- _TuningExample_to_mldev(api_client, item, to_object)
116
+ _TuningExample_to_mldev(item, to_object)
121
117
  for item in getv(from_object, ['examples'])
122
118
  ],
123
119
  )
@@ -126,7 +122,6 @@ def _TuningDataset_to_mldev(
126
122
 
127
123
 
128
124
  def _TuningValidationDataset_to_mldev(
129
- api_client: BaseApiClient,
130
125
  from_object: Union[dict[str, Any], object],
131
126
  parent_object: Optional[dict[str, Any]] = None,
132
127
  ) -> dict[str, Any]:
@@ -138,7 +133,6 @@ def _TuningValidationDataset_to_mldev(
138
133
 
139
134
 
140
135
  def _CreateTuningJobConfig_to_mldev(
141
- api_client: BaseApiClient,
142
136
  from_object: Union[dict[str, Any], object],
143
137
  parent_object: Optional[dict[str, Any]] = None,
144
138
  ) -> dict[str, Any]:
@@ -199,7 +193,6 @@ def _CreateTuningJobConfig_to_mldev(
199
193
 
200
194
 
201
195
  def _CreateTuningJobParameters_to_mldev(
202
- api_client: BaseApiClient,
203
196
  from_object: Union[dict[str, Any], object],
204
197
  parent_object: Optional[dict[str, Any]] = None,
205
198
  ) -> dict[str, Any]:
@@ -212,7 +205,7 @@ def _CreateTuningJobParameters_to_mldev(
212
205
  to_object,
213
206
  ['tuningTask', 'trainingData'],
214
207
  _TuningDataset_to_mldev(
215
- api_client, getv(from_object, ['training_dataset']), to_object
208
+ getv(from_object, ['training_dataset']), to_object
216
209
  ),
217
210
  )
218
211
 
@@ -221,7 +214,7 @@ def _CreateTuningJobParameters_to_mldev(
221
214
  to_object,
222
215
  ['config'],
223
216
  _CreateTuningJobConfig_to_mldev(
224
- api_client, getv(from_object, ['config']), to_object
217
+ getv(from_object, ['config']), to_object
225
218
  ),
226
219
  )
227
220
 
@@ -229,7 +222,6 @@ def _CreateTuningJobParameters_to_mldev(
229
222
 
230
223
 
231
224
  def _GetTuningJobParameters_to_vertex(
232
- api_client: BaseApiClient,
233
225
  from_object: Union[dict[str, Any], object],
234
226
  parent_object: Optional[dict[str, Any]] = None,
235
227
  ) -> dict[str, Any]:
@@ -244,7 +236,6 @@ def _GetTuningJobParameters_to_vertex(
244
236
 
245
237
 
246
238
  def _ListTuningJobsConfig_to_vertex(
247
- api_client: BaseApiClient,
248
239
  from_object: Union[dict[str, Any], object],
249
240
  parent_object: Optional[dict[str, Any]] = None,
250
241
  ) -> dict[str, Any]:
@@ -269,7 +260,6 @@ def _ListTuningJobsConfig_to_vertex(
269
260
 
270
261
 
271
262
  def _ListTuningJobsParameters_to_vertex(
272
- api_client: BaseApiClient,
273
263
  from_object: Union[dict[str, Any], object],
274
264
  parent_object: Optional[dict[str, Any]] = None,
275
265
  ) -> dict[str, Any]:
@@ -279,7 +269,7 @@ def _ListTuningJobsParameters_to_vertex(
279
269
  to_object,
280
270
  ['config'],
281
271
  _ListTuningJobsConfig_to_vertex(
282
- api_client, getv(from_object, ['config']), to_object
272
+ getv(from_object, ['config']), to_object
283
273
  ),
284
274
  )
285
275
 
@@ -287,7 +277,6 @@ def _ListTuningJobsParameters_to_vertex(
287
277
 
288
278
 
289
279
  def _TuningExample_to_vertex(
290
- api_client: BaseApiClient,
291
280
  from_object: Union[dict[str, Any], object],
292
281
  parent_object: Optional[dict[str, Any]] = None,
293
282
  ) -> dict[str, Any]:
@@ -302,7 +291,6 @@ def _TuningExample_to_vertex(
302
291
 
303
292
 
304
293
  def _TuningDataset_to_vertex(
305
- api_client: BaseApiClient,
306
294
  from_object: Union[dict[str, Any], object],
307
295
  parent_object: Optional[dict[str, Any]] = None,
308
296
  ) -> dict[str, Any]:
@@ -321,7 +309,6 @@ def _TuningDataset_to_vertex(
321
309
 
322
310
 
323
311
  def _TuningValidationDataset_to_vertex(
324
- api_client: BaseApiClient,
325
312
  from_object: Union[dict[str, Any], object],
326
313
  parent_object: Optional[dict[str, Any]] = None,
327
314
  ) -> dict[str, Any]:
@@ -333,7 +320,6 @@ def _TuningValidationDataset_to_vertex(
333
320
 
334
321
 
335
322
  def _CreateTuningJobConfig_to_vertex(
336
- api_client: BaseApiClient,
337
323
  from_object: Union[dict[str, Any], object],
338
324
  parent_object: Optional[dict[str, Any]] = None,
339
325
  ) -> dict[str, Any]:
@@ -344,7 +330,7 @@ def _CreateTuningJobConfig_to_vertex(
344
330
  parent_object,
345
331
  ['supervisedTuningSpec'],
346
332
  _TuningValidationDataset_to_vertex(
347
- api_client, getv(from_object, ['validation_dataset']), to_object
333
+ getv(from_object, ['validation_dataset']), to_object
348
334
  ),
349
335
  )
350
336
 
@@ -396,7 +382,6 @@ def _CreateTuningJobConfig_to_vertex(
396
382
 
397
383
 
398
384
  def _CreateTuningJobParameters_to_vertex(
399
- api_client: BaseApiClient,
400
385
  from_object: Union[dict[str, Any], object],
401
386
  parent_object: Optional[dict[str, Any]] = None,
402
387
  ) -> dict[str, Any]:
@@ -409,7 +394,7 @@ def _CreateTuningJobParameters_to_vertex(
409
394
  to_object,
410
395
  ['supervisedTuningSpec', 'trainingDatasetUri'],
411
396
  _TuningDataset_to_vertex(
412
- api_client, getv(from_object, ['training_dataset']), to_object
397
+ getv(from_object, ['training_dataset']), to_object
413
398
  ),
414
399
  )
415
400
 
@@ -418,7 +403,7 @@ def _CreateTuningJobParameters_to_vertex(
418
403
  to_object,
419
404
  ['config'],
420
405
  _CreateTuningJobConfig_to_vertex(
421
- api_client, getv(from_object, ['config']), to_object
406
+ getv(from_object, ['config']), to_object
422
407
  ),
423
408
  )
424
409
 
@@ -426,7 +411,6 @@ def _CreateTuningJobParameters_to_vertex(
426
411
 
427
412
 
428
413
  def _TunedModelCheckpoint_from_mldev(
429
- api_client: BaseApiClient,
430
414
  from_object: Union[dict[str, Any], object],
431
415
  parent_object: Optional[dict[str, Any]] = None,
432
416
  ) -> dict[str, Any]:
@@ -436,7 +420,6 @@ def _TunedModelCheckpoint_from_mldev(
436
420
 
437
421
 
438
422
  def _TunedModel_from_mldev(
439
- api_client: BaseApiClient,
440
423
  from_object: Union[dict[str, Any], object],
441
424
  parent_object: Optional[dict[str, Any]] = None,
442
425
  ) -> dict[str, Any]:
@@ -451,7 +434,6 @@ def _TunedModel_from_mldev(
451
434
 
452
435
 
453
436
  def _TuningJob_from_mldev(
454
- api_client: BaseApiClient,
455
437
  from_object: Union[dict[str, Any], object],
456
438
  parent_object: Optional[dict[str, Any]] = None,
457
439
  ) -> dict[str, Any]:
@@ -463,7 +445,7 @@ def _TuningJob_from_mldev(
463
445
  setv(
464
446
  to_object,
465
447
  ['state'],
466
- t.t_tuning_job_status(api_client, getv(from_object, ['state'])),
448
+ t.t_tuning_job_status(getv(from_object, ['state'])),
467
449
  )
468
450
 
469
451
  if getv(from_object, ['createTime']) is not None:
@@ -496,9 +478,7 @@ def _TuningJob_from_mldev(
496
478
  setv(
497
479
  to_object,
498
480
  ['tuned_model'],
499
- _TunedModel_from_mldev(
500
- api_client, getv(from_object, ['_self']), to_object
501
- ),
481
+ _TunedModel_from_mldev(getv(from_object, ['_self']), to_object),
502
482
  )
503
483
 
504
484
  if getv(from_object, ['distillationSpec']) is not None:
@@ -531,7 +511,6 @@ def _TuningJob_from_mldev(
531
511
 
532
512
 
533
513
  def _ListTuningJobsResponse_from_mldev(
534
- api_client: BaseApiClient,
535
514
  from_object: Union[dict[str, Any], object],
536
515
  parent_object: Optional[dict[str, Any]] = None,
537
516
  ) -> dict[str, Any]:
@@ -544,7 +523,7 @@ def _ListTuningJobsResponse_from_mldev(
544
523
  to_object,
545
524
  ['tuning_jobs'],
546
525
  [
547
- _TuningJob_from_mldev(api_client, item, to_object)
526
+ _TuningJob_from_mldev(item, to_object)
548
527
  for item in getv(from_object, ['tunedModels'])
549
528
  ],
550
529
  )
@@ -553,7 +532,6 @@ def _ListTuningJobsResponse_from_mldev(
553
532
 
554
533
 
555
534
  def _Operation_from_mldev(
556
- api_client: BaseApiClient,
557
535
  from_object: Union[dict[str, Any], object],
558
536
  parent_object: Optional[dict[str, Any]] = None,
559
537
  ) -> dict[str, Any]:
@@ -574,7 +552,6 @@ def _Operation_from_mldev(
574
552
 
575
553
 
576
554
  def _TunedModelCheckpoint_from_vertex(
577
- api_client: BaseApiClient,
578
555
  from_object: Union[dict[str, Any], object],
579
556
  parent_object: Optional[dict[str, Any]] = None,
580
557
  ) -> dict[str, Any]:
@@ -595,7 +572,6 @@ def _TunedModelCheckpoint_from_vertex(
595
572
 
596
573
 
597
574
  def _TunedModel_from_vertex(
598
- api_client: BaseApiClient,
599
575
  from_object: Union[dict[str, Any], object],
600
576
  parent_object: Optional[dict[str, Any]] = None,
601
577
  ) -> dict[str, Any]:
@@ -611,7 +587,7 @@ def _TunedModel_from_vertex(
611
587
  to_object,
612
588
  ['checkpoints'],
613
589
  [
614
- _TunedModelCheckpoint_from_vertex(api_client, item, to_object)
590
+ _TunedModelCheckpoint_from_vertex(item, to_object)
615
591
  for item in getv(from_object, ['checkpoints'])
616
592
  ],
617
593
  )
@@ -620,7 +596,6 @@ def _TunedModel_from_vertex(
620
596
 
621
597
 
622
598
  def _TuningJob_from_vertex(
623
- api_client: BaseApiClient,
624
599
  from_object: Union[dict[str, Any], object],
625
600
  parent_object: Optional[dict[str, Any]] = None,
626
601
  ) -> dict[str, Any]:
@@ -632,7 +607,7 @@ def _TuningJob_from_vertex(
632
607
  setv(
633
608
  to_object,
634
609
  ['state'],
635
- t.t_tuning_job_status(api_client, getv(from_object, ['state'])),
610
+ t.t_tuning_job_status(getv(from_object, ['state'])),
636
611
  )
637
612
 
638
613
  if getv(from_object, ['createTime']) is not None:
@@ -660,9 +635,7 @@ def _TuningJob_from_vertex(
660
635
  setv(
661
636
  to_object,
662
637
  ['tuned_model'],
663
- _TunedModel_from_vertex(
664
- api_client, getv(from_object, ['tunedModel']), to_object
665
- ),
638
+ _TunedModel_from_vertex(getv(from_object, ['tunedModel']), to_object),
666
639
  )
667
640
 
668
641
  if getv(from_object, ['supervisedTuningSpec']) is not None:
@@ -717,7 +690,6 @@ def _TuningJob_from_vertex(
717
690
 
718
691
 
719
692
  def _ListTuningJobsResponse_from_vertex(
720
- api_client: BaseApiClient,
721
693
  from_object: Union[dict[str, Any], object],
722
694
  parent_object: Optional[dict[str, Any]] = None,
723
695
  ) -> dict[str, Any]:
@@ -730,7 +702,7 @@ def _ListTuningJobsResponse_from_vertex(
730
702
  to_object,
731
703
  ['tuning_jobs'],
732
704
  [
733
- _TuningJob_from_vertex(api_client, item, to_object)
705
+ _TuningJob_from_vertex(item, to_object)
734
706
  for item in getv(from_object, ['tuningJobs'])
735
707
  ],
736
708
  )
@@ -763,18 +735,14 @@ class Tunings(_api_module.BaseModule):
763
735
  request_url_dict: Optional[dict[str, str]]
764
736
 
765
737
  if self._api_client.vertexai:
766
- request_dict = _GetTuningJobParameters_to_vertex(
767
- self._api_client, parameter_model
768
- )
738
+ request_dict = _GetTuningJobParameters_to_vertex(parameter_model)
769
739
  request_url_dict = request_dict.get('_url')
770
740
  if request_url_dict:
771
741
  path = '{name}'.format_map(request_url_dict)
772
742
  else:
773
743
  path = '{name}'
774
744
  else:
775
- request_dict = _GetTuningJobParameters_to_mldev(
776
- self._api_client, parameter_model
777
- )
745
+ request_dict = _GetTuningJobParameters_to_mldev(parameter_model)
778
746
  request_url_dict = request_dict.get('_url')
779
747
  if request_url_dict:
780
748
  path = '{name}'.format_map(request_url_dict)
@@ -796,15 +764,15 @@ class Tunings(_api_module.BaseModule):
796
764
  request_dict = _common.convert_to_dict(request_dict)
797
765
  request_dict = _common.encode_unserializable_types(request_dict)
798
766
 
799
- response_dict = self._api_client.request(
800
- 'get', path, request_dict, http_options
801
- )
767
+ response = self._api_client.request('get', path, request_dict, http_options)
768
+
769
+ response_dict = '' if not response.body else json.loads(response.body)
802
770
 
803
771
  if self._api_client.vertexai:
804
- response_dict = _TuningJob_from_vertex(self._api_client, response_dict)
772
+ response_dict = _TuningJob_from_vertex(response_dict)
805
773
 
806
774
  else:
807
- response_dict = _TuningJob_from_mldev(self._api_client, response_dict)
775
+ response_dict = _TuningJob_from_mldev(response_dict)
808
776
 
809
777
  return_value = types.TuningJob._from_response(
810
778
  response=response_dict, kwargs=parameter_model.model_dump()
@@ -831,18 +799,14 @@ class Tunings(_api_module.BaseModule):
831
799
  request_url_dict: Optional[dict[str, str]]
832
800
 
833
801
  if self._api_client.vertexai:
834
- request_dict = _ListTuningJobsParameters_to_vertex(
835
- self._api_client, parameter_model
836
- )
802
+ request_dict = _ListTuningJobsParameters_to_vertex(parameter_model)
837
803
  request_url_dict = request_dict.get('_url')
838
804
  if request_url_dict:
839
805
  path = 'tuningJobs'.format_map(request_url_dict)
840
806
  else:
841
807
  path = 'tuningJobs'
842
808
  else:
843
- request_dict = _ListTuningJobsParameters_to_mldev(
844
- self._api_client, parameter_model
845
- )
809
+ request_dict = _ListTuningJobsParameters_to_mldev(parameter_model)
846
810
  request_url_dict = request_dict.get('_url')
847
811
  if request_url_dict:
848
812
  path = 'tunedModels'.format_map(request_url_dict)
@@ -864,19 +828,15 @@ class Tunings(_api_module.BaseModule):
864
828
  request_dict = _common.convert_to_dict(request_dict)
865
829
  request_dict = _common.encode_unserializable_types(request_dict)
866
830
 
867
- response_dict = self._api_client.request(
868
- 'get', path, request_dict, http_options
869
- )
831
+ response = self._api_client.request('get', path, request_dict, http_options)
832
+
833
+ response_dict = '' if not response.body else json.loads(response.body)
870
834
 
871
835
  if self._api_client.vertexai:
872
- response_dict = _ListTuningJobsResponse_from_vertex(
873
- self._api_client, response_dict
874
- )
836
+ response_dict = _ListTuningJobsResponse_from_vertex(response_dict)
875
837
 
876
838
  else:
877
- response_dict = _ListTuningJobsResponse_from_mldev(
878
- self._api_client, response_dict
879
- )
839
+ response_dict = _ListTuningJobsResponse_from_mldev(response_dict)
880
840
 
881
841
  return_value = types.ListTuningJobsResponse._from_response(
882
842
  response=response_dict, kwargs=parameter_model.model_dump()
@@ -912,9 +872,7 @@ class Tunings(_api_module.BaseModule):
912
872
  if not self._api_client.vertexai:
913
873
  raise ValueError('This method is only supported in the Vertex AI client.')
914
874
  else:
915
- request_dict = _CreateTuningJobParameters_to_vertex(
916
- self._api_client, parameter_model
917
- )
875
+ request_dict = _CreateTuningJobParameters_to_vertex(parameter_model)
918
876
  request_url_dict = request_dict.get('_url')
919
877
  if request_url_dict:
920
878
  path = 'tuningJobs'.format_map(request_url_dict)
@@ -937,12 +895,14 @@ class Tunings(_api_module.BaseModule):
937
895
  request_dict = _common.convert_to_dict(request_dict)
938
896
  request_dict = _common.encode_unserializable_types(request_dict)
939
897
 
940
- response_dict = self._api_client.request(
898
+ response = self._api_client.request(
941
899
  'post', path, request_dict, http_options
942
900
  )
943
901
 
902
+ response_dict = '' if not response.body else json.loads(response.body)
903
+
944
904
  if self._api_client.vertexai:
945
- response_dict = _TuningJob_from_vertex(self._api_client, response_dict)
905
+ response_dict = _TuningJob_from_vertex(response_dict)
946
906
 
947
907
  return_value = types.TuningJob._from_response(
948
908
  response=response_dict, kwargs=parameter_model.model_dump()
@@ -980,9 +940,7 @@ class Tunings(_api_module.BaseModule):
980
940
  'This method is only supported in the Gemini Developer client.'
981
941
  )
982
942
  else:
983
- request_dict = _CreateTuningJobParameters_to_mldev(
984
- self._api_client, parameter_model
985
- )
943
+ request_dict = _CreateTuningJobParameters_to_mldev(parameter_model)
986
944
  request_url_dict = request_dict.get('_url')
987
945
  if request_url_dict:
988
946
  path = 'tunedModels'.format_map(request_url_dict)
@@ -1005,12 +963,14 @@ class Tunings(_api_module.BaseModule):
1005
963
  request_dict = _common.convert_to_dict(request_dict)
1006
964
  request_dict = _common.encode_unserializable_types(request_dict)
1007
965
 
1008
- response_dict = self._api_client.request(
966
+ response = self._api_client.request(
1009
967
  'post', path, request_dict, http_options
1010
968
  )
1011
969
 
970
+ response_dict = '' if not response.body else json.loads(response.body)
971
+
1012
972
  if not self._api_client.vertexai:
1013
- response_dict = _Operation_from_mldev(self._api_client, response_dict)
973
+ response_dict = _Operation_from_mldev(response_dict)
1014
974
 
1015
975
  return_value = types.Operation._from_response(
1016
976
  response=response_dict, kwargs=parameter_model.model_dump()
@@ -1111,18 +1071,14 @@ class AsyncTunings(_api_module.BaseModule):
1111
1071
  request_url_dict: Optional[dict[str, str]]
1112
1072
 
1113
1073
  if self._api_client.vertexai:
1114
- request_dict = _GetTuningJobParameters_to_vertex(
1115
- self._api_client, parameter_model
1116
- )
1074
+ request_dict = _GetTuningJobParameters_to_vertex(parameter_model)
1117
1075
  request_url_dict = request_dict.get('_url')
1118
1076
  if request_url_dict:
1119
1077
  path = '{name}'.format_map(request_url_dict)
1120
1078
  else:
1121
1079
  path = '{name}'
1122
1080
  else:
1123
- request_dict = _GetTuningJobParameters_to_mldev(
1124
- self._api_client, parameter_model
1125
- )
1081
+ request_dict = _GetTuningJobParameters_to_mldev(parameter_model)
1126
1082
  request_url_dict = request_dict.get('_url')
1127
1083
  if request_url_dict:
1128
1084
  path = '{name}'.format_map(request_url_dict)
@@ -1144,15 +1100,17 @@ class AsyncTunings(_api_module.BaseModule):
1144
1100
  request_dict = _common.convert_to_dict(request_dict)
1145
1101
  request_dict = _common.encode_unserializable_types(request_dict)
1146
1102
 
1147
- response_dict = await self._api_client.async_request(
1103
+ response = await self._api_client.async_request(
1148
1104
  'get', path, request_dict, http_options
1149
1105
  )
1150
1106
 
1107
+ response_dict = '' if not response.body else json.loads(response.body)
1108
+
1151
1109
  if self._api_client.vertexai:
1152
- response_dict = _TuningJob_from_vertex(self._api_client, response_dict)
1110
+ response_dict = _TuningJob_from_vertex(response_dict)
1153
1111
 
1154
1112
  else:
1155
- response_dict = _TuningJob_from_mldev(self._api_client, response_dict)
1113
+ response_dict = _TuningJob_from_mldev(response_dict)
1156
1114
 
1157
1115
  return_value = types.TuningJob._from_response(
1158
1116
  response=response_dict, kwargs=parameter_model.model_dump()
@@ -1179,18 +1137,14 @@ class AsyncTunings(_api_module.BaseModule):
1179
1137
  request_url_dict: Optional[dict[str, str]]
1180
1138
 
1181
1139
  if self._api_client.vertexai:
1182
- request_dict = _ListTuningJobsParameters_to_vertex(
1183
- self._api_client, parameter_model
1184
- )
1140
+ request_dict = _ListTuningJobsParameters_to_vertex(parameter_model)
1185
1141
  request_url_dict = request_dict.get('_url')
1186
1142
  if request_url_dict:
1187
1143
  path = 'tuningJobs'.format_map(request_url_dict)
1188
1144
  else:
1189
1145
  path = 'tuningJobs'
1190
1146
  else:
1191
- request_dict = _ListTuningJobsParameters_to_mldev(
1192
- self._api_client, parameter_model
1193
- )
1147
+ request_dict = _ListTuningJobsParameters_to_mldev(parameter_model)
1194
1148
  request_url_dict = request_dict.get('_url')
1195
1149
  if request_url_dict:
1196
1150
  path = 'tunedModels'.format_map(request_url_dict)
@@ -1212,19 +1166,17 @@ class AsyncTunings(_api_module.BaseModule):
1212
1166
  request_dict = _common.convert_to_dict(request_dict)
1213
1167
  request_dict = _common.encode_unserializable_types(request_dict)
1214
1168
 
1215
- response_dict = await self._api_client.async_request(
1169
+ response = await self._api_client.async_request(
1216
1170
  'get', path, request_dict, http_options
1217
1171
  )
1218
1172
 
1173
+ response_dict = '' if not response.body else json.loads(response.body)
1174
+
1219
1175
  if self._api_client.vertexai:
1220
- response_dict = _ListTuningJobsResponse_from_vertex(
1221
- self._api_client, response_dict
1222
- )
1176
+ response_dict = _ListTuningJobsResponse_from_vertex(response_dict)
1223
1177
 
1224
1178
  else:
1225
- response_dict = _ListTuningJobsResponse_from_mldev(
1226
- self._api_client, response_dict
1227
- )
1179
+ response_dict = _ListTuningJobsResponse_from_mldev(response_dict)
1228
1180
 
1229
1181
  return_value = types.ListTuningJobsResponse._from_response(
1230
1182
  response=response_dict, kwargs=parameter_model.model_dump()
@@ -1260,9 +1212,7 @@ class AsyncTunings(_api_module.BaseModule):
1260
1212
  if not self._api_client.vertexai:
1261
1213
  raise ValueError('This method is only supported in the Vertex AI client.')
1262
1214
  else:
1263
- request_dict = _CreateTuningJobParameters_to_vertex(
1264
- self._api_client, parameter_model
1265
- )
1215
+ request_dict = _CreateTuningJobParameters_to_vertex(parameter_model)
1266
1216
  request_url_dict = request_dict.get('_url')
1267
1217
  if request_url_dict:
1268
1218
  path = 'tuningJobs'.format_map(request_url_dict)
@@ -1285,12 +1235,14 @@ class AsyncTunings(_api_module.BaseModule):
1285
1235
  request_dict = _common.convert_to_dict(request_dict)
1286
1236
  request_dict = _common.encode_unserializable_types(request_dict)
1287
1237
 
1288
- response_dict = await self._api_client.async_request(
1238
+ response = await self._api_client.async_request(
1289
1239
  'post', path, request_dict, http_options
1290
1240
  )
1291
1241
 
1242
+ response_dict = '' if not response.body else json.loads(response.body)
1243
+
1292
1244
  if self._api_client.vertexai:
1293
- response_dict = _TuningJob_from_vertex(self._api_client, response_dict)
1245
+ response_dict = _TuningJob_from_vertex(response_dict)
1294
1246
 
1295
1247
  return_value = types.TuningJob._from_response(
1296
1248
  response=response_dict, kwargs=parameter_model.model_dump()
@@ -1328,9 +1280,7 @@ class AsyncTunings(_api_module.BaseModule):
1328
1280
  'This method is only supported in the Gemini Developer client.'
1329
1281
  )
1330
1282
  else:
1331
- request_dict = _CreateTuningJobParameters_to_mldev(
1332
- self._api_client, parameter_model
1333
- )
1283
+ request_dict = _CreateTuningJobParameters_to_mldev(parameter_model)
1334
1284
  request_url_dict = request_dict.get('_url')
1335
1285
  if request_url_dict:
1336
1286
  path = 'tunedModels'.format_map(request_url_dict)
@@ -1353,12 +1303,14 @@ class AsyncTunings(_api_module.BaseModule):
1353
1303
  request_dict = _common.convert_to_dict(request_dict)
1354
1304
  request_dict = _common.encode_unserializable_types(request_dict)
1355
1305
 
1356
- response_dict = await self._api_client.async_request(
1306
+ response = await self._api_client.async_request(
1357
1307
  'post', path, request_dict, http_options
1358
1308
  )
1359
1309
 
1310
+ response_dict = '' if not response.body else json.loads(response.body)
1311
+
1360
1312
  if not self._api_client.vertexai:
1361
- response_dict = _Operation_from_mldev(self._api_client, response_dict)
1313
+ response_dict = _Operation_from_mldev(response_dict)
1362
1314
 
1363
1315
  return_value = types.Operation._from_response(
1364
1316
  response=response_dict, kwargs=parameter_model.model_dump()