Skip to content

Commit a37fcd5

Browse files
amirhcopybara-github
authored andcommitted
feat: Introduce tool retrieval config
feat: Add displayName to FileData feat: Add responseModalities and speechconfig to GenerationConfig PiperOrigin-RevId: 747683395
1 parent 0af470b commit a37fcd5

File tree

4 files changed

+257
-159
lines changed

4 files changed

+257
-159
lines changed

google/genai/caches.py

+36-12
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ def _Part_to_mldev(
3939
if getv(from_object, ['video_metadata']) is not None:
4040
raise ValueError('video_metadata parameter is not supported in Gemini API.')
4141

42-
if getv(from_object, ['thought']) is not None:
43-
setv(to_object, ['thought'], getv(from_object, ['thought']))
44-
4542
if getv(from_object, ['code_execution_result']) is not None:
4643
setv(
4744
to_object,
@@ -71,6 +68,9 @@ def _Part_to_mldev(
7168
if getv(from_object, ['text']) is not None:
7269
setv(to_object, ['text'], getv(from_object, ['text']))
7370

71+
if getv(from_object, ['thought']) is not None:
72+
setv(to_object, ['thought'], getv(from_object, ['thought']))
73+
7474
return to_object
7575

7676

@@ -261,9 +261,6 @@ def _Tool_to_mldev(
261261
],
262262
)
263263

264-
if getv(from_object, ['retrieval']) is not None:
265-
raise ValueError('retrieval parameter is not supported in Gemini API.')
266-
267264
if getv(from_object, ['google_search']) is not None:
268265
setv(
269266
to_object,
@@ -273,6 +270,9 @@ def _Tool_to_mldev(
273270
),
274271
)
275272

273+
if getv(from_object, ['retrieval']) is not None:
274+
raise ValueError('retrieval parameter is not supported in Gemini API.')
275+
276276
if getv(from_object, ['google_search_retrieval']) is not None:
277277
setv(
278278
to_object,
@@ -287,6 +287,13 @@ def _Tool_to_mldev(
287287
if getv(from_object, ['code_execution']) is not None:
288288
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
289289

290+
if getv(from_object, ['enterprise_web_search']) is not None:
291+
setv(
292+
to_object,
293+
['enterpriseWebSearch'],
294+
getv(from_object, ['enterprise_web_search']),
295+
)
296+
290297
return to_object
291298

292299

@@ -326,6 +333,11 @@ def _ToolConfig_to_mldev(
326333
),
327334
)
328335

336+
if getv(from_object, ['retrieval_config']) is not None:
337+
setv(
338+
to_object, ['retrievalConfig'], getv(from_object, ['retrieval_config'])
339+
)
340+
329341
return to_object
330342

331343

@@ -543,9 +555,6 @@ def _Part_to_vertex(
543555
if getv(from_object, ['video_metadata']) is not None:
544556
setv(to_object, ['videoMetadata'], getv(from_object, ['video_metadata']))
545557

546-
if getv(from_object, ['thought']) is not None:
547-
setv(to_object, ['thought'], getv(from_object, ['thought']))
548-
549558
if getv(from_object, ['code_execution_result']) is not None:
550559
setv(
551560
to_object,
@@ -575,6 +584,9 @@ def _Part_to_vertex(
575584
if getv(from_object, ['text']) is not None:
576585
setv(to_object, ['text'], getv(from_object, ['text']))
577586

587+
if getv(from_object, ['thought']) is not None:
588+
setv(to_object, ['thought'], getv(from_object, ['thought']))
589+
578590
return to_object
579591

580592

@@ -771,9 +783,6 @@ def _Tool_to_vertex(
771783
],
772784
)
773785

774-
if getv(from_object, ['retrieval']) is not None:
775-
setv(to_object, ['retrieval'], getv(from_object, ['retrieval']))
776-
777786
if getv(from_object, ['google_search']) is not None:
778787
setv(
779788
to_object,
@@ -783,6 +792,9 @@ def _Tool_to_vertex(
783792
),
784793
)
785794

795+
if getv(from_object, ['retrieval']) is not None:
796+
setv(to_object, ['retrieval'], getv(from_object, ['retrieval']))
797+
786798
if getv(from_object, ['google_search_retrieval']) is not None:
787799
setv(
788800
to_object,
@@ -797,6 +809,13 @@ def _Tool_to_vertex(
797809
if getv(from_object, ['code_execution']) is not None:
798810
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
799811

812+
if getv(from_object, ['enterprise_web_search']) is not None:
813+
setv(
814+
to_object,
815+
['enterpriseWebSearch'],
816+
getv(from_object, ['enterprise_web_search']),
817+
)
818+
800819
return to_object
801820

802821

@@ -836,6 +855,11 @@ def _ToolConfig_to_vertex(
836855
),
837856
)
838857

858+
if getv(from_object, ['retrieval_config']) is not None:
859+
setv(
860+
to_object, ['retrievalConfig'], getv(from_object, ['retrieval_config'])
861+
)
862+
839863
return to_object
840864

841865

google/genai/models.py

+42-90
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ def _Part_to_mldev(
4040
if getv(from_object, ['video_metadata']) is not None:
4141
raise ValueError('video_metadata parameter is not supported in Gemini API.')
4242

43-
if getv(from_object, ['thought']) is not None:
44-
setv(to_object, ['thought'], getv(from_object, ['thought']))
45-
4643
if getv(from_object, ['code_execution_result']) is not None:
4744
setv(
4845
to_object,
@@ -72,6 +69,9 @@ def _Part_to_mldev(
7269
if getv(from_object, ['text']) is not None:
7370
setv(to_object, ['text'], getv(from_object, ['text']))
7471

72+
if getv(from_object, ['thought']) is not None:
73+
setv(to_object, ['thought'], getv(from_object, ['thought']))
74+
7575
return to_object
7676

7777

@@ -280,9 +280,6 @@ def _Tool_to_mldev(
280280
],
281281
)
282282

283-
if getv(from_object, ['retrieval']) is not None:
284-
raise ValueError('retrieval parameter is not supported in Gemini API.')
285-
286283
if getv(from_object, ['google_search']) is not None:
287284
setv(
288285
to_object,
@@ -292,6 +289,9 @@ def _Tool_to_mldev(
292289
),
293290
)
294291

292+
if getv(from_object, ['retrieval']) is not None:
293+
raise ValueError('retrieval parameter is not supported in Gemini API.')
294+
295295
if getv(from_object, ['google_search_retrieval']) is not None:
296296
setv(
297297
to_object,
@@ -306,6 +306,13 @@ def _Tool_to_mldev(
306306
if getv(from_object, ['code_execution']) is not None:
307307
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
308308

309+
if getv(from_object, ['enterprise_web_search']) is not None:
310+
setv(
311+
to_object,
312+
['enterpriseWebSearch'],
313+
getv(from_object, ['enterprise_web_search']),
314+
)
315+
309316
return to_object
310317

311318

@@ -345,34 +352,9 @@ def _ToolConfig_to_mldev(
345352
),
346353
)
347354

348-
return to_object
349-
350-
351-
def _PrebuiltVoiceConfig_to_mldev(
352-
api_client: BaseApiClient,
353-
from_object: Union[dict, object],
354-
parent_object: Optional[dict] = None,
355-
) -> dict:
356-
to_object: dict[str, Any] = {}
357-
if getv(from_object, ['voice_name']) is not None:
358-
setv(to_object, ['voiceName'], getv(from_object, ['voice_name']))
359-
360-
return to_object
361-
362-
363-
def _VoiceConfig_to_mldev(
364-
api_client: BaseApiClient,
365-
from_object: Union[dict, object],
366-
parent_object: Optional[dict] = None,
367-
) -> dict:
368-
to_object: dict[str, Any] = {}
369-
if getv(from_object, ['prebuilt_voice_config']) is not None:
355+
if getv(from_object, ['retrieval_config']) is not None:
370356
setv(
371-
to_object,
372-
['prebuiltVoiceConfig'],
373-
_PrebuiltVoiceConfig_to_mldev(
374-
api_client, getv(from_object, ['prebuilt_voice_config']), to_object
375-
),
357+
to_object, ['retrievalConfig'], getv(from_object, ['retrieval_config'])
376358
)
377359

378360
return to_object
@@ -384,18 +366,12 @@ def _SpeechConfig_to_mldev(
384366
parent_object: Optional[dict] = None,
385367
) -> dict:
386368
to_object: dict[str, Any] = {}
387-
if getv(from_object, ['voice_config']) is not None:
388-
setv(
389-
to_object,
390-
['voiceConfig'],
391-
_VoiceConfig_to_mldev(
392-
api_client, getv(from_object, ['voice_config']), to_object
393-
),
394-
)
395-
396369
if getv(from_object, ['language_code']) is not None:
397370
setv(to_object, ['languageCode'], getv(from_object, ['language_code']))
398371

372+
if getv(from_object, ['voice_config']) is not None:
373+
setv(to_object, ['voiceConfig'], getv(from_object, ['voice_config']))
374+
399375
return to_object
400376

401377

@@ -1137,9 +1113,6 @@ def _Part_to_vertex(
11371113
if getv(from_object, ['video_metadata']) is not None:
11381114
setv(to_object, ['videoMetadata'], getv(from_object, ['video_metadata']))
11391115

1140-
if getv(from_object, ['thought']) is not None:
1141-
setv(to_object, ['thought'], getv(from_object, ['thought']))
1142-
11431116
if getv(from_object, ['code_execution_result']) is not None:
11441117
setv(
11451118
to_object,
@@ -1169,6 +1142,9 @@ def _Part_to_vertex(
11691142
if getv(from_object, ['text']) is not None:
11701143
setv(to_object, ['text'], getv(from_object, ['text']))
11711144

1145+
if getv(from_object, ['thought']) is not None:
1146+
setv(to_object, ['thought'], getv(from_object, ['thought']))
1147+
11721148
return to_object
11731149

11741150

@@ -1383,9 +1359,6 @@ def _Tool_to_vertex(
13831359
],
13841360
)
13851361

1386-
if getv(from_object, ['retrieval']) is not None:
1387-
setv(to_object, ['retrieval'], getv(from_object, ['retrieval']))
1388-
13891362
if getv(from_object, ['google_search']) is not None:
13901363
setv(
13911364
to_object,
@@ -1395,6 +1368,9 @@ def _Tool_to_vertex(
13951368
),
13961369
)
13971370

1371+
if getv(from_object, ['retrieval']) is not None:
1372+
setv(to_object, ['retrieval'], getv(from_object, ['retrieval']))
1373+
13981374
if getv(from_object, ['google_search_retrieval']) is not None:
13991375
setv(
14001376
to_object,
@@ -1409,6 +1385,13 @@ def _Tool_to_vertex(
14091385
if getv(from_object, ['code_execution']) is not None:
14101386
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))
14111387

1388+
if getv(from_object, ['enterprise_web_search']) is not None:
1389+
setv(
1390+
to_object,
1391+
['enterpriseWebSearch'],
1392+
getv(from_object, ['enterprise_web_search']),
1393+
)
1394+
14121395
return to_object
14131396

14141397

@@ -1448,34 +1431,9 @@ def _ToolConfig_to_vertex(
14481431
),
14491432
)
14501433

1451-
return to_object
1452-
1453-
1454-
def _PrebuiltVoiceConfig_to_vertex(
1455-
api_client: BaseApiClient,
1456-
from_object: Union[dict, object],
1457-
parent_object: Optional[dict] = None,
1458-
) -> dict:
1459-
to_object: dict[str, Any] = {}
1460-
if getv(from_object, ['voice_name']) is not None:
1461-
setv(to_object, ['voiceName'], getv(from_object, ['voice_name']))
1462-
1463-
return to_object
1464-
1465-
1466-
def _VoiceConfig_to_vertex(
1467-
api_client: BaseApiClient,
1468-
from_object: Union[dict, object],
1469-
parent_object: Optional[dict] = None,
1470-
) -> dict:
1471-
to_object: dict[str, Any] = {}
1472-
if getv(from_object, ['prebuilt_voice_config']) is not None:
1434+
if getv(from_object, ['retrieval_config']) is not None:
14731435
setv(
1474-
to_object,
1475-
['prebuiltVoiceConfig'],
1476-
_PrebuiltVoiceConfig_to_vertex(
1477-
api_client, getv(from_object, ['prebuilt_voice_config']), to_object
1478-
),
1436+
to_object, ['retrievalConfig'], getv(from_object, ['retrieval_config'])
14791437
)
14801438

14811439
return to_object
@@ -1487,18 +1445,12 @@ def _SpeechConfig_to_vertex(
14871445
parent_object: Optional[dict] = None,
14881446
) -> dict:
14891447
to_object: dict[str, Any] = {}
1490-
if getv(from_object, ['voice_config']) is not None:
1491-
setv(
1492-
to_object,
1493-
['voiceConfig'],
1494-
_VoiceConfig_to_vertex(
1495-
api_client, getv(from_object, ['voice_config']), to_object
1496-
),
1497-
)
1498-
14991448
if getv(from_object, ['language_code']) is not None:
15001449
setv(to_object, ['languageCode'], getv(from_object, ['language_code']))
15011450

1451+
if getv(from_object, ['voice_config']) is not None:
1452+
setv(to_object, ['voiceConfig'], getv(from_object, ['voice_config']))
1453+
15021454
return to_object
15031455

15041456

@@ -2682,9 +2634,6 @@ def _Part_from_mldev(
26822634
) -> dict:
26832635
to_object: dict[str, Any] = {}
26842636

2685-
if getv(from_object, ['thought']) is not None:
2686-
setv(to_object, ['thought'], getv(from_object, ['thought']))
2687-
26882637
if getv(from_object, ['codeExecutionResult']) is not None:
26892638
setv(
26902639
to_object,
@@ -2714,6 +2663,9 @@ def _Part_from_mldev(
27142663
if getv(from_object, ['text']) is not None:
27152664
setv(to_object, ['text'], getv(from_object, ['text']))
27162665

2666+
if getv(from_object, ['thought']) is not None:
2667+
setv(to_object, ['thought'], getv(from_object, ['thought']))
2668+
27172669
return to_object
27182670

27192671

@@ -3250,9 +3202,6 @@ def _Part_from_vertex(
32503202
if getv(from_object, ['videoMetadata']) is not None:
32513203
setv(to_object, ['video_metadata'], getv(from_object, ['videoMetadata']))
32523204

3253-
if getv(from_object, ['thought']) is not None:
3254-
setv(to_object, ['thought'], getv(from_object, ['thought']))
3255-
32563205
if getv(from_object, ['codeExecutionResult']) is not None:
32573206
setv(
32583207
to_object,
@@ -3282,6 +3231,9 @@ def _Part_from_vertex(
32823231
if getv(from_object, ['text']) is not None:
32833232
setv(to_object, ['text'], getv(from_object, ['text']))
32843233

3234+
if getv(from_object, ['thought']) is not None:
3235+
setv(to_object, ['thought'], getv(from_object, ['thought']))
3236+
32853237
return to_object
32863238

32873239

0 commit comments

Comments
 (0)