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
80 changes: 65 additions & 15 deletions google/genai/_live_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 @@ -257,7 +291,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 @@ -273,14 +311,14 @@ def _GoogleSearch_to_mldev(
if getv(from_object, ['search_types']) is not None:
setv(to_object, ['searchTypes'], getv(from_object, ['search_types']))

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 @@ -1368,6 +1406,13 @@ def _Tool_to_mldev(
_GoogleSearch_to_mldev(getv(from_object, ['google_search']), to_object),
)

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 @@ -1383,20 +1428,18 @@ def _Tool_to_mldev(
[item for item in getv(from_object, ['function_declarations'])],
)

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_retrieval']) is not None:
setv(
to_object,
['googleSearchRetrieval'],
getv(from_object, ['google_search_retrieval']),
)

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

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

Expand Down Expand Up @@ -1427,6 +1470,9 @@ def _Tool_to_vertex(
if getv(from_object, ['google_search']) is not None:
setv(to_object, ['googleSearch'], getv(from_object, ['google_search']))

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

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

Expand All @@ -1447,16 +1493,20 @@ def _Tool_to_vertex(
],
)

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

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

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

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

Expand Down
67 changes: 55 additions & 12 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 @@ -193,14 +231,14 @@ def _GoogleSearch_to_mldev(
if getv(from_object, ['search_types']) is not None:
setv(to_object, ['searchTypes'], getv(from_object, ['search_types']))

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 @@ -493,6 +531,13 @@ def _Tool_to_mldev(
_GoogleSearch_to_mldev(getv(from_object, ['google_search']), to_object),
)

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 @@ -508,20 +553,18 @@ def _Tool_to_mldev(
[item for item in getv(from_object, ['function_declarations'])],
)

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_retrieval']) is not None:
setv(
to_object,
['googleSearchRetrieval'],
getv(from_object, ['google_search_retrieval']),
)

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

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

Expand Down
72 changes: 60 additions & 12 deletions google/genai/batches.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,40 @@
logger = logging.getLogger('google_genai.batches')


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 _BatchJobDestination_from_mldev(
from_object: Union[dict[str, Any], object],
parent_object: Optional[dict[str, Any]] = None,
Expand Down Expand Up @@ -1094,7 +1128,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 @@ -1110,14 +1148,14 @@ def _GoogleSearch_to_mldev(
if getv(from_object, ['search_types']) is not None:
setv(to_object, ['searchTypes'], getv(from_object, ['search_types']))

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 @@ -1159,6 +1197,11 @@ def _ImageConfig_to_mldev(
'output_compression_quality parameter is not supported in Gemini API.'
)

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

return to_object


Expand Down Expand Up @@ -1474,6 +1517,13 @@ def _Tool_to_mldev(
_GoogleSearch_to_mldev(getv(from_object, ['google_search']), to_object),
)

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 @@ -1489,20 +1539,18 @@ def _Tool_to_mldev(
[item for item in getv(from_object, ['function_declarations'])],
)

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_retrieval']) is not None:
setv(
to_object,
['googleSearchRetrieval'],
getv(from_object, ['google_search_retrieval']),
)

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

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

Expand Down
Loading