Skip to content

feat: Introduce tool retrieval config #688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 36 additions & 12 deletions google/genai/caches.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ def _Part_to_mldev(
if getv(from_object, ['video_metadata']) is not None:
raise ValueError('video_metadata parameter is not supported in Gemini API.')

if getv(from_object, ['thought']) is not None:
setv(to_object, ['thought'], getv(from_object, ['thought']))

if getv(from_object, ['code_execution_result']) is not None:
setv(
to_object,
Expand Down Expand Up @@ -71,6 +68,9 @@ def _Part_to_mldev(
if getv(from_object, ['text']) is not None:
setv(to_object, ['text'], getv(from_object, ['text']))

if getv(from_object, ['thought']) is not None:
setv(to_object, ['thought'], getv(from_object, ['thought']))

return to_object


Expand Down Expand Up @@ -261,9 +261,6 @@ def _Tool_to_mldev(
],
)

if getv(from_object, ['retrieval']) is not None:
raise ValueError('retrieval parameter is not supported in Gemini API.')

if getv(from_object, ['google_search']) is not None:
setv(
to_object,
Expand All @@ -273,6 +270,9 @@ def _Tool_to_mldev(
),
)

if getv(from_object, ['retrieval']) is not None:
raise ValueError('retrieval parameter is not supported in Gemini API.')

if getv(from_object, ['google_search_retrieval']) is not None:
setv(
to_object,
Expand All @@ -287,6 +287,13 @@ def _Tool_to_mldev(
if getv(from_object, ['code_execution']) is not None:
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))

if getv(from_object, ['enterprise_web_search']) is not None:
setv(
to_object,
['enterpriseWebSearch'],
getv(from_object, ['enterprise_web_search']),
)

return to_object


Expand Down Expand Up @@ -326,6 +333,11 @@ def _ToolConfig_to_mldev(
),
)

if getv(from_object, ['retrieval_config']) is not None:
setv(
to_object, ['retrievalConfig'], getv(from_object, ['retrieval_config'])
)

return to_object


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

if getv(from_object, ['thought']) is not None:
setv(to_object, ['thought'], getv(from_object, ['thought']))

if getv(from_object, ['code_execution_result']) is not None:
setv(
to_object,
Expand Down Expand Up @@ -575,6 +584,9 @@ def _Part_to_vertex(
if getv(from_object, ['text']) is not None:
setv(to_object, ['text'], getv(from_object, ['text']))

if getv(from_object, ['thought']) is not None:
setv(to_object, ['thought'], getv(from_object, ['thought']))

return to_object


Expand Down Expand Up @@ -771,9 +783,6 @@ def _Tool_to_vertex(
],
)

if getv(from_object, ['retrieval']) is not None:
setv(to_object, ['retrieval'], getv(from_object, ['retrieval']))

if getv(from_object, ['google_search']) is not None:
setv(
to_object,
Expand All @@ -783,6 +792,9 @@ def _Tool_to_vertex(
),
)

if getv(from_object, ['retrieval']) is not None:
setv(to_object, ['retrieval'], getv(from_object, ['retrieval']))

if getv(from_object, ['google_search_retrieval']) is not None:
setv(
to_object,
Expand All @@ -797,6 +809,13 @@ def _Tool_to_vertex(
if getv(from_object, ['code_execution']) is not None:
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))

if getv(from_object, ['enterprise_web_search']) is not None:
setv(
to_object,
['enterpriseWebSearch'],
getv(from_object, ['enterprise_web_search']),
)

return to_object


Expand Down Expand Up @@ -836,6 +855,11 @@ def _ToolConfig_to_vertex(
),
)

if getv(from_object, ['retrieval_config']) is not None:
setv(
to_object, ['retrievalConfig'], getv(from_object, ['retrieval_config'])
)

return to_object


