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
137 changes: 128 additions & 9 deletions google/genai/_live_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,27 @@ def _Content_to_mldev(
return to_object


def _Content_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, ['parts']) is not None:
setv(
to_object,
['parts'],
[
_Part_to_vertex(item, to_object)
for item in getv(from_object, ['parts'])
],
)

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

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 @@ -361,6 +382,27 @@ def _LiveClientContent_to_mldev(
return to_object


def _LiveClientContent_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, ['turns']) is not None:
setv(
to_object,
['turns'],
[
_Content_to_vertex(item, to_object)
for item in getv(from_object, ['turns'])
],
)

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

return to_object


def _LiveClientMessage_to_mldev(
api_client: BaseApiClient,
from_object: Union[dict[str, Any], object],
Expand Down Expand Up @@ -416,7 +458,13 @@ def _LiveClientMessage_to_vertex(
)

if getv(from_object, ['client_content']) is not None:
setv(to_object, ['clientContent'], getv(from_object, ['client_content']))
setv(
to_object,
['clientContent'],
_LiveClientContent_to_vertex(
getv(from_object, ['client_content']), to_object
),
)

if getv(from_object, ['realtime_input']) is not None:
setv(
Expand Down Expand Up @@ -617,7 +665,9 @@ def _LiveClientSetup_to_vertex(
setv(
to_object,
['systemInstruction'],
t.t_content(getv(from_object, ['system_instruction'])),
_Content_to_vertex(
t.t_content(getv(from_object, ['system_instruction'])), to_object
),
)

if getv(from_object, ['tools']) is not None:
Expand Down Expand Up @@ -930,7 +980,9 @@ def _LiveConnectConfig_to_vertex(
setv(
parent_object,
['setup', 'systemInstruction'],
t.t_content(getv(from_object, ['system_instruction'])),
_Content_to_vertex(
t.t_content(getv(from_object, ['system_instruction'])), to_object
),
)

if getv(from_object, ['tools']) is not None:
Expand Down Expand Up @@ -1344,10 +1396,8 @@ def _Part_to_mldev(
parent_object: Optional[dict[str, Any]] = None,
) -> dict[str, Any]:
to_object: dict[str, Any] = {}
if getv(from_object, ['media_resolution']) is not None:
setv(
to_object, ['mediaResolution'], getv(from_object, ['media_resolution'])
)
if getv(from_object, ['executable_code']) is not None:
setv(to_object, ['executableCode'], getv(from_object, ['executable_code']))

if getv(from_object, ['code_execution_result']) is not None:
setv(
Expand All @@ -1356,8 +1406,16 @@ def _Part_to_mldev(
getv(from_object, ['code_execution_result']),
)

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

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

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

if getv(from_object, ['file_data']) is not None:
setv(
Expand Down Expand Up @@ -1406,6 +1464,67 @@ def _Part_to_mldev(
return to_object


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

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

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

if getv(from_object, ['tool_call']) is not None:
raise ValueError('tool_call parameter is not supported in Vertex AI.')

if getv(from_object, ['tool_response']) is not None:
raise ValueError('tool_response parameter is not supported in Vertex AI.')

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

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

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

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

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']))

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

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

return to_object


def _SessionResumptionConfig_to_mldev(
from_object: Union[dict[str, Any], object],
parent_object: Optional[dict[str, Any]] = None,
Expand Down
18 changes: 12 additions & 6 deletions google/genai/_tokens_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,8 @@ def _Part_to_mldev(
parent_object: Optional[dict[str, Any]] = None,
) -> dict[str, Any]:
to_object: dict[str, Any] = {}
if getv(from_object, ['media_resolution']) is not None:
setv(
to_object, ['mediaResolution'], getv(from_object, ['media_resolution'])
)
if getv(from_object, ['executable_code']) is not None:
setv(to_object, ['executableCode'], getv(from_object, ['executable_code']))

if getv(from_object, ['code_execution_result']) is not None:
setv(
Expand All @@ -468,8 +466,16 @@ def _Part_to_mldev(
getv(from_object, ['code_execution_result']),
)

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

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

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

if getv(from_object, ['file_data']) is not None:
setv(
Expand Down
25 changes: 19 additions & 6 deletions google/genai/batches.py
Original file line number Diff line number Diff line change
Expand Up @@ -1395,10 +1395,8 @@ def _Part_to_mldev(
parent_object: Optional[dict[str, Any]] = None,
) -> dict[str, Any]:
to_object: dict[str, Any] = {}
if getv(from_object, ['media_resolution']) is not None:
setv(
to_object, ['mediaResolution'], getv(from_object, ['media_resolution'])
)
if getv(from_object, ['executable_code']) is not None:
setv(to_object, ['executableCode'], getv(from_object, ['executable_code']))

if getv(from_object, ['code_execution_result']) is not None:
setv(
Expand All @@ -1407,8 +1405,16 @@ def _Part_to_mldev(
getv(from_object, ['code_execution_result']),
)

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

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

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

if getv(from_object, ['file_data']) is not None:
setv(
Expand Down Expand Up @@ -1484,6 +1490,13 @@ def _ToolConfig_to_mldev(
to_object, ['retrievalConfig'], getv(from_object, ['retrieval_config'])
)

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

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