diff --git a/agentplatform/_genai/evals.py b/agentplatform/_genai/evals.py index 4b600f7054..56d490f8b4 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"])) @@ -160,6 +163,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"])) @@ -1336,6 +1345,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 +1356,7 @@ def _create_evaluation_metric( display_name=display_name, description=description, metric=metric, + encryption_spec=encryption_spec, config=config, ) @@ -1422,6 +1433,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: """ @@ -1437,6 +1449,7 @@ def _create_evaluation_run( inference_configs=inference_configs, config=config, analysis_configs=analysis_configs, + encryption_spec=encryption_spec, evaluation_experiment=evaluation_experiment, ) @@ -1505,6 +1518,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: """ @@ -1514,6 +1528,7 @@ def _create_evaluation_set( parameter_model = types._CreateEvaluationSetParameters( evaluation_items=evaluation_items, display_name=display_name, + encryption_spec=encryption_spec, config=config, ) @@ -3236,6 +3251,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 +3446,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 +3548,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 +3557,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 +3568,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,9 +3716,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. @@ -3717,6 +3751,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 +4013,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 +4024,7 @@ async def _create_evaluation_metric( display_name=display_name, description=description, metric=metric, + encryption_spec=encryption_spec, config=config, ) @@ -4066,6 +4103,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: """ @@ -4081,6 +4119,7 @@ async def _create_evaluation_run( inference_configs=inference_configs, config=config, analysis_configs=analysis_configs, + encryption_spec=encryption_spec, evaluation_experiment=evaluation_experiment, ) @@ -4151,6 +4190,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: """ @@ -4160,6 +4200,7 @@ async def _create_evaluation_set( parameter_model = types._CreateEvaluationSetParameters( evaluation_items=evaluation_items, display_name=display_name, + encryption_spec=encryption_spec, config=config, ) @@ -5515,6 +5556,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 +5752,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 +5859,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 +5868,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 +5879,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,9 +6028,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 @@ -6001,6 +6061,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..e0681555ae 100644 --- a/agentplatform/_genai/types/common.py +++ b/agentplatform/_genai/types/common.py @@ -2301,6 +2301,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="""""" ) @@ -2322,6 +2326,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] """""" @@ -2446,6 +2453,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): @@ -2463,6 +2474,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] @@ -3017,6 +3031,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 @@ -3052,6 +3070,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: @@ -3944,6 +3965,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. @@ -4047,6 +4072,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] @@ -4076,6 +4104,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="""""" ) @@ -4090,6 +4122,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] """""" @@ -4121,6 +4156,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): @@ -4144,6 +4183,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] 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..2aa8cfd3e7 100644 --- a/tests/unit/agentplatform/genai/replays/test_create_evaluation_set.py +++ b/tests/unit/agentplatform/genai/replays/test_create_evaluation_set.py @@ -36,6 +36,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=types.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..db1add00d6 100644 --- a/tests/unit/agentplatform/genai/replays/test_evaluation_metric.py +++ b/tests/unit/agentplatform/genai/replays/test_evaluation_metric.py @@ -69,6 +69,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=types.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..b8d477fde7 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"])) @@ -1226,6 +1235,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 +1246,7 @@ def _create_evaluation_metric( display_name=display_name, description=description, metric=metric, + encryption_spec=encryption_spec, config=config, ) @@ -1312,6 +1323,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 +1339,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 +1408,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 +1418,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 +2781,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 +2837,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 +2941,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 +3043,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 +3052,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 +3063,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 +3183,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 +3218,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 +3813,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 +3824,7 @@ async def _create_evaluation_metric( display_name=display_name, description=description, metric=metric, + encryption_spec=encryption_spec, config=config, ) @@ -3864,6 +3903,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 +3919,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 +3990,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 +4000,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 +5003,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 +5162,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 +5269,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 +5278,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 +5289,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 +5410,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 +5443,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]