Expand Down
132 changes: 42 additions & 90 deletions google/genai/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ def _Part_to_mldev(
if getv(from_object, ['video_metadata']) is not None:
raise ValueError('video_metadata parameter is not supported in Gemini API.')

if getv(from_object, ['thought']) is not None:
setv(to_object, ['thought'], getv(from_object, ['thought']))

if getv(from_object, ['code_execution_result']) is not None:
setv(
to_object,
Expand Down Expand Up @@ -72,6 +69,9 @@ def _Part_to_mldev(
if getv(from_object, ['text']) is not None:
setv(to_object, ['text'], getv(from_object, ['text']))

if getv(from_object, ['thought']) is not None:
setv(to_object, ['thought'], getv(from_object, ['thought']))

return to_object


Expand Down Expand Up @@ -280,9 +280,6 @@ def _Tool_to_mldev(
],
)

if getv(from_object, ['retrieval']) is not None:
raise ValueError('retrieval parameter is not supported in Gemini API.')

if getv(from_object, ['google_search']) is not None:
setv(
to_object,
Expand All @@ -292,6 +289,9 @@ def _Tool_to_mldev(
),
)

if getv(from_object, ['retrieval']) is not None:
raise ValueError('retrieval parameter is not supported in Gemini API.')

if getv(from_object, ['google_search_retrieval']) is not None:
setv(
to_object,
Expand All @@ -306,6 +306,13 @@ def _Tool_to_mldev(
if getv(from_object, ['code_execution']) is not None:
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))

if getv(from_object, ['enterprise_web_search']) is not None:
setv(
to_object,
['enterpriseWebSearch'],
getv(from_object, ['enterprise_web_search']),
)

return to_object


Expand Down Expand Up @@ -345,34 +352,9 @@ def _ToolConfig_to_mldev(
),
)

return to_object


def _PrebuiltVoiceConfig_to_mldev(
api_client: BaseApiClient,
from_object: Union[dict, object],
parent_object: Optional[dict] = None,
) -> dict:
to_object: dict[str, Any] = {}
if getv(from_object, ['voice_name']) is not None:
setv(to_object, ['voiceName'], getv(from_object, ['voice_name']))

return to_object


def _VoiceConfig_to_mldev(
api_client: BaseApiClient,
from_object: Union[dict, object],
parent_object: Optional[dict] = None,
) -> dict:
to_object: dict[str, Any] = {}
if getv(from_object, ['prebuilt_voice_config']) is not None:
if getv(from_object, ['retrieval_config']) is not None:
setv(
to_object,
['prebuiltVoiceConfig'],
_PrebuiltVoiceConfig_to_mldev(
api_client, getv(from_object, ['prebuilt_voice_config']), to_object
),
to_object, ['retrievalConfig'], getv(from_object, ['retrieval_config'])
)

return to_object
Expand All @@ -384,18 +366,12 @@ def _SpeechConfig_to_mldev(
parent_object: Optional[dict] = None,
) -> dict:
to_object: dict[str, Any] = {}
if getv(from_object, ['voice_config']) is not None:
setv(
to_object,
['voiceConfig'],
_VoiceConfig_to_mldev(
api_client, getv(from_object, ['voice_config']), to_object
),
)

if getv(from_object, ['language_code']) is not None:
setv(to_object, ['languageCode'], getv(from_object, ['language_code']))

if getv(from_object, ['voice_config']) is not None:
setv(to_object, ['voiceConfig'], getv(from_object, ['voice_config']))

return to_object


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

if getv(from_object, ['thought']) is not None:
setv(to_object, ['thought'], getv(from_object, ['thought']))

if getv(from_object, ['code_execution_result']) is not None:
setv(
to_object,
Expand Down Expand Up @@ -1169,6 +1142,9 @@ def _Part_to_vertex(
if getv(from_object, ['text']) is not None:
setv(to_object, ['text'], getv(from_object, ['text']))

if getv(from_object, ['thought']) is not None:
setv(to_object, ['thought'], getv(from_object, ['thought']))

return to_object


Expand Down Expand Up @@ -1383,9 +1359,6 @@ def _Tool_to_vertex(
],
)

if getv(from_object, ['retrieval']) is not None:
setv(to_object, ['retrieval'], getv(from_object, ['retrieval']))

if getv(from_object, ['google_search']) is not None:
setv(
to_object,
Expand All @@ -1395,6 +1368,9 @@ def _Tool_to_vertex(
),
)

if getv(from_object, ['retrieval']) is not None:
setv(to_object, ['retrieval'], getv(from_object, ['retrieval']))

if getv(from_object, ['google_search_retrieval']) is not None:
setv(
to_object,
Expand All @@ -1409,6 +1385,13 @@ def _Tool_to_vertex(
if getv(from_object, ['code_execution']) is not None:
setv(to_object, ['codeExecution'], getv(from_object, ['code_execution']))

if getv(from_object, ['enterprise_web_search']) is not None:
setv(
to_object,
['enterpriseWebSearch'],
getv(from_object, ['enterprise_web_search']),
)

return to_object


Expand Down Expand Up @@ -1448,34 +1431,9 @@ def _ToolConfig_to_vertex(
),
)

return to_object


def _PrebuiltVoiceConfig_to_vertex(
api_client: BaseApiClient,
from_object: Union[dict, object],
parent_object: Optional[dict] = None,
) -> dict:
to_object: dict[str, Any] = {}
if getv(from_object, ['voice_name']) is not None:
setv(to_object, ['voiceName'], getv(from_object, ['voice_name']))

return to_object


def _VoiceConfig_to_vertex(
api_client: BaseApiClient,
from_object: Union[dict, object],
parent_object: Optional[dict] = None,
) -> dict:
to_object: dict[str, Any] = {}
if getv(from_object, ['prebuilt_voice_config']) is not None:
if getv(from_object, ['retrieval_config']) is not None:
setv(
to_object,
['prebuiltVoiceConfig'],
_PrebuiltVoiceConfig_to_vertex(
api_client, getv(from_object, ['prebuilt_voice_config']), to_object
),
to_object, ['retrievalConfig'], getv(from_object, ['retrieval_config'])
)

return to_object
Expand All @@ -1487,18 +1445,12 @@ def _SpeechConfig_to_vertex(
parent_object: Optional[dict] = None,
) -> dict:
to_object: dict[str, Any] = {}
if getv(from_object, ['voice_config']) is not None:
setv(
to_object,
['voiceConfig'],
_VoiceConfig_to_vertex(
api_client, getv(from_object, ['voice_config']), to_object
),
)

if getv(from_object, ['language_code']) is not None:
setv(to_object, ['languageCode'], getv(from_object, ['language_code']))

if getv(from_object, ['voice_config']) is not None:
setv(to_object, ['voiceConfig'], getv(from_object, ['voice_config']))

return to_object


Expand Down Expand Up @@ -2682,9 +2634,6 @@ def _Part_from_mldev(
) -> dict:
to_object: dict[str, Any] = {}

if getv(from_object, ['thought']) is not None:
setv(to_object, ['thought'], getv(from_object, ['thought']))

if getv(from_object, ['codeExecutionResult']) is not None:
setv(
to_object,
Expand Down Expand Up @@ -2714,6 +2663,9 @@ def _Part_from_mldev(
if getv(from_object, ['text']) is not None:
setv(to_object, ['text'], getv(from_object, ['text']))

if getv(from_object, ['thought']) is not None:
setv(to_object, ['thought'], getv(from_object, ['thought']))

return to_object


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

if getv(from_object, ['thought']) is not None:
setv(to_object, ['thought'], getv(from_object, ['thought']))

if getv(from_object, ['codeExecutionResult']) is not None:
setv(
to_object,
Expand Down Expand Up @@ -3282,6 +3231,9 @@ def _Part_from_vertex(
if getv(from_object, ['text']) is not None:
setv(to_object, ['text'], getv(from_object, ['text']))

if getv(from_object, ['thought']) is not None:
setv(to_object, ['thought'], getv(from_object, ['thought']))

return to_object


Expand Down
Loading