Skip to content
Closed
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
143 changes: 143 additions & 0 deletions google/genai/tunings.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,38 @@ def _CompositeReinforcementTuningRewardConfig_to_vertex(
return to_object


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

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

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

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

return to_object


def _Content_to_vertex(
from_object: Union[dict[str, Any], object],
parent_object: Optional[dict[str, Any]] = None,
Expand Down Expand Up @@ -1441,6 +1473,27 @@ def _ListTuningJobsResponse_from_vertex(
return to_object


def _McpServer_to_vertex(
from_object: Union[dict[str, Any], object],
parent_object: Optional[dict[str, Any]] = None,
root_object: Optional[Union[dict[str, Any], object]] = None,
) -> dict[str, Any]:
to_object: dict[str, Any] = {}
if getv(from_object, ['name']) is not None:
raise ValueError(
'name parameter is only supported in Gemini Developer API mode, not in'
' Gemini Enterprise Agent Platform mode.'
)

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

return to_object


def _MultiSpeakerVoiceConfig_to_vertex(
from_object: Union[dict[str, Any], object],
parent_object: Optional[dict[str, Any]] = None,
Expand Down Expand Up @@ -1662,6 +1715,16 @@ def _ReinforcementTuningExample_to_vertex(
),
)

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

return to_object


Expand Down Expand Up @@ -1893,6 +1956,86 @@ def _SpeechConfig_to_vertex(
return to_object


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

if getv(from_object, ['computer_use']) is not None:
setv(
to_object,
['computerUse'],
_ComputerUse_to_vertex(
getv(from_object, ['computer_use']), to_object, root_object
),
)

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

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

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

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

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

if getv(from_object, ['mcp_servers']) is not None:
setv(
to_object,
['mcpServers'],
[
_McpServer_to_vertex(item, to_object, root_object)
for item in getv(from_object, ['mcp_servers'])
],
)

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

return to_object


def _TunedModel_from_mldev(
from_object: Union[dict[str, Any], object],
parent_object: Optional[dict[str, Any]] = None,
Expand Down
81 changes: 59 additions & 22 deletions google/genai/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,17 @@ def __getattr__(name: str) -> Any:
MetricSubclass = typing.TypeVar('MetricSubclass', bound='Metric')


class MediaProcessing(_common.CaseInSensitiveEnum):
"""How the model processes input media for understanding."""

MEDIA_PROCESSING_UNSPECIFIED = 'MEDIA_PROCESSING_UNSPECIFIED'
"""Default. Uses model-specific processing"""
STATIC = 'STATIC'
"""Fixed-rate frame extraction. All frames placed in context."""
AGENTIC = 'AGENTIC'
"""Model-driven dynamic navigation. Recommended for most use cases."""


class Outcome(_common.CaseInSensitiveEnum):
"""Outcome of the code execution."""

Expand Down Expand Up @@ -485,6 +496,17 @@ class FunctionCallingConfigMode(_common.CaseInSensitiveEnum):
"""Model is constrained to predict either function calls or natural language response. If "allowed_function_names" are set, the predicted function calls will be limited to any one of "allowed_function_names", else the predicted function calls will be any one of the provided "function_declarations"."""


class AudioTranscriptionConfigMode(_common.CaseInSensitiveEnum):
"""Transcription mode."""

MODE_UNSPECIFIED = 'MODE_UNSPECIFIED'
"""Unspecified transcription mode."""
VERBATIM = 'VERBATIM'
"""Verbatim transcription mode."""
SMART = 'SMART'
"""Smart transcription mode."""


class FinishReason(_common.CaseInSensitiveEnum):
"""Output only. The reason why the model stopped generating tokens.

Expand Down Expand Up @@ -613,6 +635,8 @@ class TrafficType(_common.CaseInSensitiveEnum):
"""Type for Priority Pay-As-You-Go traffic."""
ON_DEMAND_FLEX = 'ON_DEMAND_FLEX'
"""Type for Flex traffic."""
ON_DEMAND_OFFPEAK = 'ON_DEMAND_OFFPEAK'
"""Type for Off-Peak Pay-As-You-Go traffic."""
PROVISIONED_THROUGHPUT = 'PROVISIONED_THROUGHPUT'
"""Type for Provisioned Throughput traffic."""

Expand Down Expand Up @@ -1013,17 +1037,6 @@ class ComputationBasedMetricType(_common.CaseInSensitiveEnum):
"""ROUGE metric."""


class MediaProcessing(_common.CaseInSensitiveEnum):
"""How the model processes input media for understanding."""

MEDIA_PROCESSING_UNSPECIFIED = 'MEDIA_PROCESSING_UNSPECIFIED'
"""Default. Uses model-specific processing"""
STATIC = 'STATIC'
"""Fixed-rate frame extraction. All frames placed in context."""
AGENTIC = 'AGENTIC'
"""Model-driven dynamic navigation. Recommended for most use cases."""


class PartMediaResolutionLevel(_common.CaseInSensitiveEnum):
"""The tokenization quality used for given media."""

Expand Down Expand Up @@ -1373,17 +1386,6 @@ class VoiceActivityType(_common.CaseInSensitiveEnum):
"""End of sentence signal."""


class AudioTranscriptionConfigMode(_common.CaseInSensitiveEnum):
"""Transcription mode."""

MODE_UNSPECIFIED = 'MODE_UNSPECIFIED'
"""Unspecified transcription mode."""
VERBATIM = 'VERBATIM'
"""Verbatim transcription mode."""
SMART = 'SMART'
"""Smart transcription mode."""


class StartSensitivity(_common.CaseInSensitiveEnum):
"""Start of speech sensitivity."""

Expand Down Expand Up @@ -11324,6 +11326,10 @@ class VideoResponseFormat(_common.BaseModel):
default=None,
description="""Optional. The Google Cloud Storage URI to store the video output. Required for Vertex if delivery is URI.""",
)
resolution: Optional[str] = Field(
default=None,
description="""Optional. The video output resolution. Supported values: "360p", "720p", "1080p", "4k".""",
)


class VideoResponseFormatDict(TypedDict, total=False):
Expand All @@ -11344,6 +11350,9 @@ class VideoResponseFormatDict(TypedDict, total=False):
gcs_uri: Optional[str]
"""Optional. The Google Cloud Storage URI to store the video output. Required for Vertex if delivery is URI."""

resolution: Optional[str]
"""Optional. The video output resolution. Supported values: "360p", "720p", "1080p", "4k"."""


VideoResponseFormatOrDict = Union[VideoResponseFormat, VideoResponseFormatDict]

Expand Down Expand Up @@ -14062,6 +14071,10 @@ class ReinforcementTuningExample(_common.BaseModel):
default=None,
description="""Corresponds to system_instruction in user-facing GenerateContentRequest.""",
)
tools: Optional[list[Tool]] = Field(
default=None,
description="""Optional. Corresponds to tools in user-facing GenerateContentRequest.""",
)


class ReinforcementTuningExampleDict(TypedDict, total=False):
Expand All @@ -14076,6 +14089,9 @@ class ReinforcementTuningExampleDict(TypedDict, total=False):
system_instruction: Optional[ContentDict]
"""Corresponds to system_instruction in user-facing GenerateContentRequest."""

tools: Optional[list[ToolDict]]
"""Optional. Corresponds to tools in user-facing GenerateContentRequest."""


ReinforcementTuningExampleOrDict = Union[
ReinforcementTuningExample, ReinforcementTuningExampleDict
Expand Down Expand Up @@ -16364,6 +16380,10 @@ class ReinforcementTuningRewardInfo(_common.BaseModel):
default=None,
description="""Output only. The user-requested auxiliary info for the reward function. This field is set only if the Cloud Run reward function configured by user returns a "user_requested_aux_info". Refer to ReinforcementTuningCloudRunRewardScorer for more details.""",
)
error_status: Optional[GoogleRpcStatus] = Field(
default=None,
description="""Output only. In case of an error for this reward, this field will be populated with a detailed error status.""",
)


class ReinforcementTuningRewardInfoDict(TypedDict, total=False):
Expand All @@ -16375,6 +16395,9 @@ class ReinforcementTuningRewardInfoDict(TypedDict, total=False):
user_requested_aux_info: Optional[str]
"""Output only. The user-requested auxiliary info for the reward function. This field is set only if the Cloud Run reward function configured by user returns a "user_requested_aux_info". Refer to ReinforcementTuningCloudRunRewardScorer for more details."""

error_status: Optional[GoogleRpcStatusDict]
"""Output only. In case of an error for this reward, this field will be populated with a detailed error status."""


ReinforcementTuningRewardInfoOrDict = Union[
ReinforcementTuningRewardInfo, ReinforcementTuningRewardInfoDict
Expand Down Expand Up @@ -23094,6 +23117,10 @@ class EvaluationParserConfigCustomCodeParserConfig(_common.BaseModel):
default=None,
description="""Required. Python function for parsing results. The function should be defined within this string. The function takes a list of strings (LLM responses) and should return either a list of dictionaries (for rubrics) or a single dictionary (for a metric result). Example function signature: def parse(responses: list[str]) -> list[dict[str, Any]] | dict[str, Any]: When parsing rubrics, return a list of dictionaries, where each dictionary represents a Rubric. Example for rubrics: [ { "content": {"property": {"description": "The response is factual."}}, "type": "FACTUALITY", "importance": "HIGH" }, { "content": {"property": {"description": "The response is fluent."}}, "type": "FLUENCY", "importance": "MEDIUM" } ] When parsing critique results, return a dictionary representing a MetricResult. Example for a metric result: { "score": 0.8, "explanation": "The model followed most instructions.", "rubric_verdicts": [...] } ... code for result extraction and aggregation""",
)
code_execution_region: Optional[str] = Field(
default=None,
description="""Optional. The region to use for code execution. If set, the Code Execution Sandbox will be invoked in the specified region regardless of the request's originating region. Must be a region where the Code Execution Sandbox is available. Supported regions: us-central1, us-east1, us-east4, us-west1, us-west4, southamerica-east1, europe-west2, europe-west3, asia-east1, asia-south1, asia-southeast1. If unset, the request's originating region is used.""",
)


class EvaluationParserConfigCustomCodeParserConfigDict(TypedDict, total=False):
Expand All @@ -23105,6 +23132,9 @@ class EvaluationParserConfigCustomCodeParserConfigDict(TypedDict, total=False):
parsing_function: Optional[str]
"""Required. Python function for parsing results. The function should be defined within this string. The function takes a list of strings (LLM responses) and should return either a list of dictionaries (for rubrics) or a single dictionary (for a metric result). Example function signature: def parse(responses: list[str]) -> list[dict[str, Any]] | dict[str, Any]: When parsing rubrics, return a list of dictionaries, where each dictionary represents a Rubric. Example for rubrics: [ { "content": {"property": {"description": "The response is factual."}}, "type": "FACTUALITY", "importance": "HIGH" }, { "content": {"property": {"description": "The response is fluent."}}, "type": "FLUENCY", "importance": "MEDIUM" } ] When parsing critique results, return a dictionary representing a MetricResult. Example for a metric result: { "score": 0.8, "explanation": "The model followed most instructions.", "rubric_verdicts": [...] } ... code for result extraction and aggregation"""

code_execution_region: Optional[str]
"""Optional. The region to use for code execution. If set, the Code Execution Sandbox will be invoked in the specified region regardless of the request's originating region. Must be a region where the Code Execution Sandbox is available. Supported regions: us-central1, us-east1, us-east4, us-west1, us-west4, southamerica-east1, europe-west2, europe-west3, asia-east1, asia-south1, asia-southeast1. If unset, the request's originating region is used."""


EvaluationParserConfigCustomCodeParserConfigOrDict = Union[
EvaluationParserConfigCustomCodeParserConfig,
Expand Down Expand Up @@ -23228,6 +23258,10 @@ def evaluate(instance: dict[str, Any]) -> float:
Instance is the evaluation instance, any fields populated in the instance
are available to the function as instance[field_name].""",
)
code_execution_region: Optional[str] = Field(
default=None,
description="""Optional. The region to use for code execution. If set, the Code Execution Sandbox will be invoked in the specified region regardless of the request's originating region. Must be a region where the Code Execution Sandbox is available. Supported regions: us-central1, us-east1, us-east4, us-west1, us-west4, southamerica-east1, europe-west2, europe-west3, asia-east1, asia-south1, asia-southeast1. If unset, the request's originating region is used; requests from regions where the sandbox is unavailable will fail with UNIMPLEMENTED.""",
)


class CustomCodeExecutionSpecDict(TypedDict, total=False):
Expand All @@ -23241,6 +23275,9 @@ def evaluate(instance: dict[str, Any]) -> float:
Instance is the evaluation instance, any fields populated in the instance
are available to the function as instance[field_name]."""

code_execution_region: Optional[str]
"""Optional. The region to use for code execution. If set, the Code Execution Sandbox will be invoked in the specified region regardless of the request's originating region. Must be a region where the Code Execution Sandbox is available. Supported regions: us-central1, us-east1, us-east4, us-west1, us-west4, southamerica-east1, europe-west2, europe-west3, asia-east1, asia-south1, asia-southeast1. If unset, the request's originating region is used; requests from regions where the sandbox is unavailable will fail with UNIMPLEMENTED."""


CustomCodeExecutionSpecOrDict = Union[
CustomCodeExecutionSpec, CustomCodeExecutionSpecDict
Expand Down
Loading