Skip to content
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
281 changes: 245 additions & 36 deletions google/genai/_live_converters.py

Large diffs are not rendered by default.

153 changes: 140 additions & 13 deletions google/genai/_tokens_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,40 @@
from ._common import set_value_by_path as setv


def _AuthConfig_to_mldev(
from_object: Union[dict[str, Any], object],
parent_object: Optional[dict[str, Any]] = None,
) -> dict[str, Any]:
to_object: dict[str, Any] = {}
if getv(from_object, ['api_key']) is not None:
setv(to_object, ['apiKey'], getv(from_object, ['api_key']))

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

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

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

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

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

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

return to_object


def _Blob_to_mldev(
from_object: Union[dict[str, Any], object],
parent_object: Optional[dict[str, Any]] = None,
Expand Down Expand Up @@ -177,7 +211,11 @@ def _GoogleMaps_to_mldev(
) -> dict[str, Any]:
to_object: dict[str, Any] = {}
if getv(from_object, ['auth_config']) is not None:
raise ValueError('auth_config parameter is not supported in Gemini API.')
setv(
to_object,
['authConfig'],
_AuthConfig_to_mldev(getv(from_object, ['auth_config']), to_object),
)

if getv(from_object, ['enable_widget']) is not None:
setv(to_object, ['enableWidget'], getv(from_object, ['enable_widget']))
Expand All @@ -190,14 +228,14 @@ def _GoogleSearch_to_mldev(
parent_object: Optional[dict[str, Any]] = None,
) -> dict[str, Any]:
to_object: dict[str, Any] = {}
if getv(from_object, ['exclude_domains']) is not None:
if getv(from_object, ['blocking_confidence']) is not None:
raise ValueError(
'exclude_domains parameter is not supported in Gemini API.'
'blocking_confidence parameter is not supported in Gemini API.'
)

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

if getv(from_object, ['time_range_filter']) is not None:
Expand Down Expand Up @@ -275,7 +313,10 @@ def _LiveConnectConfig_to_mldev(
setv(
parent_object,
['setup', 'generationConfig', 'speechConfig'],
t.t_live_speech_config(getv(from_object, ['speech_config'])),
_SpeechConfig_to_mldev(
t.t_live_speech_config(getv(from_object, ['speech_config'])),
to_object,
),
)

if getv(from_object, ['thinking_config']) is not None:
Expand Down Expand Up @@ -383,6 +424,24 @@ def _LiveConnectConstraints_to_mldev(
return to_object


def _MultiSpeakerVoiceConfig_to_mldev(
from_object: Union[dict[str, Any], object],
parent_object: Optional[dict[str, Any]] = None,
) -> dict[str, Any]:
to_object: dict[str, Any] = {}
if getv(from_object, ['speaker_voice_configs']) is not None:
setv(
to_object,
['speakerVoiceConfigs'],
[
_SpeakerVoiceConfig_to_mldev(item, to_object)
for item in getv(from_object, ['speaker_voice_configs'])
],
)

return to_object


def _Part_to_mldev(
from_object: Union[dict[str, Any], object],
parent_object: Optional[dict[str, Any]] = None,
Expand Down Expand Up @@ -447,6 +506,9 @@ def _Part_to_mldev(
if getv(from_object, ['video_metadata']) is not None:
setv(to_object, ['videoMetadata'], getv(from_object, ['video_metadata']))

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

return to_object


Expand All @@ -464,6 +526,51 @@ def _SessionResumptionConfig_to_mldev(
return to_object


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

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

return to_object


def _SpeechConfig_to_mldev(
from_object: Union[dict[str, Any], object],
parent_object: Optional[dict[str, Any]] = None,
) -> dict[str, Any]:
to_object: dict[str, Any] = {}
if getv(from_object, ['language_code']) is not None:
setv(to_object, ['languageCode'], getv(from_object, ['language_code']))

if getv(from_object, ['multi_speaker_voice_config']) is not None:
setv(
to_object,
['multiSpeakerVoiceConfig'],
_MultiSpeakerVoiceConfig_to_mldev(
getv(from_object, ['multi_speaker_voice_config']), to_object
),
)

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

return to_object


def _Tool_to_mldev(
from_object: Union[dict[str, Any], object],
parent_object: Optional[dict[str, Any]] = None,
Expand Down Expand Up @@ -492,6 +599,13 @@ def _Tool_to_mldev(
if getv(from_object, ['file_search']) is not None:
setv(to_object, ['fileSearch'], getv(from_object, ['file_search']))

if getv(from_object, ['google_maps']) is not None:
setv(
to_object,
['googleMaps'],
_GoogleMaps_to_mldev(getv(from_object, ['google_maps']), to_object),
)

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

Expand All @@ -500,13 +614,6 @@ def _Tool_to_mldev(
'enterprise_web_search parameter is not supported in Gemini API.'
)

if getv(from_object, ['google_maps']) is not None:
setv(
to_object,
['googleMaps'],
_GoogleMaps_to_mldev(getv(from_object, ['google_maps']), to_object),
)

if getv(from_object, ['google_search']) is not None:
setv(
to_object,
Expand All @@ -518,3 +625,23 @@ def _Tool_to_mldev(
setv(to_object, ['urlContext'], getv(from_object, ['url_context']))

return to_object


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

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

return to_object
Loading