From edbe10586e617fe0c100b9a689a86c45f218f8e2 Mon Sep 17 00:00:00 2001 From: A Vertex SDK engineer Date: Wed, 5 Aug 2026 10:56:18 -0700 Subject: [PATCH] feat: Add encryption_spec (CMEK) support to EvaluationRun SDK PiperOrigin-RevId: 959753152 --- agentplatform/_genai/evals.py | 43 +++++++++++ agentplatform/_genai/types/common.py | 54 ++++++++++++++ .../replays/test_create_evaluation_run.py | 25 +++++++ .../replays/test_create_evaluation_set.py | 21 ++++++ .../genai/replays/test_evaluation_metric.py | 30 ++++++++ vertexai/_genai/evals.py | 73 ++++++++++++++++++- vertexai/_genai/types/common.py | 42 +++++++++++ 7 files changed, 286 insertions(+), 2 deletions(-) diff --git a/agentplatform/_genai/evals.py b/agentplatform/_genai/evals.py index 4b600f7054..c835886015 100644 --- a/agentplatform/_genai/evals.py +++ b/agentplatform/_genai/evals.py @@ -108,6 +108,9 @@ def _CreateEvaluationMetricParameters_to_vertex( t.t_metric_for_registry(getv(from_object, ["metric"])), ) + if getv(from_object, ["encryption_spec"]) is not None: + setv(to_object, ["encryptionSpec"], getv(from_object, ["encryption_spec"])) + if getv(from_object, ["config"]) is not None: setv(to_object, ["config"], getv(from_object, ["config"])) @@ -167,6 +170,9 @@ def _CreateEvaluationRunParameters_to_vertex( getv(from_object, ["evaluation_experiment"]), ) + if getv(from_object, ["encryption_spec"]) is not None: + setv(to_object, ["encryptionSpec"], getv(from_object, ["encryption_spec"])) + return to_object @@ -184,6 +190,9 @@ def _CreateEvaluationSetParameters_to_vertex( if getv(from_object, ["config"]) is not None: setv(to_object, ["config"], getv(from_object, ["config"])) + if getv(from_object, ["encryption_spec"]) is not None: + setv(to_object, ["encryptionSpec"], getv(from_object, ["encryption_spec"])) + return to_object @@ -415,6 +424,9 @@ def _EvaluationMetric_from_vertex( _UnifiedMetric_from_vertex(getv(from_object, ["metric"]), to_object), ) + if getv(from_object, ["encryptionSpec"]) is not None: + setv(to_object, ["encryption_spec"], getv(from_object, ["encryptionSpec"])) + return to_object @@ -668,6 +680,9 @@ def _EvaluationRun_from_vertex( [item for item in getv(from_object, ["analysisConfigs"])], ) + if getv(from_object, ["encryptionSpec"]) is not None: + setv(to_object, ["encryption_spec"], getv(from_object, ["encryptionSpec"])) + return to_object @@ -1336,6 +1351,7 @@ def _create_evaluation_metric( display_name: Optional[str] = None, description: Optional[str] = None, metric: Optional[types.MetricOrDict] = None, + encryption_spec: Optional[genai_types.EncryptionSpecOrDict] = None, config: Optional[types.CreateEvaluationMetricConfigOrDict] = None, ) -> types.EvaluationMetric: """ @@ -1346,6 +1362,7 @@ def _create_evaluation_metric( display_name=display_name, description=description, metric=metric, + encryption_spec=encryption_spec, config=config, ) @@ -1423,6 +1440,7 @@ def _create_evaluation_run( config: Optional[types.CreateEvaluationRunConfigOrDict] = None, analysis_configs: Optional[list[types.AnalysisConfigOrDict]] = None, evaluation_experiment: Optional[str] = None, + encryption_spec: Optional[genai_types.EncryptionSpecOrDict] = None, ) -> types.EvaluationRun: """ Creates an EvaluationRun. @@ -1438,6 +1456,7 @@ def _create_evaluation_run( config=config, analysis_configs=analysis_configs, evaluation_experiment=evaluation_experiment, + encryption_spec=encryption_spec, ) request_url_dict: Optional[dict[str, str]] @@ -1506,6 +1525,7 @@ def _create_evaluation_set( evaluation_items: list[str], display_name: Optional[str] = None, config: Optional[types.CreateEvaluationSetConfigOrDict] = None, + encryption_spec: Optional[genai_types.EncryptionSpecOrDict] = None, ) -> types.EvaluationSet: """ Creates an EvaluationSet. @@ -1515,6 +1535,7 @@ def _create_evaluation_set( evaluation_items=evaluation_items, display_name=display_name, config=config, + encryption_spec=encryption_spec, ) request_url_dict: Optional[dict[str, str]] @@ -3236,6 +3257,7 @@ def create_evaluation_run( loss_analysis_metrics: Optional[list[Union[str, types.MetricOrDict]]] = None, loss_analysis_configs: Optional[list[types.LossAnalysisConfigOrDict]] = None, red_teaming_config: Optional[types.RedTeamingAnalysisConfigOrDict] = None, + encryption_spec: Optional[genai_types.EncryptionSpecOrDict] = None, config: Optional[types.CreateEvaluationRunConfigOrDict] = None, ) -> types.EvaluationRun: """Creates an EvaluationRun. @@ -3430,6 +3452,7 @@ def create_evaluation_run( inference_configs=resolved_inference_configs, analysis_configs=resolved_analysis_configs, labels=resolved_labels, + encryption_spec=encryption_spec, config=config, ) @@ -3531,6 +3554,7 @@ def create_evaluation_set( *, evaluation_items: list[str], display_name: Optional[str] = None, + encryption_spec: Optional[genai_types.EncryptionSpecOrDict] = None, config: Optional[types.CreateEvaluationSetConfigOrDict] = None, ) -> types.EvaluationSet: """Creates an EvaluationSet. @@ -3539,6 +3563,8 @@ def create_evaluation_set( evaluation_items: The list of evaluation item names. Format: `projects/{project}/locations/{location}/evaluationItems/{evaluation_item}` display_name: The display name of the evaluation set. + encryption_spec: Customer-managed encryption key spec. If set, this + EvaluationSet will be secured by the provided key. config: The optional configuration for the evaluation set. Must be a dict or `types.CreateEvaluationSetConfigOrDict` type. @@ -3548,6 +3574,7 @@ def create_evaluation_set( return self._create_evaluation_set( evaluation_items=evaluation_items, display_name=display_name, + encryption_spec=encryption_spec, config=config, ) @@ -3695,6 +3722,7 @@ def create_evaluation_metric( display_name: Optional[str] = None, description: Optional[str] = None, metric: Optional[types.MetricOrDict] = None, + encryption_spec: Optional[genai_types.EncryptionSpecOrDict] = None, config: Optional[types.CreateEvaluationMetricConfigOrDict] = None, ) -> str: """Creates an EvaluationMetric.""" @@ -3717,6 +3745,7 @@ def create_evaluation_metric( display_name=display_name, description=description, metric=metric, + encryption_spec=encryption_spec, config=config, ) # result.name is Optional[str], but we know it's always returned on creation @@ -3978,6 +4007,7 @@ async def _create_evaluation_metric( display_name: Optional[str] = None, description: Optional[str] = None, metric: Optional[types.MetricOrDict] = None, + encryption_spec: Optional[genai_types.EncryptionSpecOrDict] = None, config: Optional[types.CreateEvaluationMetricConfigOrDict] = None, ) -> types.EvaluationMetric: """ @@ -3988,6 +4018,7 @@ async def _create_evaluation_metric( display_name=display_name, description=description, metric=metric, + encryption_spec=encryption_spec, config=config, ) @@ -4067,6 +4098,7 @@ async def _create_evaluation_run( config: Optional[types.CreateEvaluationRunConfigOrDict] = None, analysis_configs: Optional[list[types.AnalysisConfigOrDict]] = None, evaluation_experiment: Optional[str] = None, + encryption_spec: Optional[genai_types.EncryptionSpecOrDict] = None, ) -> types.EvaluationRun: """ Creates an EvaluationRun. @@ -4082,6 +4114,7 @@ async def _create_evaluation_run( config=config, analysis_configs=analysis_configs, evaluation_experiment=evaluation_experiment, + encryption_spec=encryption_spec, ) request_url_dict: Optional[dict[str, str]] @@ -4152,6 +4185,7 @@ async def _create_evaluation_set( evaluation_items: list[str], display_name: Optional[str] = None, config: Optional[types.CreateEvaluationSetConfigOrDict] = None, + encryption_spec: Optional[genai_types.EncryptionSpecOrDict] = None, ) -> types.EvaluationSet: """ Creates an EvaluationSet. @@ -4161,6 +4195,7 @@ async def _create_evaluation_set( evaluation_items=evaluation_items, display_name=display_name, config=config, + encryption_spec=encryption_spec, ) request_url_dict: Optional[dict[str, str]] @@ -5515,6 +5550,7 @@ async def create_evaluation_run( labels: Optional[dict[str, str]] = None, loss_analysis_metrics: Optional[list[Union[str, types.MetricOrDict]]] = None, loss_analysis_configs: Optional[list[types.LossAnalysisConfigOrDict]] = None, + encryption_spec: Optional[genai_types.EncryptionSpecOrDict] = None, config: Optional[types.CreateEvaluationRunConfigOrDict] = None, ) -> types.EvaluationRun: """Creates an EvaluationRun. @@ -5710,6 +5746,7 @@ async def create_evaluation_run( inference_configs=resolved_inference_configs, analysis_configs=resolved_analysis_configs, labels=resolved_labels, + encryption_spec=encryption_spec, config=config, ) @@ -5816,6 +5853,7 @@ async def create_evaluation_set( *, evaluation_items: list[str], display_name: Optional[str] = None, + encryption_spec: Optional[genai_types.EncryptionSpecOrDict] = None, config: Optional[types.CreateEvaluationSetConfigOrDict] = None, ) -> types.EvaluationSet: """Creates an EvaluationSet. @@ -5824,6 +5862,8 @@ async def create_evaluation_set( evaluation_items: The list of evaluation item names. Format: `projects/{project}/locations/{location}/evaluationItems/{evaluation_item}` display_name: The display name of the evaluation set. + encryption_spec: Customer-managed encryption key spec. If set, this + EvaluationSet will be secured by the provided key. config: The optional configuration for the evaluation set. Must be a dict or `types.CreateEvaluationSetConfigOrDict` type. @@ -5833,6 +5873,7 @@ async def create_evaluation_set( result = await self._create_evaluation_set( evaluation_items=evaluation_items, display_name=display_name, + encryption_spec=encryption_spec, config=config, ) return result @@ -5981,6 +6022,7 @@ async def create_evaluation_metric( display_name: Optional[str] = None, description: Optional[str] = None, metric: Optional[types.MetricOrDict] = None, + encryption_spec: Optional[genai_types.EncryptionSpecOrDict] = None, config: Optional[types.CreateEvaluationMetricConfigOrDict] = None, ) -> str: """Creates an EvaluationMetric.""" @@ -6001,6 +6043,7 @@ async def create_evaluation_metric( display_name=display_name, description=description, metric=metric, + encryption_spec=encryption_spec, config=config, ) return cast(str, result.name) diff --git a/agentplatform/_genai/types/common.py b/agentplatform/_genai/types/common.py index b0343429c1..1b38648211 100644 --- a/agentplatform/_genai/types/common.py +++ b/agentplatform/_genai/types/common.py @@ -2301,6 +2301,11 @@ class _CreateEvaluationMetricParameters(_common.BaseModel): default=None, description="""The metric configuration of the evaluation metric.""", ) + encryption_spec: Optional[genai_types.EncryptionSpec] = Field( + default=None, + description="""Customer-managed encryption key spec for this EvaluationMetric. + If set, this EvaluationMetric will be secured by this key.""", + ) config: Optional[CreateEvaluationMetricConfig] = Field( default=None, description="""""" ) @@ -2322,6 +2327,10 @@ class _CreateEvaluationMetricParametersDict(TypedDict, total=False): metric: Optional[MetricDict] """The metric configuration of the evaluation metric.""" + encryption_spec: Optional[genai_types.EncryptionSpec] + """Customer-managed encryption key spec for this EvaluationMetric. + If set, this EvaluationMetric will be secured by this key.""" + config: Optional[CreateEvaluationMetricConfigDict] """""" @@ -2446,6 +2455,11 @@ class EvaluationMetric(_common.BaseModel): default=None, description="""The metric configuration of the evaluation metric.""", ) + encryption_spec: Optional[genai_types.EncryptionSpec] = Field( + default=None, + description="""Customer-managed encryption key spec for this EvaluationMetric. + If set, this EvaluationMetric will be secured by this key.""", + ) class EvaluationMetricDict(TypedDict, total=False): @@ -2463,6 +2477,10 @@ class EvaluationMetricDict(TypedDict, total=False): metric: Optional[UnifiedMetricDict] """The metric configuration of the evaluation metric.""" + encryption_spec: Optional[genai_types.EncryptionSpec] + """Customer-managed encryption key spec for this EvaluationMetric. + If set, this EvaluationMetric will be secured by this key.""" + EvaluationMetricOrDict = Union[EvaluationMetric, EvaluationMetricDict] @@ -3023,6 +3041,11 @@ class _CreateEvaluationRunParameters(_common.BaseModel): belongs to. Format: `projects/{project}/locations/{location}/evaluationExperiments/{evaluation_experiment}`.""", ) + encryption_spec: Optional[genai_types.EncryptionSpec] = Field( + default=None, + description="""Customer-managed encryption key spec for this EvaluationRun. + If set, this EvaluationRun will be secured by this key.""", + ) class _CreateEvaluationRunParametersDict(TypedDict, total=False): @@ -3057,6 +3080,10 @@ class _CreateEvaluationRunParametersDict(TypedDict, total=False): belongs to. Format: `projects/{project}/locations/{location}/evaluationExperiments/{evaluation_experiment}`.""" + encryption_spec: Optional[genai_types.EncryptionSpec] + """Customer-managed encryption key spec for this EvaluationRun. + If set, this EvaluationRun will be secured by this key.""" + _CreateEvaluationRunParametersOrDict = Union[ _CreateEvaluationRunParameters, _CreateEvaluationRunParametersDict @@ -3944,6 +3971,11 @@ class EvaluationRun(_common.BaseModel): default=None, description="""The analysis configurations for the evaluation run.""", ) + encryption_spec: Optional[genai_types.EncryptionSpec] = Field( + default=None, + description="""Customer-managed encryption key spec for this EvaluationRun. + If set, this EvaluationRun will be secured by this key.""", + ) # TODO(b/448806531): Remove all the overridden _from_response methods once the # ticket is resolved and published. @@ -4047,6 +4079,10 @@ class EvaluationRunDict(TypedDict, total=False): analysis_configs: Optional[list[AnalysisConfigDict]] """The analysis configurations for the evaluation run.""" + encryption_spec: Optional[genai_types.EncryptionSpec] + """Customer-managed encryption key spec for this EvaluationRun. + If set, this EvaluationRun will be secured by this key.""" + EvaluationRunOrDict = Union[EvaluationRun, EvaluationRunDict] @@ -4079,6 +4115,11 @@ class _CreateEvaluationSetParameters(_common.BaseModel): config: Optional[CreateEvaluationSetConfig] = Field( default=None, description="""""" ) + encryption_spec: Optional[genai_types.EncryptionSpec] = Field( + default=None, + description="""Customer-managed encryption key spec for this EvaluationSet. + If set, this EvaluationSet will be secured by this key.""", + ) class _CreateEvaluationSetParametersDict(TypedDict, total=False): @@ -4093,6 +4134,10 @@ class _CreateEvaluationSetParametersDict(TypedDict, total=False): config: Optional[CreateEvaluationSetConfigDict] """""" + encryption_spec: Optional[genai_types.EncryptionSpec] + """Customer-managed encryption key spec for this EvaluationSet. + If set, this EvaluationSet will be secured by this key.""" + _CreateEvaluationSetParametersOrDict = Union[ _CreateEvaluationSetParameters, _CreateEvaluationSetParametersDict @@ -4121,6 +4166,11 @@ class EvaluationSet(_common.BaseModel): metadata: Optional[dict[str, Any]] = Field( default=None, description="""The metadata of the evaluation set.""" ) + encryption_spec: Optional[genai_types.EncryptionSpec] = Field( + default=None, + description="""Customer-managed encryption key spec for this EvaluationSet. + If set, this EvaluationSet will be secured by this key.""", + ) class EvaluationSetDict(TypedDict, total=False): @@ -4144,6 +4194,10 @@ class EvaluationSetDict(TypedDict, total=False): metadata: Optional[dict[str, Any]] """The metadata of the evaluation set.""" + encryption_spec: Optional[genai_types.EncryptionSpec] + """Customer-managed encryption key spec for this EvaluationSet. + If set, this EvaluationSet will be secured by this key.""" + EvaluationSetOrDict = Union[EvaluationSet, EvaluationSetDict] diff --git a/tests/unit/agentplatform/genai/replays/test_create_evaluation_run.py b/tests/unit/agentplatform/genai/replays/test_create_evaluation_run.py index 738a0b25b2..0b94761fa8 100644 --- a/tests/unit/agentplatform/genai/replays/test_create_evaluation_run.py +++ b/tests/unit/agentplatform/genai/replays/test_create_evaluation_run.py @@ -751,6 +751,31 @@ def test_create_eval_run_with_interactions_data_source(mock_uuid4, client): assert evaluation_run.error is None +_KMS_KEY = ( + "projects/977012026409/locations/us-central1" + "/keyRings/test-kr/cryptoKeys/test-key" +) + + +def test_create_eval_run_with_cmek(client): + """CMEK: encryption_spec is forwarded in the request and returned on the resource.""" + client._api_client._http_options.api_version = "v1beta1" + evaluation_run = client.evals.create_evaluation_run( + name="test_cmek", + display_name="test_cmek", + dataset=types.EvaluationRunDataSource(evaluation_set=EVAL_SET_NAME), + dest=GCS_DEST, + metrics=[GENERAL_QUALITY_METRIC], + encryption_spec=genai_types.EncryptionSpec(kms_key_name=_KMS_KEY), + ) + assert isinstance(evaluation_run, types.EvaluationRun) + assert evaluation_run.display_name == "test_cmek" + assert evaluation_run.state == types.EvaluationRunState.PENDING + assert evaluation_run.encryption_spec is not None + assert evaluation_run.encryption_spec.kms_key_name == _KMS_KEY + assert evaluation_run.error is None + + def test_create_eval_run_with_red_teaming_config(client): """Tests that create_evaluation_run() with red_teaming_config sends analysisConfigs.""" evaluation_run = client.evals.create_evaluation_run( diff --git a/tests/unit/agentplatform/genai/replays/test_create_evaluation_set.py b/tests/unit/agentplatform/genai/replays/test_create_evaluation_set.py index 694c94851f..2a69fd7fec 100644 --- a/tests/unit/agentplatform/genai/replays/test_create_evaluation_set.py +++ b/tests/unit/agentplatform/genai/replays/test_create_evaluation_set.py @@ -16,6 +16,7 @@ from tests.unit.agentplatform.genai.replays import pytest_helper from agentplatform import types +from google.genai import types as genai_types import pytest @@ -36,6 +37,26 @@ def test_create_eval_set(client): assert evaluation_set.evaluation_items == EVAL_ITEMS +_KMS_KEY = ( + "projects/503583131166/locations/us-central1" + "/keyRings/test-kr/cryptoKeys/test-key" +) + + +def test_create_eval_set_with_cmek(client): + """CMEK: encryption_spec is forwarded in the request and returned on the resource.""" + evaluation_set = client.evals.create_evaluation_set( + evaluation_items=EVAL_ITEMS, + display_name=DISPLAY_NAME, + encryption_spec=genai_types.EncryptionSpec(kms_key_name=_KMS_KEY), + ) + assert isinstance(evaluation_set, types.EvaluationSet) + assert evaluation_set.display_name == DISPLAY_NAME + assert evaluation_set.evaluation_items == EVAL_ITEMS + assert evaluation_set.encryption_spec is not None + assert evaluation_set.encryption_spec.kms_key_name == _KMS_KEY + + pytest_plugins = ("pytest_asyncio",) diff --git a/tests/unit/agentplatform/genai/replays/test_evaluation_metric.py b/tests/unit/agentplatform/genai/replays/test_evaluation_metric.py index c9443f9395..40a64ba209 100644 --- a/tests/unit/agentplatform/genai/replays/test_evaluation_metric.py +++ b/tests/unit/agentplatform/genai/replays/test_evaluation_metric.py @@ -18,6 +18,7 @@ from tests.unit.agentplatform.genai.replays import pytest_helper from agentplatform._genai import types from google.genai import errors +from google.genai import types as genai_types import pytest @@ -69,6 +70,35 @@ def test_list_evaluation_metrics_with_filter(client): assert metric.display_name == "tone-check-v1" +def test_create_evaluation_metric_with_cmek(client): + """CMEK: encryption_spec is forwarded in the request and returned on GET.""" + client._api_client._http_options.api_version = "v1beta1" + _KMS_KEY = ( + "projects/977012026409/locations/us-central1" + "/keyRings/test-kr/cryptoKeys/test-key" + ) + result = client.evals.create_evaluation_metric( + display_name="test_cmek_metric", + description="test_cmek_description", + metric=types.LLMMetric( + name="custom_llm_metric", prompt_template="test_prompt_template" + ), + encryption_spec=genai_types.EncryptionSpec(kms_key_name=_KMS_KEY), + ) + assert isinstance(result, str) + assert re.match( + r"^projects/[^/]+/locations/[^/]+/evaluationMetrics/[^/]+$", + result, + ) + + metric = client.evals.get_evaluation_metric(metric_resource_name=result) + assert isinstance(metric, types.EvaluationMetric) + assert metric.display_name == "test_cmek_metric" + # encryption_spec is returned from the API and surfaced on the resource. + assert metric.encryption_spec is not None + assert metric.encryption_spec.kms_key_name == _KMS_KEY + + # The setup function registers the module and method for the recorder pytestmark = pytest_helper.setup( file=__file__, diff --git a/vertexai/_genai/evals.py b/vertexai/_genai/evals.py index 3715571d96..48f02cc500 100644 --- a/vertexai/_genai/evals.py +++ b/vertexai/_genai/evals.py @@ -85,6 +85,9 @@ def _CreateEvaluationMetricParameters_to_vertex( t.t_metric_for_registry(getv(from_object, ["metric"])), ) + if getv(from_object, ["encryption_spec"]) is not None: + setv(to_object, ["encryptionSpec"], getv(from_object, ["encryption_spec"])) + if getv(from_object, ["config"]) is not None: setv(to_object, ["config"], getv(from_object, ["config"])) @@ -137,6 +140,9 @@ def _CreateEvaluationRunParameters_to_vertex( [item for item in getv(from_object, ["analysis_configs"])], ) + if getv(from_object, ["encryption_spec"]) is not None: + setv(to_object, ["encryptionSpec"], getv(from_object, ["encryption_spec"])) + if getv(from_object, ["evaluation_experiment"]) is not None: setv( to_object, @@ -181,6 +187,9 @@ def _CreateEvaluationSetParameters_to_vertex( if getv(from_object, ["display_name"]) is not None: setv(to_object, ["displayName"], getv(from_object, ["display_name"])) + if getv(from_object, ["encryption_spec"]) is not None: + setv(to_object, ["encryptionSpec"], getv(from_object, ["encryption_spec"])) + if getv(from_object, ["config"]) is not None: setv(to_object, ["config"], getv(from_object, ["config"])) @@ -408,6 +417,9 @@ def _EvaluationMetric_from_vertex( _UnifiedMetric_from_vertex(getv(from_object, ["metric"]), to_object), ) + if getv(from_object, ["encryptionSpec"]) is not None: + setv(to_object, ["encryption_spec"], getv(from_object, ["encryptionSpec"])) + return to_object @@ -661,6 +673,9 @@ def _EvaluationRun_from_vertex( [item for item in getv(from_object, ["analysisConfigs"])], ) + if getv(from_object, ["encryptionSpec"]) is not None: + setv(to_object, ["encryption_spec"], getv(from_object, ["encryptionSpec"])) + return to_object @@ -1226,6 +1241,7 @@ def _create_evaluation_metric( display_name: Optional[str] = None, description: Optional[str] = None, metric: Optional[types.MetricOrDict] = None, + encryption_spec: Optional[genai_types.EncryptionSpecOrDict] = None, config: Optional[types.CreateEvaluationMetricConfigOrDict] = None, ) -> types.EvaluationMetric: """ @@ -1236,6 +1252,7 @@ def _create_evaluation_metric( display_name=display_name, description=description, metric=metric, + encryption_spec=encryption_spec, config=config, ) @@ -1312,6 +1329,7 @@ def _create_evaluation_run( ] = None, config: Optional[types.CreateEvaluationRunConfigOrDict] = None, analysis_configs: Optional[list[types.AnalysisConfigOrDict]] = None, + encryption_spec: Optional[genai_types.EncryptionSpecOrDict] = None, evaluation_experiment: Optional[str] = None, ) -> types.EvaluationRun: """ @@ -1327,6 +1345,7 @@ def _create_evaluation_run( inference_configs=inference_configs, config=config, analysis_configs=analysis_configs, + encryption_spec=encryption_spec, evaluation_experiment=evaluation_experiment, ) @@ -1395,6 +1414,7 @@ def _create_evaluation_set( *, evaluation_items: list[str], display_name: Optional[str] = None, + encryption_spec: Optional[genai_types.EncryptionSpecOrDict] = None, config: Optional[types.CreateEvaluationSetConfigOrDict] = None, ) -> types.EvaluationSet: """ @@ -1404,6 +1424,7 @@ def _create_evaluation_set( parameter_model = types._CreateEvaluationSetParameters( evaluation_items=evaluation_items, display_name=display_name, + encryption_spec=encryption_spec, config=config, ) @@ -2766,6 +2787,7 @@ def create_evaluation_run( loss_analysis_metrics: Optional[list[Union[str, types.MetricOrDict]]] = None, loss_analysis_configs: Optional[list[types.LossAnalysisConfigOrDict]] = None, red_teaming_config: Optional[types.RedTeamingAnalysisConfigOrDict] = None, + encryption_spec: Optional[genai_types.EncryptionSpecOrDict] = None, config: Optional[types.CreateEvaluationRunConfigOrDict] = None, ) -> types.EvaluationRun: """Creates an EvaluationRun. @@ -2821,6 +2843,8 @@ def create_evaluation_run( advanced options like ``predefined_taxonomy`` and ``max_top_cluster_count``. Mutually exclusive with ``loss_analysis_metrics``. + encryption_spec: Customer-managed encryption key spec. If set, this + EvaluationRun will be secured by the provided key. config: The configuration for the evaluation run. - allow_cross_region_model: Allows the evaluation run to use cross region models. When this flag is set, the service may route traffic to @@ -2923,6 +2947,7 @@ def create_evaluation_run( inference_configs=resolved_inference_configs, analysis_configs=resolved_analysis_configs, labels=resolved_labels, + encryption_spec=encryption_spec, config=config, ) @@ -3024,6 +3049,7 @@ def create_evaluation_set( *, evaluation_items: list[str], display_name: Optional[str] = None, + encryption_spec: Optional[genai_types.EncryptionSpecOrDict] = None, config: Optional[types.CreateEvaluationSetConfigOrDict] = None, ) -> types.EvaluationSet: """Creates an EvaluationSet. @@ -3032,6 +3058,8 @@ def create_evaluation_set( evaluation_items: The list of evaluation item names. Format: `projects/{project}/locations/{location}/evaluationItems/{evaluation_item}` display_name: The display name of the evaluation set. + encryption_spec: Customer-managed encryption key spec. If set, this + EvaluationSet will be secured by the provided key. config: The optional configuration for the evaluation set. Must be a dict or `types.CreateEvaluationSetConfigOrDict` type. @@ -3041,6 +3069,7 @@ def create_evaluation_set( return self._create_evaluation_set( evaluation_items=evaluation_items, display_name=display_name, + encryption_spec=encryption_spec, config=config, ) @@ -3160,9 +3189,22 @@ def create_evaluation_metric( display_name: Optional[str] = None, description: Optional[str] = None, metric: Optional[types.MetricOrDict] = None, + encryption_spec: Optional[genai_types.EncryptionSpecOrDict] = None, config: Optional[types.CreateEvaluationMetricConfigOrDict] = None, ) -> str: - """Creates an EvaluationMetric.""" + """Creates an EvaluationMetric. + + Args: + display_name: The display name of the EvaluationMetric. + description: The description of the EvaluationMetric. + metric: The metric configuration. + encryption_spec: Customer-managed encryption key spec. If set, this + EvaluationMetric will be secured by the provided key. + config: Optional configuration for the request. + + Returns: + The resource name of the created EvaluationMetric. + """ if metric and not isinstance(metric, dict): # metric is now Metric | LazyLoadedPrebuiltMetric (RubricMetric) # Mypy correctly narrows the type here, so cast is not needed. @@ -3182,6 +3224,7 @@ def create_evaluation_metric( display_name=display_name, description=description, metric=metric, + encryption_spec=encryption_spec, config=config, ) # result.name is Optional[str], but we know it's always returned on creation @@ -3776,6 +3819,7 @@ async def _create_evaluation_metric( display_name: Optional[str] = None, description: Optional[str] = None, metric: Optional[types.MetricOrDict] = None, + encryption_spec: Optional[genai_types.EncryptionSpecOrDict] = None, config: Optional[types.CreateEvaluationMetricConfigOrDict] = None, ) -> types.EvaluationMetric: """ @@ -3786,6 +3830,7 @@ async def _create_evaluation_metric( display_name=display_name, description=description, metric=metric, + encryption_spec=encryption_spec, config=config, ) @@ -3864,6 +3909,7 @@ async def _create_evaluation_run( ] = None, config: Optional[types.CreateEvaluationRunConfigOrDict] = None, analysis_configs: Optional[list[types.AnalysisConfigOrDict]] = None, + encryption_spec: Optional[genai_types.EncryptionSpecOrDict] = None, evaluation_experiment: Optional[str] = None, ) -> types.EvaluationRun: """ @@ -3879,6 +3925,7 @@ async def _create_evaluation_run( inference_configs=inference_configs, config=config, analysis_configs=analysis_configs, + encryption_spec=encryption_spec, evaluation_experiment=evaluation_experiment, ) @@ -3949,6 +3996,7 @@ async def _create_evaluation_set( *, evaluation_items: list[str], display_name: Optional[str] = None, + encryption_spec: Optional[genai_types.EncryptionSpecOrDict] = None, config: Optional[types.CreateEvaluationSetConfigOrDict] = None, ) -> types.EvaluationSet: """ @@ -3958,6 +4006,7 @@ async def _create_evaluation_set( parameter_model = types._CreateEvaluationSetParameters( evaluation_items=evaluation_items, display_name=display_name, + encryption_spec=encryption_spec, config=config, ) @@ -4960,6 +5009,7 @@ async def create_evaluation_run( labels: Optional[dict[str, str]] = None, loss_analysis_metrics: Optional[list[Union[str, types.MetricOrDict]]] = None, loss_analysis_configs: Optional[list[types.LossAnalysisConfigOrDict]] = None, + encryption_spec: Optional[genai_types.EncryptionSpecOrDict] = None, config: Optional[types.CreateEvaluationRunConfigOrDict] = None, ) -> types.EvaluationRun: """Creates an EvaluationRun. @@ -5118,6 +5168,7 @@ async def create_evaluation_run( inference_configs=resolved_inference_configs, analysis_configs=resolved_analysis_configs, labels=resolved_labels, + encryption_spec=encryption_spec, config=config, ) @@ -5224,6 +5275,7 @@ async def create_evaluation_set( *, evaluation_items: list[str], display_name: Optional[str] = None, + encryption_spec: Optional[genai_types.EncryptionSpecOrDict] = None, config: Optional[types.CreateEvaluationSetConfigOrDict] = None, ) -> types.EvaluationSet: """Creates an EvaluationSet. @@ -5232,6 +5284,8 @@ async def create_evaluation_set( evaluation_items: The list of evaluation item names. Format: `projects/{project}/locations/{location}/evaluationItems/{evaluation_item}` display_name: The display name of the evaluation set. + encryption_spec: Customer-managed encryption key spec. If set, this + EvaluationSet will be secured by the provided key. config: The optional configuration for the evaluation set. Must be a dict or `types.CreateEvaluationSetConfigOrDict` type. @@ -5241,6 +5295,7 @@ async def create_evaluation_set( result = await self._create_evaluation_set( evaluation_items=evaluation_items, display_name=display_name, + encryption_spec=encryption_spec, config=config, ) return result @@ -5361,9 +5416,22 @@ async def create_evaluation_metric( display_name: Optional[str] = None, description: Optional[str] = None, metric: Optional[types.MetricOrDict] = None, + encryption_spec: Optional[genai_types.EncryptionSpecOrDict] = None, config: Optional[types.CreateEvaluationMetricConfigOrDict] = None, ) -> str: - """Creates an EvaluationMetric.""" + """Creates an EvaluationMetric. + + Args: + display_name: The display name of the EvaluationMetric. + description: The description of the EvaluationMetric. + metric: The metric configuration. + encryption_spec: Customer-managed encryption key spec. If set, this + EvaluationMetric will be secured by the provided key. + config: Optional configuration for the request. + + Returns: + The resource name of the created EvaluationMetric. + """ if metric and not isinstance(metric, dict): resolved_metrics = _evals_common._resolve_metrics( [metric], self._api_client @@ -5381,6 +5449,7 @@ async def create_evaluation_metric( display_name=display_name, description=description, metric=metric, + encryption_spec=encryption_spec, config=config, ) return cast(str, result.name) diff --git a/vertexai/_genai/types/common.py b/vertexai/_genai/types/common.py index 17d95148d1..8133a608d1 100644 --- a/vertexai/_genai/types/common.py +++ b/vertexai/_genai/types/common.py @@ -2115,6 +2115,10 @@ class _CreateEvaluationMetricParameters(_common.BaseModel): default=None, description="""The metric configuration of the evaluation metric.""", ) + encryption_spec: Optional[genai_types.EncryptionSpec] = Field( + default=None, + description="""Customer-managed encryption key spec for this EvaluationMetric. If set, this EvaluationMetric will be secured by this key.""", + ) config: Optional[CreateEvaluationMetricConfig] = Field( default=None, description="""""" ) @@ -2136,6 +2140,9 @@ class _CreateEvaluationMetricParametersDict(TypedDict, total=False): metric: Optional[MetricDict] """The metric configuration of the evaluation metric.""" + encryption_spec: Optional[genai_types.EncryptionSpecDict] + """Customer-managed encryption key spec for this EvaluationMetric. If set, this EvaluationMetric will be secured by this key.""" + config: Optional[CreateEvaluationMetricConfigDict] """""" @@ -2260,6 +2267,10 @@ class EvaluationMetric(_common.BaseModel): default=None, description="""The metric configuration of the evaluation metric.""", ) + encryption_spec: Optional[genai_types.EncryptionSpec] = Field( + default=None, + description="""Customer-managed encryption key spec for this EvaluationMetric. If set, this EvaluationMetric will be secured by this key.""", + ) class EvaluationMetricDict(TypedDict, total=False): @@ -2277,6 +2288,9 @@ class EvaluationMetricDict(TypedDict, total=False): metric: Optional[UnifiedMetricDict] """The metric configuration of the evaluation metric.""" + encryption_spec: Optional[genai_types.EncryptionSpecDict] + """Customer-managed encryption key spec for this EvaluationMetric. If set, this EvaluationMetric will be secured by this key.""" + EvaluationMetricOrDict = Union[EvaluationMetric, EvaluationMetricDict] @@ -2793,6 +2807,10 @@ class _CreateEvaluationRunParameters(_common.BaseModel): analysis_configs: Optional[list[AnalysisConfig]] = Field( default=None, description="""""" ) + encryption_spec: Optional[genai_types.EncryptionSpec] = Field( + default=None, + description="""Customer-managed encryption key spec for this EvaluationRun. If set, this EvaluationRun will be secured by this key.""", + ) evaluation_experiment: Optional[str] = Field( default=None, description="""The resource name of the parent EvaluationExperiment that this run @@ -2828,6 +2846,9 @@ class _CreateEvaluationRunParametersDict(TypedDict, total=False): analysis_configs: Optional[list[AnalysisConfigDict]] """""" + encryption_spec: Optional[genai_types.EncryptionSpecDict] + """Customer-managed encryption key spec for this EvaluationRun. If set, this EvaluationRun will be secured by this key.""" + evaluation_experiment: Optional[str] """The resource name of the parent EvaluationExperiment that this run belongs to. Format: @@ -3684,6 +3705,10 @@ class EvaluationRun(_common.BaseModel): default=None, description="""The analysis configurations for the evaluation run.""", ) + encryption_spec: Optional[genai_types.EncryptionSpec] = Field( + default=None, + description="""Customer-managed encryption key spec for this EvaluationRun. If set, this EvaluationRun will be secured by this key.""", + ) # TODO(b/448806531): Remove all the overridden _from_response methods once the # ticket is resolved and published. @@ -3787,6 +3812,9 @@ class EvaluationRunDict(TypedDict, total=False): analysis_configs: Optional[list[AnalysisConfigDict]] """The analysis configurations for the evaluation run.""" + encryption_spec: Optional[genai_types.EncryptionSpecDict] + """Customer-managed encryption key spec for this EvaluationRun. If set, this EvaluationRun will be secured by this key.""" + EvaluationRunOrDict = Union[EvaluationRun, EvaluationRunDict] @@ -3816,6 +3844,10 @@ class _CreateEvaluationSetParameters(_common.BaseModel): evaluation_items: Optional[list[str]] = Field(default=None, description="""""") display_name: Optional[str] = Field(default=None, description="""""") + encryption_spec: Optional[genai_types.EncryptionSpec] = Field( + default=None, + description="""Customer-managed encryption key spec for this EvaluationSet. If set, this EvaluationSet will be secured by this key.""", + ) config: Optional[CreateEvaluationSetConfig] = Field( default=None, description="""""" ) @@ -3830,6 +3862,9 @@ class _CreateEvaluationSetParametersDict(TypedDict, total=False): display_name: Optional[str] """""" + encryption_spec: Optional[genai_types.EncryptionSpecDict] + """Customer-managed encryption key spec for this EvaluationSet. If set, this EvaluationSet will be secured by this key.""" + config: Optional[CreateEvaluationSetConfigDict] """""" @@ -3861,6 +3896,10 @@ class EvaluationSet(_common.BaseModel): metadata: Optional[dict[str, Any]] = Field( default=None, description="""The metadata of the evaluation set.""" ) + encryption_spec: Optional[genai_types.EncryptionSpec] = Field( + default=None, + description="""Customer-managed encryption key spec for this EvaluationSet. If set, this EvaluationSet will be secured by this key.""", + ) class EvaluationSetDict(TypedDict, total=False): @@ -3884,6 +3923,9 @@ class EvaluationSetDict(TypedDict, total=False): metadata: Optional[dict[str, Any]] """The metadata of the evaluation set.""" + encryption_spec: Optional[genai_types.EncryptionSpecDict] + """Customer-managed encryption key spec for this EvaluationSet. If set, this EvaluationSet will be secured by this key.""" + EvaluationSetOrDict = Union[EvaluationSet, EvaluationSetDict]