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
52 changes: 2 additions & 50 deletions google/genai/_live_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,26 +90,6 @@ def _Blob_to_mldev(
return to_object


def _CodeExecutionResult_to_vertex(
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, ['outcome']) is not None:
setv(to_object, ['outcome'], getv(from_object, ['outcome']))

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

if getv(from_object, ['id']) is not None:
raise ValueError(
'id parameter is only supported in Gemini Developer API mode, not in'
' Gemini Enterprise Agent Platform mode.'
)

return to_object


def _ComputerUse_to_vertex(
from_object: Union[dict[str, Any], object],
parent_object: Optional[dict[str, Any]] = None,
Expand Down Expand Up @@ -183,26 +163,6 @@ def _Content_to_vertex(
return to_object


def _ExecutableCode_to_vertex(
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, ['code']) is not None:
setv(to_object, ['code'], getv(from_object, ['code']))

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

if getv(from_object, ['id']) is not None:
raise ValueError(
'id parameter is only supported in Gemini Developer API mode, not in'
' Gemini Enterprise Agent Platform mode.'
)

return to_object


def _FileData_to_mldev(
from_object: Union[dict[str, Any], object],
parent_object: Optional[dict[str, Any]] = None,
Expand Down Expand Up @@ -1691,19 +1651,11 @@ def _Part_to_vertex(
setv(
to_object,
['codeExecutionResult'],
_CodeExecutionResult_to_vertex(
getv(from_object, ['code_execution_result']), to_object
),
getv(from_object, ['code_execution_result']),
)

if getv(from_object, ['executable_code']) is not None:
setv(
to_object,
['executableCode'],
_ExecutableCode_to_vertex(
getv(from_object, ['executable_code']), to_object
),
)
setv(to_object, ['executableCode'], getv(from_object, ['executable_code']))

if getv(from_object, ['file_data']) is not None:
setv(to_object, ['fileData'], getv(from_object, ['file_data']))
Expand Down
231 changes: 231 additions & 0 deletions google/genai/_tokens_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,113 @@ def _AuthConfig_to_mldev(
return to_object


def _AuthToken_from_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, ['name']) is not None:
setv(to_object, ['name'], getv(from_object, ['name']))

if getv(from_object, ['bidiGenerateContentSetup']) is not None:
setv(
to_object,
['bidi_generate_content_setup'],
_BidiGenerateContentSetup_from_mldev(
getv(from_object, ['bidiGenerateContentSetup']), to_object
),
)

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

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

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

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

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

return to_object


def _BidiGenerateContentSetup_from_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, ['contextWindowCompression']) is not None:
setv(
to_object,
['context_window_compression'],
getv(from_object, ['contextWindowCompression']),
)

if getv(from_object, ['generationConfig']) is not None:
setv(
to_object,
['generation_config'],
_GenerationConfig_from_mldev(
getv(from_object, ['generationConfig']), to_object
),
)

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

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

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

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

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

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

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

if getv(from_object, ['tools']) is not None:
setv(to_object, ['tools'], [item for item in getv(from_object, ['tools'])])

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 @@ -233,6 +340,130 @@ def _FunctionCall_to_mldev(
return to_object


def _GenerationConfig_from_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, ['responseJsonSchema']) is not None:
setv(
to_object,
['response_json_schema'],
t.t_json_schema(getv(from_object, ['responseJsonSchema'])),
)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

if getv(from_object, ['responseFormat']) is not None:
setv(
to_object,
['response_format'],
[item for item in getv(from_object, ['responseFormat'])],
)

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

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

return to_object


def _GoogleMaps_to_mldev(
from_object: Union[dict[str, Any], object],
parent_object: Optional[dict[str, Any]] = None,
Expand Down
52 changes: 2 additions & 50 deletions google/genai/caches.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,6 @@ def _Blob_to_mldev(
return to_object


def _CodeExecutionResult_to_vertex(
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, ['outcome']) is not None:
setv(to_object, ['outcome'], getv(from_object, ['outcome']))

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

if getv(from_object, ['id']) is not None:
raise ValueError(
'id parameter is only supported in Gemini Developer API mode, not in'
' Gemini Enterprise Agent Platform mode.'
)

return to_object


def _ComputerUse_to_vertex(
from_object: Union[dict[str, Any], object],
parent_object: Optional[dict[str, Any]] = None,
Expand Down Expand Up @@ -413,26 +393,6 @@ def _DeleteCachedContentResponse_from_vertex(
return to_object


def _ExecutableCode_to_vertex(
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, ['code']) is not None:
setv(to_object, ['code'], getv(from_object, ['code']))

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

if getv(from_object, ['id']) is not None:
raise ValueError(
'id parameter is only supported in Gemini Developer API mode, not in'
' Gemini Enterprise Agent Platform mode.'
)

return to_object


def _FileData_to_mldev(
from_object: Union[dict[str, Any], object],
parent_object: Optional[dict[str, Any]] = None,
Expand Down Expand Up @@ -819,19 +779,11 @@ def _Part_to_vertex(
setv(
to_object,
['codeExecutionResult'],
_CodeExecutionResult_to_vertex(
getv(from_object, ['code_execution_result']), to_object
),
getv(from_object, ['code_execution_result']),
)

if getv(from_object, ['executable_code']) is not None:
setv(
to_object,
['executableCode'],
_ExecutableCode_to_vertex(
getv(from_object, ['executable_code']), to_object
),
)
setv(to_object, ['executableCode'], getv(from_object, ['executable_code']))

if getv(from_object, ['file_data']) is not None:
setv(to_object, ['fileData'], getv(from_object, ['file_data']))
Expand Down
Loading
Loading