@@ -2257,6 +2257,17 @@ def create(
2257
2257
)
2258
2258
print(batch_job.state)
2259
2259
"""
2260
+ parameter_model = types ._CreateBatchJobParameters (
2261
+ model = model ,
2262
+ src = src ,
2263
+ config = config ,
2264
+ )
2265
+ http_options : Optional [types .HttpOptions ] = None
2266
+ if (
2267
+ parameter_model .config is not None
2268
+ and parameter_model .config .http_options is not None
2269
+ ):
2270
+ http_options = parameter_model .config .http_options
2260
2271
if self ._api_client .vertexai :
2261
2272
if isinstance (src , list ):
2262
2273
raise ValueError (
@@ -2265,6 +2276,65 @@ def create(
2265
2276
)
2266
2277
2267
2278
config = _extra_utils .format_destination (src , config )
2279
+ else :
2280
+ if isinstance (parameter_model .src , list ) or (
2281
+ not isinstance (parameter_model .src , str )
2282
+ and parameter_model .src
2283
+ and parameter_model .src .inlined_requests
2284
+ ):
2285
+ # Handle system instruction in InlinedRequests.
2286
+ request_url_dict : Optional [dict [str , str ]]
2287
+ request_dict : dict [str , Any ] = _CreateBatchJobParameters_to_mldev (
2288
+ self ._api_client , parameter_model
2289
+ )
2290
+ request_url_dict = request_dict .get ('_url' )
2291
+ if request_url_dict :
2292
+ path = '{model}:batchGenerateContent' .format_map (request_url_dict )
2293
+ else :
2294
+ path = '{model}:batchGenerateContent'
2295
+ query_params = request_dict .get ('_query' )
2296
+ if query_params :
2297
+ path = f'{ path } ?{ urlencode (query_params )} '
2298
+ request_dict .pop ('config' , None )
2299
+
2300
+ request_dict = _common .convert_to_dict (request_dict )
2301
+ request_dict = _common .encode_unserializable_types (request_dict )
2302
+ # Move system instruction to 'request':
2303
+ # {'systemInstruction': system_instruction}
2304
+ requests = []
2305
+ batch_dict = request_dict .get ('batch' )
2306
+ if batch_dict and isinstance (batch_dict , dict ):
2307
+ input_config_dict = batch_dict .get ('inputConfig' )
2308
+ if input_config_dict and isinstance (input_config_dict , dict ):
2309
+ requests_dict = input_config_dict .get ('requests' )
2310
+ if requests_dict and isinstance (requests_dict , dict ):
2311
+ requests = requests_dict .get ('requests' )
2312
+ new_requests = []
2313
+ if requests :
2314
+ for req in requests :
2315
+ if req .get ('systemInstruction' ):
2316
+ value = req .pop ('systemInstruction' )
2317
+ req ['request' ].update ({'systemInstruction' : value })
2318
+ new_requests .append (req )
2319
+ request_dict ['batch' ]['inputConfig' ]['requests' ][ # type: ignore
2320
+ 'requests'
2321
+ ] = new_requests
2322
+
2323
+ response = self ._api_client .request (
2324
+ 'post' , path , request_dict , http_options
2325
+ )
2326
+
2327
+ response_dict = '' if not response .body else json .loads (response .body )
2328
+
2329
+ response_dict = _BatchJob_from_mldev (response_dict )
2330
+
2331
+ return_value = types .BatchJob ._from_response (
2332
+ response = response_dict , kwargs = parameter_model .model_dump ()
2333
+ )
2334
+
2335
+ self ._api_client ._verify_response (return_value )
2336
+ return return_value
2337
+
2268
2338
return self ._create (model = model , src = src , config = config )
2269
2339
2270
2340
def list (
@@ -2691,6 +2761,17 @@ async def create(
2691
2761
src="gs://path/to/input/data",
2692
2762
)
2693
2763
"""
2764
+ parameter_model = types ._CreateBatchJobParameters (
2765
+ model = model ,
2766
+ src = src ,
2767
+ config = config ,
2768
+ )
2769
+ http_options : Optional [types .HttpOptions ] = None
2770
+ if (
2771
+ parameter_model .config is not None
2772
+ and parameter_model .config .http_options is not None
2773
+ ):
2774
+ http_options = parameter_model .config .http_options
2694
2775
if self ._api_client .vertexai :
2695
2776
if isinstance (src , list ):
2696
2777
raise ValueError (
@@ -2699,6 +2780,65 @@ async def create(
2699
2780
)
2700
2781
2701
2782
config = _extra_utils .format_destination (src , config )
2783
+ else :
2784
+ if isinstance (parameter_model .src , list ) or (
2785
+ not isinstance (parameter_model .src , str )
2786
+ and parameter_model .src
2787
+ and parameter_model .src .inlined_requests
2788
+ ):
2789
+ # Handle system instruction in InlinedRequests.
2790
+ request_url_dict : Optional [dict [str , str ]]
2791
+ request_dict : dict [str , Any ] = _CreateBatchJobParameters_to_mldev (
2792
+ self ._api_client , parameter_model
2793
+ )
2794
+ request_url_dict = request_dict .get ('_url' )
2795
+ if request_url_dict :
2796
+ path = '{model}:batchGenerateContent' .format_map (request_url_dict )
2797
+ else :
2798
+ path = '{model}:batchGenerateContent'
2799
+ query_params = request_dict .get ('_query' )
2800
+ if query_params :
2801
+ path = f'{ path } ?{ urlencode (query_params )} '
2802
+ request_dict .pop ('config' , None )
2803
+
2804
+ request_dict = _common .convert_to_dict (request_dict )
2805
+ request_dict = _common .encode_unserializable_types (request_dict )
2806
+ # Move system instruction to 'request':
2807
+ # {'systemInstruction': system_instruction}
2808
+ requests = []
2809
+ batch_dict = request_dict .get ('batch' )
2810
+ if batch_dict and isinstance (batch_dict , dict ):
2811
+ input_config_dict = batch_dict .get ('inputConfig' )
2812
+ if input_config_dict and isinstance (input_config_dict , dict ):
2813
+ requests_dict = input_config_dict .get ('requests' )
2814
+ if requests_dict and isinstance (requests_dict , dict ):
2815
+ requests = requests_dict .get ('requests' )
2816
+ new_requests = []
2817
+ if requests :
2818
+ for req in requests :
2819
+ if req .get ('systemInstruction' ):
2820
+ value = req .pop ('systemInstruction' )
2821
+ req ['request' ].update ({'systemInstruction' : value })
2822
+ new_requests .append (req )
2823
+ request_dict ['batch' ]['inputConfig' ]['requests' ][ # type: ignore
2824
+ 'requests'
2825
+ ] = new_requests
2826
+
2827
+ response = await self ._api_client .async_request (
2828
+ 'post' , path , request_dict , http_options
2829
+ )
2830
+
2831
+ response_dict = '' if not response .body else json .loads (response .body )
2832
+
2833
+ response_dict = _BatchJob_from_mldev (response_dict )
2834
+
2835
+ return_value = types .BatchJob ._from_response (
2836
+ response = response_dict , kwargs = parameter_model .model_dump ()
2837
+ )
2838
+
2839
+ self ._api_client ._verify_response (return_value )
2840
+ return return_value
2841
+
2702
2842
return await self ._create (model = model , src = src , config = config )
2703
2843
2704
2844
async def list (
0 commit comments