Skip to content

Commit 0035182

Browse files
matthew29tangcopybara-github
authored andcommitted
feat: Add Image Grounding support to GoogleSearch tool
PiperOrigin-RevId: 875338036
1 parent 8b2a4e0 commit 0035182

6 files changed

Lines changed: 383 additions & 173 deletions

File tree

google/genai/_live_converters.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ def _GoogleSearch_to_mldev(
270270
parent_object: Optional[dict[str, Any]] = None,
271271
) -> dict[str, Any]:
272272
to_object: dict[str, Any] = {}
273+
if getv(from_object, ['search_types']) is not None:
274+
setv(to_object, ['searchTypes'], getv(from_object, ['search_types']))
275+
273276
if getv(from_object, ['exclude_domains']) is not None:
274277
raise ValueError(
275278
'exclude_domains parameter is not supported in Gemini API.'
@@ -1358,6 +1361,13 @@ def _Tool_to_mldev(
13581361
if getv(from_object, ['file_search']) is not None:
13591362
setv(to_object, ['fileSearch'], getv(from_object, ['file_search']))
13601363

1364+
if getv(from_object, ['google_search']) is not None:
1365+
setv(
1366+
to_object,
1367+
['googleSearch'],
1368+
_GoogleSearch_to_mldev(getv(from_object, ['google_search']), to_object),
1369+
)
1370+
13611371
if getv(from_object, ['code_execution']) is not None:
13621372
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
13631373

@@ -1380,13 +1390,6 @@ def _Tool_to_mldev(
13801390
_GoogleMaps_to_mldev(getv(from_object, ['google_maps']), to_object),
13811391
)
13821392

1383-
if getv(from_object, ['google_search']) is not None:
1384-
setv(
1385-
to_object,
1386-
['googleSearch'],
1387-
_GoogleSearch_to_mldev(getv(from_object, ['google_search']), to_object),
1388-
)
1389-
13901393
if getv(from_object, ['google_search_retrieval']) is not None:
13911394
setv(
13921395
to_object,
@@ -1421,6 +1424,9 @@ def _Tool_to_vertex(
14211424
if getv(from_object, ['file_search']) is not None:
14221425
raise ValueError('file_search parameter is not supported in Vertex AI.')
14231426

1427+
if getv(from_object, ['google_search']) is not None:
1428+
setv(to_object, ['googleSearch'], getv(from_object, ['google_search']))
1429+
14241430
if getv(from_object, ['code_execution']) is not None:
14251431
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
14261432

@@ -1444,9 +1450,6 @@ def _Tool_to_vertex(
14441450
if getv(from_object, ['google_maps']) is not None:
14451451
setv(to_object, ['googleMaps'], getv(from_object, ['google_maps']))
14461452

1447-
if getv(from_object, ['google_search']) is not None:
1448-
setv(to_object, ['googleSearch'], getv(from_object, ['google_search']))
1449-
14501453
if getv(from_object, ['google_search_retrieval']) is not None:
14511454
setv(
14521455
to_object,

google/genai/_tokens_converters.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ def _GoogleSearch_to_mldev(
190190
parent_object: Optional[dict[str, Any]] = None,
191191
) -> dict[str, Any]:
192192
to_object: dict[str, Any] = {}
193+
if getv(from_object, ['search_types']) is not None:
194+
setv(to_object, ['searchTypes'], getv(from_object, ['search_types']))
195+
193196
if getv(from_object, ['exclude_domains']) is not None:
194197
raise ValueError(
195198
'exclude_domains parameter is not supported in Gemini API.'
@@ -483,6 +486,13 @@ def _Tool_to_mldev(
483486
if getv(from_object, ['file_search']) is not None:
484487
setv(to_object, ['fileSearch'], getv(from_object, ['file_search']))
485488

489+
if getv(from_object, ['google_search']) is not None:
490+
setv(
491+
to_object,
492+
['googleSearch'],
493+
_GoogleSearch_to_mldev(getv(from_object, ['google_search']), to_object),
494+
)
495+
486496
if getv(from_object, ['code_execution']) is not None:
487497
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
488498

@@ -505,13 +515,6 @@ def _Tool_to_mldev(
505515
_GoogleMaps_to_mldev(getv(from_object, ['google_maps']), to_object),
506516
)
507517

508-
if getv(from_object, ['google_search']) is not None:
509-
setv(
510-
to_object,
511-
['googleSearch'],
512-
_GoogleSearch_to_mldev(getv(from_object, ['google_search']), to_object),
513-
)
514-
515518
if getv(from_object, ['google_search_retrieval']) is not None:
516519
setv(
517520
to_object,

google/genai/batches.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -408,16 +408,16 @@ def _Candidate_from_mldev(
408408
if getv(from_object, ['finishReason']) is not None:
409409
setv(to_object, ['finish_reason'], getv(from_object, ['finishReason']))
410410

411-
if getv(from_object, ['avgLogprobs']) is not None:
412-
setv(to_object, ['avg_logprobs'], getv(from_object, ['avgLogprobs']))
413-
414411
if getv(from_object, ['groundingMetadata']) is not None:
415412
setv(
416413
to_object,
417414
['grounding_metadata'],
418415
getv(from_object, ['groundingMetadata']),
419416
)
420417

418+
if getv(from_object, ['avgLogprobs']) is not None:
419+
setv(to_object, ['avg_logprobs'], getv(from_object, ['avgLogprobs']))
420+
421421
if getv(from_object, ['index']) is not None:
422422
setv(to_object, ['index'], getv(from_object, ['index']))
423423

@@ -1107,6 +1107,9 @@ def _GoogleSearch_to_mldev(
11071107
parent_object: Optional[dict[str, Any]] = None,
11081108
) -> dict[str, Any]:
11091109
to_object: dict[str, Any] = {}
1110+
if getv(from_object, ['search_types']) is not None:
1111+
setv(to_object, ['searchTypes'], getv(from_object, ['search_types']))
1112+
11101113
if getv(from_object, ['exclude_domains']) is not None:
11111114
raise ValueError(
11121115
'exclude_domains parameter is not supported in Gemini API.'
@@ -1141,6 +1144,11 @@ def _ImageConfig_to_mldev(
11411144
'person_generation parameter is not supported in Gemini API.'
11421145
)
11431146

1147+
if getv(from_object, ['prominent_people']) is not None:
1148+
raise ValueError(
1149+
'prominent_people parameter is not supported in Gemini API.'
1150+
)
1151+
11441152
if getv(from_object, ['output_mime_type']) is not None:
11451153
raise ValueError(
11461154
'output_mime_type parameter is not supported in Gemini API.'
@@ -1459,6 +1467,13 @@ def _Tool_to_mldev(
14591467
if getv(from_object, ['file_search']) is not None:
14601468
setv(to_object, ['fileSearch'], getv(from_object, ['file_search']))
14611469

1470+
if getv(from_object, ['google_search']) is not None:
1471+
setv(
1472+
to_object,
1473+
['googleSearch'],
1474+
_GoogleSearch_to_mldev(getv(from_object, ['google_search']), to_object),
1475+
)
1476+
14621477
if getv(from_object, ['code_execution']) is not None:
14631478
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
14641479

@@ -1481,13 +1496,6 @@ def _Tool_to_mldev(
14811496
_GoogleMaps_to_mldev(getv(from_object, ['google_maps']), to_object),
14821497
)
14831498

1484-
if getv(from_object, ['google_search']) is not None:
1485-
setv(
1486-
to_object,
1487-
['googleSearch'],
1488-
_GoogleSearch_to_mldev(getv(from_object, ['google_search']), to_object),
1489-
)
1490-
14911499
if getv(from_object, ['google_search_retrieval']) is not None:
14921500
setv(
14931501
to_object,

google/genai/caches.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,9 @@ def _GoogleSearch_to_mldev(
432432
parent_object: Optional[dict[str, Any]] = None,
433433
) -> dict[str, Any]:
434434
to_object: dict[str, Any] = {}
435+
if getv(from_object, ['search_types']) is not None:
436+
setv(to_object, ['searchTypes'], getv(from_object, ['search_types']))
437+
435438
if getv(from_object, ['exclude_domains']) is not None:
436439
raise ValueError(
437440
'exclude_domains parameter is not supported in Gemini API.'
@@ -665,6 +668,13 @@ def _Tool_to_mldev(
665668
if getv(from_object, ['file_search']) is not None:
666669
setv(to_object, ['fileSearch'], getv(from_object, ['file_search']))
667670

671+
if getv(from_object, ['google_search']) is not None:
672+
setv(
673+
to_object,
674+
['googleSearch'],
675+
_GoogleSearch_to_mldev(getv(from_object, ['google_search']), to_object),
676+
)
677+
668678
if getv(from_object, ['code_execution']) is not None:
669679
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
670680

@@ -687,13 +697,6 @@ def _Tool_to_mldev(
687697
_GoogleMaps_to_mldev(getv(from_object, ['google_maps']), to_object),
688698
)
689699

690-
if getv(from_object, ['google_search']) is not None:
691-
setv(
692-
to_object,
693-
['googleSearch'],
694-
_GoogleSearch_to_mldev(getv(from_object, ['google_search']), to_object),
695-
)
696-
697700
if getv(from_object, ['google_search_retrieval']) is not None:
698701
setv(
699702
to_object,
@@ -728,6 +731,9 @@ def _Tool_to_vertex(
728731
if getv(from_object, ['file_search']) is not None:
729732
raise ValueError('file_search parameter is not supported in Vertex AI.')
730733

734+
if getv(from_object, ['google_search']) is not None:
735+
setv(to_object, ['googleSearch'], getv(from_object, ['google_search']))
736+
731737
if getv(from_object, ['code_execution']) is not None:
732738
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
733739

@@ -751,9 +757,6 @@ def _Tool_to_vertex(
751757
if getv(from_object, ['google_maps']) is not None:
752758
setv(to_object, ['googleMaps'], getv(from_object, ['google_maps']))
753759

754-
if getv(from_object, ['google_search']) is not None:
755-
setv(to_object, ['googleSearch'], getv(from_object, ['google_search']))
756-
757760
if getv(from_object, ['google_search_retrieval']) is not None:
758761
setv(
759762
to_object,

google/genai/models.py

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,16 @@ def _Candidate_from_mldev(
9696
if getv(from_object, ['finishReason']) is not None:
9797
setv(to_object, ['finish_reason'], getv(from_object, ['finishReason']))
9898

99-
if getv(from_object, ['avgLogprobs']) is not None:
100-
setv(to_object, ['avg_logprobs'], getv(from_object, ['avgLogprobs']))
101-
10299
if getv(from_object, ['groundingMetadata']) is not None:
103100
setv(
104101
to_object,
105102
['grounding_metadata'],
106103
getv(from_object, ['groundingMetadata']),
107104
)
108105

106+
if getv(from_object, ['avgLogprobs']) is not None:
107+
setv(to_object, ['avg_logprobs'], getv(from_object, ['avgLogprobs']))
108+
109109
if getv(from_object, ['index']) is not None:
110110
setv(to_object, ['index'], getv(from_object, ['index']))
111111

@@ -2724,6 +2724,9 @@ def _GoogleSearch_to_mldev(
27242724
root_object: Optional[Union[dict[str, Any], object]] = None,
27252725
) -> dict[str, Any]:
27262726
to_object: dict[str, Any] = {}
2727+
if getv(from_object, ['search_types']) is not None:
2728+
setv(to_object, ['searchTypes'], getv(from_object, ['search_types']))
2729+
27272730
if getv(from_object, ['exclude_domains']) is not None:
27282731
raise ValueError(
27292732
'exclude_domains parameter is not supported in Gemini API.'
@@ -2759,6 +2762,11 @@ def _ImageConfig_to_mldev(
27592762
'person_generation parameter is not supported in Gemini API.'
27602763
)
27612764

2765+
if getv(from_object, ['prominent_people']) is not None:
2766+
raise ValueError(
2767+
'prominent_people parameter is not supported in Gemini API.'
2768+
)
2769+
27622770
if getv(from_object, ['output_mime_type']) is not None:
27632771
raise ValueError(
27642772
'output_mime_type parameter is not supported in Gemini API.'
@@ -2791,6 +2799,11 @@ def _ImageConfig_to_vertex(
27912799
getv(from_object, ['person_generation']),
27922800
)
27932801

2802+
if getv(from_object, ['prominent_people']) is not None:
2803+
setv(
2804+
to_object, ['prominentPeople'], getv(from_object, ['prominent_people'])
2805+
)
2806+
27942807
if getv(from_object, ['output_mime_type']) is not None:
27952808
setv(
27962809
to_object,
@@ -3727,6 +3740,15 @@ def _Tool_to_mldev(
37273740
if getv(from_object, ['file_search']) is not None:
37283741
setv(to_object, ['fileSearch'], getv(from_object, ['file_search']))
37293742

3743+
if getv(from_object, ['google_search']) is not None:
3744+
setv(
3745+
to_object,
3746+
['googleSearch'],
3747+
_GoogleSearch_to_mldev(
3748+
getv(from_object, ['google_search']), to_object, root_object
3749+
),
3750+
)
3751+
37303752
if getv(from_object, ['code_execution']) is not None:
37313753
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
37323754

@@ -3751,15 +3773,6 @@ def _Tool_to_mldev(
37513773
),
37523774
)
37533775

3754-
if getv(from_object, ['google_search']) is not None:
3755-
setv(
3756-
to_object,
3757-
['googleSearch'],
3758-
_GoogleSearch_to_mldev(
3759-
getv(from_object, ['google_search']), to_object, root_object
3760-
),
3761-
)
3762-
37633776
if getv(from_object, ['google_search_retrieval']) is not None:
37643777
setv(
37653778
to_object,
@@ -3795,6 +3808,9 @@ def _Tool_to_vertex(
37953808
if getv(from_object, ['file_search']) is not None:
37963809
raise ValueError('file_search parameter is not supported in Vertex AI.')
37973810

3811+
if getv(from_object, ['google_search']) is not None:
3812+
setv(to_object, ['googleSearch'], getv(from_object, ['google_search']))
3813+
37983814
if getv(from_object, ['code_execution']) is not None:
37993815
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
38003816

@@ -3818,9 +3834,6 @@ def _Tool_to_vertex(
38183834
if getv(from_object, ['google_maps']) is not None:
38193835
setv(to_object, ['googleMaps'], getv(from_object, ['google_maps']))
38203836

3821-
if getv(from_object, ['google_search']) is not None:
3822-
setv(to_object, ['googleSearch'], getv(from_object, ['google_search']))
3823-
38243837
if getv(from_object, ['google_search_retrieval']) is not None:
38253838
setv(
38263839
to_object,

0 commit comments

Comments
 (0)