google-genai 1.37.0__py3-none-any.whl → 1.39.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.
@@ -64,6 +64,14 @@ else:
64
64
  McpTool = None
65
65
 
66
66
 
67
+ metric_name_sdk_api_map = {
68
+ 'exact_match': 'exactMatchSpec',
69
+ 'bleu': 'bleuSpec',
70
+ 'rouge_spec': 'rougeSpec',
71
+ }
72
+ metric_name_api_sdk_map = {v: k for k, v in metric_name_sdk_api_map.items()}
73
+
74
+
67
75
  def _resource_name(
68
76
  client: _api_client.BaseApiClient,
69
77
  resource_name: str,
@@ -309,13 +317,6 @@ def t_blobs(
309
317
 
310
318
 
311
319
  def t_blob(blob: types.BlobImageUnionDict) -> types.Blob:
312
- try:
313
- import PIL.Image
314
-
315
- PIL_Image = PIL.Image.Image
316
- except ImportError:
317
- PIL_Image = None
318
-
319
320
  if not blob:
320
321
  raise ValueError('blob is required.')
321
322
 
@@ -325,8 +326,16 @@ def t_blob(blob: types.BlobImageUnionDict) -> types.Blob:
325
326
  if isinstance(blob, dict):
326
327
  return types.Blob.model_validate(blob)
327
328
 
328
- if PIL_Image is not None and isinstance(blob, PIL_Image):
329
- return pil_to_blob(blob)
329
+ if 'image' in blob.__class__.__name__.lower():
330
+ try:
331
+ import PIL.Image
332
+
333
+ PIL_Image = PIL.Image.Image
334
+ except ImportError:
335
+ PIL_Image = None
336
+
337
+ if PIL_Image is not None and isinstance(blob, PIL_Image):
338
+ return pil_to_blob(blob)
330
339
 
331
340
  raise TypeError(
332
341
  f'Could not parse input as Blob. Unsupported blob type: {type(blob)}'
@@ -348,19 +357,10 @@ def t_audio_blob(blob: types.BlobOrDict) -> types.Blob:
348
357
 
349
358
 
350
359
  def t_part(part: Optional[types.PartUnionDict]) -> types.Part:
351
- try:
352
- import PIL.Image
353
-
354
- PIL_Image = PIL.Image.Image
355
- except ImportError:
356
- PIL_Image = None
357
-
358
360
  if part is None:
359
361
  raise ValueError('content part is required.')
360
362
  if isinstance(part, str):
361
363
  return types.Part(text=part)
362
- if PIL_Image is not None and isinstance(part, PIL_Image):
363
- return types.Part(inline_data=pil_to_blob(part))
364
364
  if isinstance(part, types.File):
365
365
  if not part.uri or not part.mime_type:
366
366
  raise ValueError('file uri and mime_type are required.')
@@ -369,6 +369,17 @@ def t_part(part: Optional[types.PartUnionDict]) -> types.Part:
369
369
  return types.Part.model_validate(part)
370
370
  if isinstance(part, types.Part):
371
371
  return part
372
+
373
+ if 'image' in part.__class__.__name__.lower():
374
+ try:
375
+ import PIL.Image
376
+
377
+ PIL_Image = PIL.Image.Image
378
+ except ImportError:
379
+ PIL_Image = None
380
+
381
+ if PIL_Image is not None and isinstance(part, PIL_Image):
382
+ return types.Part(inline_data=pil_to_blob(part))
372
383
  raise ValueError(f'Unsupported content part type: {type(part)}')
373
384
 
374
385
 
@@ -470,13 +481,6 @@ def t_contents(
470
481
  if not isinstance(contents, list):
471
482
  return [t_content(contents)]
472
483
 
473
- try:
474
- import PIL.Image
475
-
476
- PIL_Image = PIL.Image.Image
477
- except ImportError:
478
- PIL_Image = None
479
-
480
484
  result: list[types.Content] = []
481
485
  accumulated_parts: list[types.Part] = []
482
486
 
@@ -486,7 +490,6 @@ def t_contents(
486
490
  if (
487
491
  isinstance(part, str)
488
492
  or isinstance(part, types.File)
489
- or (PIL_Image is not None and isinstance(part, PIL_Image))
490
493
  or isinstance(part, types.Part)
491
494
  ):
492
495
  return True
@@ -498,6 +501,17 @@ def t_contents(
498
501
  except pydantic.ValidationError:
499
502
  return False
500
503
 
504
+ if 'image' in part.__class__.__name__.lower():
505
+ try:
506
+ import PIL.Image
507
+
508
+ PIL_Image = PIL.Image.Image
509
+ except ImportError:
510
+ PIL_Image = None
511
+
512
+ if PIL_Image is not None and isinstance(part, PIL_Image):
513
+ return True
514
+
501
515
  return False
502
516
 
503
517
  def _is_user_part(part: types.Part) -> bool:
@@ -1100,12 +1114,16 @@ def t_job_state(state: str) -> str:
1100
1114
  return 'JOB_STATE_UNSPECIFIED'
1101
1115
  elif state == 'BATCH_STATE_PENDING':
1102
1116
  return 'JOB_STATE_PENDING'
1117
+ elif state == 'BATCH_STATE_RUNNING':
1118
+ return 'JOB_STATE_RUNNING'
1103
1119
  elif state == 'BATCH_STATE_SUCCEEDED':
1104
1120
  return 'JOB_STATE_SUCCEEDED'
1105
1121
  elif state == 'BATCH_STATE_FAILED':
1106
1122
  return 'JOB_STATE_FAILED'
1107
1123
  elif state == 'BATCH_STATE_CANCELLED':
1108
1124
  return 'JOB_STATE_CANCELLED'
1125
+ elif state == 'BATCH_STATE_EXPIRED':
1126
+ return 'JOB_STATE_EXPIRED'
1109
1127
  else:
1110
1128
  return state
1111
1129