From b5b7b1dc027ce54d24d1ca1087d3202a6bcc2ca6 Mon Sep 17 00:00:00 2001 From: Amy Wu Date: Tue, 4 Aug 2026 17:16:33 -0700 Subject: [PATCH] feat: Support Endpoints module for OpenModel prediction, and .get/undeploy/delete PiperOrigin-RevId: 959312035 --- agentplatform/_genai/_transformers.py | 31 + agentplatform/_genai/client.py | 23 + agentplatform/_genai/endpoints.py | 1107 ++++++++ agentplatform/_genai/model_garden.py | 4 +- agentplatform/_genai/types/__init__.py | 302 ++- agentplatform/_genai/types/common.py | 2397 +++++++++++++++-- .../genai/replays/test_endpoints.py | 80 + 7 files changed, 3745 insertions(+), 199 deletions(-) create mode 100644 agentplatform/_genai/endpoints.py create mode 100644 tests/unit/agentplatform/genai/replays/test_endpoints.py diff --git a/agentplatform/_genai/_transformers.py b/agentplatform/_genai/_transformers.py index fb6f477cf8..7828076c04 100644 --- a/agentplatform/_genai/_transformers.py +++ b/agentplatform/_genai/_transformers.py @@ -536,3 +536,34 @@ def t_inline_results( api_results.append(api_eval_result) return api_results + + +def t_endpoint(endpoint: str) -> str: + if not endpoint: + raise ValueError("endpoint is required.") + + # Regex patterns + full_endpoint_pattern = re.compile( + r"^projects/[^/]+/locations/[^/]+/endpoints/[^/]+$" + ) + full_publisher_model_pattern = re.compile( + r"^projects/[^/]+/locations/[^/]+/publishers/[^/]+/models/[^/]+$" + ) + + relative_endpoint_pattern = re.compile(r"^endpoints/[^/]+$") + relative_publisher_model_pattern = re.compile(r"^publishers/[^/]+/models/[^/]+$") + + if ( + full_endpoint_pattern.match(endpoint) + or full_publisher_model_pattern.match(endpoint) + or relative_endpoint_pattern.match(endpoint) + or relative_publisher_model_pattern.match(endpoint) + ): + return endpoint + + raise ValueError( + f"Invalid endpoint format: {endpoint}. Must be in the format of" + " projects/.../locations/.../endpoints/... or" + " projects/.../locations/.../publishers/.../models/... or" + " endpoints/... or publishers/.../models/..." + ) diff --git a/agentplatform/_genai/client.py b/agentplatform/_genai/client.py index e93e977980..a44e843b50 100644 --- a/agentplatform/_genai/client.py +++ b/agentplatform/_genai/client.py @@ -50,6 +50,9 @@ from agentplatform._genai import ( memory_banks as memory_banks_module, ) + from agentplatform._genai import ( + endpoints as endpoints_module, + ) _GENAI_MODULES_TELEMETRY_HEADER = "vertex-genai-modules" @@ -96,6 +99,7 @@ def __init__(self, api_client: genai_client.BaseApiClient): # type: ignore[name self._model_garden: Optional[ModuleType] = None self._feedback_entries: Optional[ModuleType] = None self._memory_banks: Optional[ModuleType] = None + self._endpoints: Optional[ModuleType] = None @property @_common.experimental_warning( @@ -186,6 +190,15 @@ def feedback_entries(self) -> "feedback_entries_module.AsyncFeedbackEntries": ) return self._feedback_entries.AsyncFeedbackEntries(self._api_client) # type: ignore[no-any-return] + @property + def endpoints(self) -> "endpoints_module.AsyncEndpoints": + if self._endpoints is None: + self._endpoints = importlib.import_module( + ".endpoints", + __package__, + ) + return self._endpoints.AsyncEndpoints(self._api_client) # type: ignore[no-any-return] + @property @_common.experimental_warning( "The Vertex SDK GenAI async rag module is experimental, " @@ -325,6 +338,7 @@ def __init__( self._model_garden: Optional[ModuleType] = None self._feedback_entries: Optional[ModuleType] = None self._memory_banks: Optional[ModuleType] = None + self._endpoints: Optional[ModuleType] = None @property def evals(self) -> "evals_module.Evals": @@ -440,6 +454,15 @@ def feedback_entries(self) -> "feedback_entries_module.FeedbackEntries": ) return self._feedback_entries.FeedbackEntries(self._api_client) # type: ignore[no-any-return] + @property + def endpoints(self) -> "endpoints_module.Endpoints": + if self._endpoints is None: + self._endpoints = importlib.import_module( + ".endpoints", + __package__, + ) + return self._endpoints.Endpoints(self._api_client) # type: ignore[no-any-return] + @property @_common.experimental_warning( "The Vertex SDK GenAI rag module is experimental, " diff --git a/agentplatform/_genai/endpoints.py b/agentplatform/_genai/endpoints.py new file mode 100644 index 0000000000..4ed7e7c118 --- /dev/null +++ b/agentplatform/_genai/endpoints.py @@ -0,0 +1,1107 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Code generated by the Google Gen AI SDK generator DO NOT EDIT. + +import json +import logging +from typing import Any, Optional, Union +from urllib.parse import urlencode + +from google.genai import _api_module +from google.genai import _common +from google.genai._common import get_value_by_path as getv +from google.genai._common import set_value_by_path as setv + +from . import _operations_utils +from . import _transformers as t +from . import types + +logger = logging.getLogger("agentplatform_genai.endpoints") + + +def _DeleteEndpointRequestParameters_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, ["name"]) is not None: + setv(to_object, ["_url", "name"], getv(from_object, ["name"])) + + return to_object + + +def _GetEndpointOperationParameters_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, ["operation_name"]) is not None: + setv( + to_object, ["_url", "operationName"], getv(from_object, ["operation_name"]) + ) + + return to_object + + +def _GetEndpointParameters_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, ["name"]) is not None: + setv(to_object, ["_url", "name"], t.t_endpoint(getv(from_object, ["name"]))) + + return to_object + + +def _PredictConfig_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, ["parameters"]) is not None: + setv(parent_object, ["parameters"], getv(from_object, ["parameters"])) + + return to_object + + +def _PredictParameters_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, ["instances"]) is not None: + setv(to_object, ["instances"], getv(from_object, ["instances"])) + + if getv(from_object, ["config"]) is not None: + _PredictConfig_to_vertex(getv(from_object, ["config"]), to_object) + + if getv(from_object, ["name"]) is not None: + setv(to_object, ["_url", "endpoint"], t.t_endpoint(getv(from_object, ["name"]))) + + return to_object + + +def _UndeployModelRequestParameters_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, ["name"]) is not None: + setv(to_object, ["_url", "endpoint"], getv(from_object, ["name"])) + + if getv(from_object, ["deployed_model_id"]) is not None: + setv(to_object, ["deployed_model_id"], getv(from_object, ["deployed_model_id"])) + + return to_object + + +class Endpoints(_api_module.BaseModule): + """Class for managing Endpoints for prediction, undeployment, and deletion.""" + + def _undeploy( + self, + *, + name: str, + deployed_model_id: str, + config: Optional[types.UndeployModelConfigOrDict] = None, + ) -> types.UndeployModelOperation: + """ + Undeploys a Model from an Endpoint, removing a + DeployedModel from it, and freeing all resources it's using. + """ + + parameter_model = types._UndeployModelRequestParameters( + name=name, + deployed_model_id=deployed_model_id, + config=config, + ) + + request_url_dict: Optional[dict[str, str]] + if not self._api_client.vertexai: + raise ValueError( + "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode." + ) + else: + request_dict = _UndeployModelRequestParameters_to_vertex(parameter_model) + request_url_dict = request_dict.get("_url") + if request_url_dict: + path = "{endpoint}:undeployModel".format_map(request_url_dict) + else: + path = "{endpoint}:undeployModel" + + query_params = request_dict.get("_query") + if query_params: + path = f"{path}?{urlencode(query_params)}" + # TODO: remove the hack that pops config. + request_dict.pop("config", None) + + http_options: Optional[types.HttpOptions] = None + if ( + parameter_model.config is not None + and parameter_model.config.http_options is not None + ): + http_options = parameter_model.config.http_options + + request_dict = _common.convert_to_dict(request_dict) + request_dict = _common.encode_unserializable_types(request_dict) + + response = self._api_client.request("post", path, request_dict, http_options) + + response_dict = {} if not response.body else json.loads(response.body) + + return_value = types.UndeployModelOperation._from_response( + response=response_dict, + kwargs=( + { + "config": { + "response_schema": getattr( + parameter_model.config, "response_schema", None + ), + "response_json_schema": getattr( + parameter_model.config, "response_json_schema", None + ), + "include_all_fields": getattr( + parameter_model.config, "include_all_fields", None + ), + } + } + if getattr(parameter_model, "config", None) + else {} + ), + ) + + self._api_client._verify_response(return_value) + return return_value + + def _predict( + self, + *, + instances: list[dict[str, Any]], + config: Optional[types.PredictConfigOrDict] = None, + name: str, + ) -> types.PredictResponse: + """ + Perform an online prediction. + """ + + parameter_model = types._PredictParameters( + instances=instances, + config=config, + name=name, + ) + + request_url_dict: Optional[dict[str, str]] + if not self._api_client.vertexai: + raise ValueError( + "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode." + ) + else: + request_dict = _PredictParameters_to_vertex(parameter_model) + request_url_dict = request_dict.get("_url") + if request_url_dict: + path = "{endpoint}:predict".format_map(request_url_dict) + else: + path = "{endpoint}:predict" + + query_params = request_dict.get("_query") + if query_params: + path = f"{path}?{urlencode(query_params)}" + # TODO: remove the hack that pops config. + request_dict.pop("config", None) + + http_options: Optional[types.HttpOptions] = None + if ( + parameter_model.config is not None + and parameter_model.config.http_options is not None + ): + http_options = parameter_model.config.http_options + + request_dict = _common.convert_to_dict(request_dict) + request_dict = _common.encode_unserializable_types(request_dict) + + response = self._api_client.request("post", path, request_dict, http_options) + + response_dict = {} if not response.body else json.loads(response.body) + + return_value = types.PredictResponse._from_response( + response=response_dict, + kwargs=( + { + "config": { + "response_schema": getattr( + parameter_model.config, "response_schema", None + ), + "response_json_schema": getattr( + parameter_model.config, "response_json_schema", None + ), + "include_all_fields": getattr( + parameter_model.config, "include_all_fields", None + ), + } + } + if getattr(parameter_model, "config", None) + else {} + ), + ) + + self._api_client._verify_response(return_value) + return return_value + + def _delete( + self, *, name: str, config: Optional[types.DeleteEndpointConfigOrDict] = None + ) -> types.DeleteEndpointOperation: + """ + Deletes an endpoint resource. + """ + + parameter_model = types._DeleteEndpointRequestParameters( + name=name, + config=config, + ) + + request_url_dict: Optional[dict[str, str]] + if not self._api_client.vertexai: + raise ValueError( + "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode." + ) + else: + request_dict = _DeleteEndpointRequestParameters_to_vertex(parameter_model) + request_url_dict = request_dict.get("_url") + if request_url_dict: + path = "{name}".format_map(request_url_dict) + else: + path = "{name}" + + query_params = request_dict.get("_query") + if query_params: + path = f"{path}?{urlencode(query_params)}" + # TODO: remove the hack that pops config. + request_dict.pop("config", None) + + http_options: Optional[types.HttpOptions] = None + if ( + parameter_model.config is not None + and parameter_model.config.http_options is not None + ): + http_options = parameter_model.config.http_options + + request_dict = _common.convert_to_dict(request_dict) + request_dict = _common.encode_unserializable_types(request_dict) + + response = self._api_client.request("delete", path, request_dict, http_options) + + response_dict = {} if not response.body else json.loads(response.body) + + return_value = types.DeleteEndpointOperation._from_response( + response=response_dict, + kwargs=( + { + "config": { + "response_schema": getattr( + parameter_model.config, "response_schema", None + ), + "response_json_schema": getattr( + parameter_model.config, "response_json_schema", None + ), + "include_all_fields": getattr( + parameter_model.config, "include_all_fields", None + ), + } + } + if getattr(parameter_model, "config", None) + else {} + ), + ) + + self._api_client._verify_response(return_value) + return return_value + + def get( + self, *, name: str, config: Optional[types.GetEndpointConfigOrDict] = None + ) -> types.Endpoint: + """ + Retrieves a specific endpoint resource by its name. + """ + + parameter_model = types._GetEndpointParameters( + name=name, + config=config, + ) + + request_url_dict: Optional[dict[str, str]] + if not self._api_client.vertexai: + raise ValueError( + "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode." + ) + else: + request_dict = _GetEndpointParameters_to_vertex(parameter_model) + request_url_dict = request_dict.get("_url") + if request_url_dict: + path = "{name}".format_map(request_url_dict) + else: + path = "{name}" + + query_params = request_dict.get("_query") + if query_params: + path = f"{path}?{urlencode(query_params)}" + # TODO: remove the hack that pops config. + request_dict.pop("config", None) + + http_options: Optional[types.HttpOptions] = None + if ( + parameter_model.config is not None + and parameter_model.config.http_options is not None + ): + http_options = parameter_model.config.http_options + + request_dict = _common.convert_to_dict(request_dict) + request_dict = _common.encode_unserializable_types(request_dict) + + response = self._api_client.request("get", path, request_dict, http_options) + + response_dict = {} if not response.body else json.loads(response.body) + + return_value = types.Endpoint._from_response( + response=response_dict, + kwargs=( + { + "config": { + "response_schema": getattr( + parameter_model.config, "response_schema", None + ), + "response_json_schema": getattr( + parameter_model.config, "response_json_schema", None + ), + "include_all_fields": getattr( + parameter_model.config, "include_all_fields", None + ), + } + } + if getattr(parameter_model, "config", None) + else {} + ), + ) + + self._api_client._verify_response(return_value) + return return_value + + def _get_endpoint_operation( + self, + *, + operation_name: str, + config: Optional[types.GetEndpointOperationConfigOrDict] = None, + ) -> types.EndpointOperation: + parameter_model = types._GetEndpointOperationParameters( + operation_name=operation_name, + config=config, + ) + + request_url_dict: Optional[dict[str, str]] + if not self._api_client.vertexai: + raise ValueError( + "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode." + ) + else: + request_dict = _GetEndpointOperationParameters_to_vertex(parameter_model) + request_url_dict = request_dict.get("_url") + if request_url_dict: + path = "{operationName}".format_map(request_url_dict) + else: + path = "{operationName}" + + query_params = request_dict.get("_query") + if query_params: + path = f"{path}?{urlencode(query_params)}" + # TODO: remove the hack that pops config. + request_dict.pop("config", None) + + http_options: Optional[types.HttpOptions] = None + if ( + parameter_model.config is not None + and parameter_model.config.http_options is not None + ): + http_options = parameter_model.config.http_options + + request_dict = _common.convert_to_dict(request_dict) + request_dict = _common.encode_unserializable_types(request_dict) + + response = self._api_client.request("get", path, request_dict, http_options) + + response_dict = {} if not response.body else json.loads(response.body) + + return_value = types.EndpointOperation._from_response( + response=response_dict, + kwargs=( + { + "config": { + "response_schema": getattr( + parameter_model.config, "response_schema", None + ), + "response_json_schema": getattr( + parameter_model.config, "response_json_schema", None + ), + "include_all_fields": getattr( + parameter_model.config, "include_all_fields", None + ), + } + } + if getattr(parameter_model, "config", None) + else {} + ), + ) + + self._api_client._verify_response(return_value) + return return_value + + def predict( + self, + *, + name: str, + instances: list[dict[str, Any]], + config: Optional[types.PredictConfigOrDict] = None, + ) -> types.PredictResponse: + + if config is None: + config = types.PredictConfig() + elif isinstance(config, dict): + config = types.PredictConfig.model_validate(config) + elif not isinstance(config, types.PredictConfig): + raise TypeError( + f"config must be a dict or PredictConfig, but got {type(config)}." + ) + + # Get endpoint + if "endpoints" in name: + deployed_endpoint = self.get(name=name) + if deployed_endpoint.dedicated_endpoint_enabled: + if deployed_endpoint.dedicated_endpoint_dns: + dedicated_endpoint_dns = deployed_endpoint.dedicated_endpoint_dns + else: + raise ValueError( + "Dedicated endpoint is enabled but no dedicated endpoint DNS is provided." + ) + + # Inject dedicated endpoint if enabled. + if config.http_options is None: + config.http_options = { + "base_url": "https://" + dedicated_endpoint_dns, + "api_version": "v1", + } + else: + config.http_options.base_url = "https://" + dedicated_endpoint_dns + config.http_options.api_version = ( + "v1" # Otherwise may see 429 errors + ) + + response = self._predict( + name=name, + instances=instances, + config=config, + ) + + return response + + def undeploy( + self, + *, + name: str, + deployed_model_id: str, + config: Optional[types.UndeployModelConfigOrDict] = None, + ) -> Optional[types.UndeployModelOperation]: + """Undeploys a Endpoint. + + Args: + name (str): + Required. The resource name of the Endpoint to undeploy model from. + Format: projects/{project}/locations/{location}/endpoints/{endpoint} + deployed_model_id (str): + Required. The ID of the DeployedModel to undeploy. + config (UndeployModelConfigOrDict): + Optional. Additional configuration for the undeploy operation. + + Returns: + UndeployModelOperation: The pending LRO if wait_for_completion is False, + otherwise None (blocks until done). + """ + if config is None: + config = types.UndeployModelConfig() + elif isinstance(config, dict): + config = types.UndeployModelConfig.model_validate(config) + elif not isinstance(config, types.UndeployModelConfig): + raise TypeError( + f"config must be a dict or UndeployModelConfig, but got {type(config)}." + ) + + operation = self._undeploy( + name=name, deployed_model_id=deployed_model_id, config=config + ) + + if config.wait_for_completion: + operation = _operations_utils.await_operation( + operation_name=operation.name, + get_operation_fn=self._get_endpoint_operation, + ) + if operation.error: + raise RuntimeError(f"Failed to undeploy Endpoint: {operation.error}") + return None + + return operation + + def delete( + self, + *, + name: str, + config: Optional[types.DeleteEndpointConfigOrDict] = None, + ) -> Optional[types.DeleteEndpointOperation]: + """Deletes a Endpoint. + + Args: + name (str): + Required. The resource name of the Endpoint to delete. + Format: projects/{project}/locations/{location}/endpoints/{endpoint} + config (DeleteEndpointConfigOrDict): + Optional. Additional configuration for the delete operation. + + Returns: + DeleteEndpointOperation: The pending LRO if wait_for_completion is False, + otherwise None (blocks until done). + """ + if config is None: + config = types.DeleteEndpointConfig() + elif isinstance(config, dict): + config = types.DeleteEndpointConfig.model_validate(config) + elif not isinstance(config, types.DeleteEndpointConfig): + raise TypeError( + f"config must be a dict or DeleteEndpointConfig, but got {type(config)}." + ) + + operation = self._delete(name=name, config=config) + + if config.wait_for_completion: + operation = _operations_utils.await_operation( + operation_name=operation.name, + get_operation_fn=self._get_endpoint_operation, + ) + if operation.error: + raise RuntimeError(f"Failed to delete Endpoint: {operation.error}") + return None + + return operation + + +class AsyncEndpoints(_api_module.BaseModule): + """Class for managing Endpoints for prediction, undeployment, and deletion.""" + + async def _undeploy( + self, + *, + name: str, + deployed_model_id: str, + config: Optional[types.UndeployModelConfigOrDict] = None, + ) -> types.UndeployModelOperation: + """ + Undeploys a Model from an Endpoint, removing a + DeployedModel from it, and freeing all resources it's using. + """ + + parameter_model = types._UndeployModelRequestParameters( + name=name, + deployed_model_id=deployed_model_id, + config=config, + ) + + request_url_dict: Optional[dict[str, str]] + if not self._api_client.vertexai: + raise ValueError( + "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode." + ) + else: + request_dict = _UndeployModelRequestParameters_to_vertex(parameter_model) + request_url_dict = request_dict.get("_url") + if request_url_dict: + path = "{endpoint}:undeployModel".format_map(request_url_dict) + else: + path = "{endpoint}:undeployModel" + + query_params = request_dict.get("_query") + if query_params: + path = f"{path}?{urlencode(query_params)}" + # TODO: remove the hack that pops config. + request_dict.pop("config", None) + + http_options: Optional[types.HttpOptions] = None + if ( + parameter_model.config is not None + and parameter_model.config.http_options is not None + ): + http_options = parameter_model.config.http_options + + request_dict = _common.convert_to_dict(request_dict) + request_dict = _common.encode_unserializable_types(request_dict) + + response = await self._api_client.async_request( + "post", path, request_dict, http_options + ) + + response_dict = {} if not response.body else json.loads(response.body) + + return_value = types.UndeployModelOperation._from_response( + response=response_dict, + kwargs=( + { + "config": { + "response_schema": getattr( + parameter_model.config, "response_schema", None + ), + "response_json_schema": getattr( + parameter_model.config, "response_json_schema", None + ), + "include_all_fields": getattr( + parameter_model.config, "include_all_fields", None + ), + } + } + if getattr(parameter_model, "config", None) + else {} + ), + ) + + self._api_client._verify_response(return_value) + return return_value + + async def _predict( + self, + *, + instances: list[dict[str, Any]], + config: Optional[types.PredictConfigOrDict] = None, + name: str, + ) -> types.PredictResponse: + """ + Perform an online prediction. + """ + + parameter_model = types._PredictParameters( + instances=instances, + config=config, + name=name, + ) + + request_url_dict: Optional[dict[str, str]] + if not self._api_client.vertexai: + raise ValueError( + "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode." + ) + else: + request_dict = _PredictParameters_to_vertex(parameter_model) + request_url_dict = request_dict.get("_url") + if request_url_dict: + path = "{endpoint}:predict".format_map(request_url_dict) + else: + path = "{endpoint}:predict" + + query_params = request_dict.get("_query") + if query_params: + path = f"{path}?{urlencode(query_params)}" + # TODO: remove the hack that pops config. + request_dict.pop("config", None) + + http_options: Optional[types.HttpOptions] = None + if ( + parameter_model.config is not None + and parameter_model.config.http_options is not None + ): + http_options = parameter_model.config.http_options + + request_dict = _common.convert_to_dict(request_dict) + request_dict = _common.encode_unserializable_types(request_dict) + + response = await self._api_client.async_request( + "post", path, request_dict, http_options + ) + + response_dict = {} if not response.body else json.loads(response.body) + + return_value = types.PredictResponse._from_response( + response=response_dict, + kwargs=( + { + "config": { + "response_schema": getattr( + parameter_model.config, "response_schema", None + ), + "response_json_schema": getattr( + parameter_model.config, "response_json_schema", None + ), + "include_all_fields": getattr( + parameter_model.config, "include_all_fields", None + ), + } + } + if getattr(parameter_model, "config", None) + else {} + ), + ) + + self._api_client._verify_response(return_value) + return return_value + + async def _delete( + self, *, name: str, config: Optional[types.DeleteEndpointConfigOrDict] = None + ) -> types.DeleteEndpointOperation: + """ + Deletes an endpoint resource. + """ + + parameter_model = types._DeleteEndpointRequestParameters( + name=name, + config=config, + ) + + request_url_dict: Optional[dict[str, str]] + if not self._api_client.vertexai: + raise ValueError( + "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode." + ) + else: + request_dict = _DeleteEndpointRequestParameters_to_vertex(parameter_model) + request_url_dict = request_dict.get("_url") + if request_url_dict: + path = "{name}".format_map(request_url_dict) + else: + path = "{name}" + + query_params = request_dict.get("_query") + if query_params: + path = f"{path}?{urlencode(query_params)}" + # TODO: remove the hack that pops config. + request_dict.pop("config", None) + + http_options: Optional[types.HttpOptions] = None + if ( + parameter_model.config is not None + and parameter_model.config.http_options is not None + ): + http_options = parameter_model.config.http_options + + request_dict = _common.convert_to_dict(request_dict) + request_dict = _common.encode_unserializable_types(request_dict) + + response = await self._api_client.async_request( + "delete", path, request_dict, http_options + ) + + response_dict = {} if not response.body else json.loads(response.body) + + return_value = types.DeleteEndpointOperation._from_response( + response=response_dict, + kwargs=( + { + "config": { + "response_schema": getattr( + parameter_model.config, "response_schema", None + ), + "response_json_schema": getattr( + parameter_model.config, "response_json_schema", None + ), + "include_all_fields": getattr( + parameter_model.config, "include_all_fields", None + ), + } + } + if getattr(parameter_model, "config", None) + else {} + ), + ) + + self._api_client._verify_response(return_value) + return return_value + + async def get( + self, *, name: str, config: Optional[types.GetEndpointConfigOrDict] = None + ) -> types.Endpoint: + """ + Retrieves a specific endpoint resource by its name. + """ + + parameter_model = types._GetEndpointParameters( + name=name, + config=config, + ) + + request_url_dict: Optional[dict[str, str]] + if not self._api_client.vertexai: + raise ValueError( + "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode." + ) + else: + request_dict = _GetEndpointParameters_to_vertex(parameter_model) + request_url_dict = request_dict.get("_url") + if request_url_dict: + path = "{name}".format_map(request_url_dict) + else: + path = "{name}" + + query_params = request_dict.get("_query") + if query_params: + path = f"{path}?{urlencode(query_params)}" + # TODO: remove the hack that pops config. + request_dict.pop("config", None) + + http_options: Optional[types.HttpOptions] = None + if ( + parameter_model.config is not None + and parameter_model.config.http_options is not None + ): + http_options = parameter_model.config.http_options + + request_dict = _common.convert_to_dict(request_dict) + request_dict = _common.encode_unserializable_types(request_dict) + + response = await self._api_client.async_request( + "get", path, request_dict, http_options + ) + + response_dict = {} if not response.body else json.loads(response.body) + + return_value = types.Endpoint._from_response( + response=response_dict, + kwargs=( + { + "config": { + "response_schema": getattr( + parameter_model.config, "response_schema", None + ), + "response_json_schema": getattr( + parameter_model.config, "response_json_schema", None + ), + "include_all_fields": getattr( + parameter_model.config, "include_all_fields", None + ), + } + } + if getattr(parameter_model, "config", None) + else {} + ), + ) + + self._api_client._verify_response(return_value) + return return_value + + async def _get_endpoint_operation( + self, + *, + operation_name: str, + config: Optional[types.GetEndpointOperationConfigOrDict] = None, + ) -> types.EndpointOperation: + parameter_model = types._GetEndpointOperationParameters( + operation_name=operation_name, + config=config, + ) + + request_url_dict: Optional[dict[str, str]] + if not self._api_client.vertexai: + raise ValueError( + "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode." + ) + else: + request_dict = _GetEndpointOperationParameters_to_vertex(parameter_model) + request_url_dict = request_dict.get("_url") + if request_url_dict: + path = "{operationName}".format_map(request_url_dict) + else: + path = "{operationName}" + + query_params = request_dict.get("_query") + if query_params: + path = f"{path}?{urlencode(query_params)}" + # TODO: remove the hack that pops config. + request_dict.pop("config", None) + + http_options: Optional[types.HttpOptions] = None + if ( + parameter_model.config is not None + and parameter_model.config.http_options is not None + ): + http_options = parameter_model.config.http_options + + request_dict = _common.convert_to_dict(request_dict) + request_dict = _common.encode_unserializable_types(request_dict) + + response = await self._api_client.async_request( + "get", path, request_dict, http_options + ) + + response_dict = {} if not response.body else json.loads(response.body) + + return_value = types.EndpointOperation._from_response( + response=response_dict, + kwargs=( + { + "config": { + "response_schema": getattr( + parameter_model.config, "response_schema", None + ), + "response_json_schema": getattr( + parameter_model.config, "response_json_schema", None + ), + "include_all_fields": getattr( + parameter_model.config, "include_all_fields", None + ), + } + } + if getattr(parameter_model, "config", None) + else {} + ), + ) + + self._api_client._verify_response(return_value) + return return_value + + async def predict( + self, + *, + name: str, + instances: list[dict[str, Any]], + config: Optional[types.PredictConfigOrDict] = None, + ) -> types.PredictResponse: + + if config is None: + config = types.PredictConfig() + elif isinstance(config, dict): + config = types.PredictConfig.model_validate(config) + elif not isinstance(config, types.PredictConfig): + raise TypeError( + f"config must be a dict or PredictConfig, but got {type(config)}." + ) + + # Get endpoint + if "endpoints" in name: + deployed_endpoint = self.get(name=name) + if deployed_endpoint.dedicated_endpoint_enabled: + if deployed_endpoint.dedicated_endpoint_dns: + dedicated_endpoint_dns = deployed_endpoint.dedicated_endpoint_dns + else: + raise ValueError( + "Dedicated endpoint is enabled but no dedicated endpoint DNS is provided." + ) + + # Inject dedicated endpoint if enabled. + if config.http_options is None: + config.http_options = { + "base_url": "https://" + dedicated_endpoint_dns, + "api_version": "v1", + } + else: + config.http_options.base_url = "https://" + dedicated_endpoint_dns + config.http_options.api_version = ( + "v1" # Otherwise may see 429 errors + ) + response = await self._predict( + name=name, + instances=instances, + config=config, + ) + + return response + + async def undeploy( + self, + *, + name: str, + deployed_model_id: str, + config: Optional[types.UndeployModelConfigOrDict] = None, + ) -> Optional[types.UndeployModelOperation]: + """Undeploys a Endpoint. + + Args: + name (str): + Required. The resource name of the Endpoint to undeploy model from. + Format: projects/{project}/locations/{location}/endpoints/{endpoint} + deployed_model_id (str): + Required. The ID of the DeployedModel to undeploy. + config (UndeployModelConfigOrDict): + Optional. Additional configuration for the undeploy operation. + + Returns: + UndeployModelOperation: The pending LRO if wait_for_completion is False, + otherwise None (blocks until done). + """ + if config is None: + config = types.UndeployModelConfig() + elif isinstance(config, dict): + config = types.UndeployModelConfig.model_validate(config) + elif not isinstance(config, types.UndeployModelConfig): + raise TypeError( + f"config must be a dict or UndeployModelConfig, but got {type(config)}." + ) + + operation = await self._undeploy( + name=name, deployed_model_id=deployed_model_id, config=config + ) + + if config.wait_for_completion: + operation = await _operations_utils.await_operation_async( + operation_name=operation.name, + get_operation_fn=self._get_endpoint_operation, + ) + if operation.error: + raise RuntimeError(f"Failed to undeploy Endpoint: {operation.error}") + return None + + return operation + + async def delete( + self, + *, + name: str, + config: Optional[types.DeleteEndpointConfigOrDict] = None, + ) -> Optional[types.DeleteEndpointOperation]: + """Deletes a Endpoint. + + Args: + name (str): + Required. The resource name of the Endpoint to delete. + Format: projects/{project}/locations/{location}/endpoints/{endpoint} + config (DeleteEndpointConfigOrDict): + Optional. Additional configuration for the delete operation. + + Returns: + DeleteEndpointOperation: The pending LRO if wait_for_completion is False, + otherwise None (blocks until done). + """ + if config is None: + config = types.DeleteEndpointConfig() + elif isinstance(config, dict): + config = types.DeleteEndpointConfig.model_validate(config) + elif not isinstance(config, types.DeleteEndpointConfig): + raise TypeError( + f"config must be a dict or DeleteEndpointConfig, but got {type(config)}." + ) + + operation = await self._delete(name=name, config=config) + + if config.wait_for_completion: + operation = await _operations_utils.await_operation_async( + operation_name=operation.name, + get_operation_fn=self._get_endpoint_operation, + ) + if operation.error: + raise RuntimeError(f"Failed to delete Endpoint: {operation.error}") + return None + + return operation diff --git a/agentplatform/_genai/model_garden.py b/agentplatform/_genai/model_garden.py index 61d19be50f..682e831b57 100644 --- a/agentplatform/_genai/model_garden.py +++ b/agentplatform/_genai/model_garden.py @@ -504,7 +504,7 @@ def get_export_publisher_model_operation( config: Optional[types.GetExportPublisherModelOperationConfigOrDict] = None, ) -> types.ExportModelOperation: """ - Fetches the status of an in-flight ``export_open_model`` LRO. + Fetches the status of an in-flight export_open_model LRO. """ parameter_model = types._GetExportPublisherModelOperationParameters( @@ -1626,7 +1626,7 @@ async def get_export_publisher_model_operation( config: Optional[types.GetExportPublisherModelOperationConfigOrDict] = None, ) -> types.ExportModelOperation: """ - Fetches the status of an in-flight ``export_open_model`` LRO. + Fetches the status of an in-flight export_open_model LRO. """ parameter_model = types._GetExportPublisherModelOperationParameters( diff --git a/agentplatform/_genai/types/__init__.py b/agentplatform/_genai/types/__init__.py index 9e9278030a..2845b7f74a 100644 --- a/agentplatform/_genai/types/__init__.py +++ b/agentplatform/_genai/types/__init__.py @@ -56,6 +56,7 @@ from .common import _DeleteAgentEngineSessionRequestParameters from .common import _DeleteAgentEngineTaskRequestParameters from .common import _DeleteDatasetRequestParameters +from .common import _DeleteEndpointRequestParameters from .common import _DeleteEvaluationExperimentParameters from .common import _DeleteEvaluationMetricParameters from .common import _DeleteMemoryBankRequestParameters @@ -91,6 +92,8 @@ from .common import _GetDatasetParameters from .common import _GetDatasetVersionParameters from .common import _GetDeleteAgentEngineRuntimeRevisionOperationParameters +from .common import _GetEndpointOperationParameters +from .common import _GetEndpointParameters from .common import _GetEvaluationExperimentParameters from .common import _GetEvaluationItemParameters from .common import _GetEvaluationMetricParameters @@ -147,6 +150,7 @@ from .common import _ListSkillsRequestParameters from .common import _OptimizeRequestParameters from .common import _OptimizeRequestParameters +from .common import _PredictParameters from .common import _PurgeMemoriesRequestParameters from .common import _QueryAgentEngineRequestParameters from .common import _QueryAgentEngineRuntimeRevisionRequestParameters @@ -161,6 +165,7 @@ from .common import _RunQueryJobAgentEngineConfigDict from .common import _RunQueryJobAgentEngineConfigOrDict from .common import _RunQueryJobAgentEngineRequestParameters +from .common import _UndeployModelRequestParameters from .common import _UpdateAgentEngineRequestParameters from .common import _UpdateAgentEngineSessionRequestParameters from .common import _UpdateDatasetParameters @@ -272,6 +277,9 @@ from .common import BleuResults from .common import BleuResultsDict from .common import BleuResultsOrDict +from .common import BlurBaselineConfig +from .common import BlurBaselineConfigDict +from .common import BlurBaselineConfigOrDict from .common import CancelQueryJobAgentEngineConfig from .common import CancelQueryJobAgentEngineConfigDict from .common import CancelQueryJobAgentEngineConfigOrDict @@ -295,7 +303,11 @@ from .common import Chunk from .common import ChunkDict from .common import ChunkOrDict +from .common import ClientConnectionConfig +from .common import ClientConnectionConfigDict +from .common import ClientConnectionConfigOrDict from .common import CodeExecutionMetric +from .common import ColorMap from .common import CometResult from .common import CometResultDict from .common import CometResultOrDict @@ -386,6 +398,7 @@ from .common import CustomJobSpec from .common import CustomJobSpecDict from .common import CustomJobSpecOrDict +from .common import DataFormat from .common import Dataset from .common import DatasetDict from .common import DatasetOperation @@ -429,6 +442,12 @@ from .common import DeleteAgentEngineTaskConfig from .common import DeleteAgentEngineTaskConfigDict from .common import DeleteAgentEngineTaskConfigOrDict +from .common import DeleteEndpointConfig +from .common import DeleteEndpointConfigDict +from .common import DeleteEndpointConfigOrDict +from .common import DeleteEndpointOperation +from .common import DeleteEndpointOperationDict +from .common import DeleteEndpointOperationOrDict from .common import DeleteEvaluationExperimentConfig from .common import DeleteEvaluationExperimentConfigDict from .common import DeleteEvaluationExperimentConfigOrDict @@ -498,6 +517,13 @@ from .common import DeleteSkillOperation from .common import DeleteSkillOperationDict from .common import DeleteSkillOperationOrDict +from .common import DeployedModel +from .common import DeployedModelDict +from .common import DeployedModelOrDict +from .common import DeployedModelStatus +from .common import DeployedModelStatusDict +from .common import DeployedModelStatusOrDict +from .common import DeploymentType from .common import DeployOption from .common import DeployOptionDict from .common import DeployOptionOrDict @@ -510,6 +536,13 @@ from .common import DnsPeeringConfig from .common import DnsPeeringConfigDict from .common import DnsPeeringConfigOrDict +from .common import Encoding +from .common import Endpoint +from .common import EndpointDict +from .common import EndpointOperation +from .common import EndpointOperationDict +from .common import EndpointOperationOrDict +from .common import EndpointOrDict from .common import EnvVar from .common import EnvVarDict from .common import EnvVarOrDict @@ -623,12 +656,39 @@ from .common import ExactMatchSpec from .common import ExactMatchSpecDict from .common import ExactMatchSpecOrDict +from .common import Examples +from .common import ExamplesDict +from .common import ExamplesExampleGcsSource +from .common import ExamplesExampleGcsSourceDict +from .common import ExamplesExampleGcsSourceOrDict +from .common import ExamplesOrDict from .common import ExecuteCodeAgentEngineSandboxConfig from .common import ExecuteCodeAgentEngineSandboxConfigDict from .common import ExecuteCodeAgentEngineSandboxConfigOrDict from .common import ExecuteSandboxEnvironmentResponse from .common import ExecuteSandboxEnvironmentResponseDict from .common import ExecuteSandboxEnvironmentResponseOrDict +from .common import ExplanationMetadata +from .common import ExplanationMetadataDict +from .common import ExplanationMetadataInputMetadata +from .common import ExplanationMetadataInputMetadataDict +from .common import ExplanationMetadataInputMetadataFeatureValueDomain +from .common import ExplanationMetadataInputMetadataFeatureValueDomainDict +from .common import ExplanationMetadataInputMetadataFeatureValueDomainOrDict +from .common import ExplanationMetadataInputMetadataOrDict +from .common import ExplanationMetadataInputMetadataVisualization +from .common import ExplanationMetadataInputMetadataVisualizationDict +from .common import ExplanationMetadataInputMetadataVisualizationOrDict +from .common import ExplanationMetadataOrDict +from .common import ExplanationMetadataOutputMetadata +from .common import ExplanationMetadataOutputMetadataDict +from .common import ExplanationMetadataOutputMetadataOrDict +from .common import ExplanationParameters +from .common import ExplanationParametersDict +from .common import ExplanationParametersOrDict +from .common import ExplanationSpec +from .common import ExplanationSpecDict +from .common import ExplanationSpecOrDict from .common import ExportModelOperation from .common import ExportModelOperationDict from .common import ExportModelOperationOrDict @@ -644,6 +704,15 @@ from .common import FailedRubric from .common import FailedRubricDict from .common import FailedRubricOrDict +from .common import FasterDeploymentConfig +from .common import FasterDeploymentConfigDict +from .common import FasterDeploymentConfigOrDict +from .common import FeatureNoiseSigma +from .common import FeatureNoiseSigmaDict +from .common import FeatureNoiseSigmaNoiseSigmaForFeature +from .common import FeatureNoiseSigmaNoiseSigmaForFeatureDict +from .common import FeatureNoiseSigmaNoiseSigmaForFeatureOrDict +from .common import FeatureNoiseSigmaOrDict from .common import FeedbackContext from .common import FeedbackContextDict from .common import FeedbackContextOrDict @@ -655,6 +724,12 @@ from .common import FlexStartDict from .common import FlexStartOrDict from .common import Framework +from .common import FullFineTunedResources +from .common import FullFineTunedResourcesDict +from .common import FullFineTunedResourcesOrDict +from .common import GdcConfig +from .common import GdcConfigDict +from .common import GdcConfigOrDict from .common import GeminiAgentConfig from .common import GeminiAgentConfigDict from .common import GeminiAgentConfigOrDict @@ -667,6 +742,12 @@ from .common import GeminiTemplateConfig from .common import GeminiTemplateConfigDict from .common import GeminiTemplateConfigOrDict +from .common import GenAiAdvancedFeaturesConfig +from .common import GenAiAdvancedFeaturesConfigDict +from .common import GenAiAdvancedFeaturesConfigOrDict +from .common import GenAiAdvancedFeaturesConfigRagConfig +from .common import GenAiAdvancedFeaturesConfigRagConfigDict +from .common import GenAiAdvancedFeaturesConfigRagConfigOrDict from .common import GenerateInstanceRubricsResponse from .common import GenerateInstanceRubricsResponseDict from .common import GenerateInstanceRubricsResponseOrDict @@ -740,6 +821,12 @@ from .common import GetDeleteAgentEngineRuntimeRevisionOperationConfig from .common import GetDeleteAgentEngineRuntimeRevisionOperationConfigDict from .common import GetDeleteAgentEngineRuntimeRevisionOperationConfigOrDict +from .common import GetEndpointConfig +from .common import GetEndpointConfigDict +from .common import GetEndpointConfigOrDict +from .common import GetEndpointOperationConfig +from .common import GetEndpointOperationConfigDict +from .common import GetEndpointOperationConfigOrDict from .common import GetEvaluationExperimentConfig from .common import GetEvaluationExperimentConfigDict from .common import GetEvaluationExperimentConfigOrDict @@ -850,6 +937,9 @@ from .common import IngestionDirectContentsSourceEventDict from .common import IngestionDirectContentsSourceEventOrDict from .common import IngestionDirectContentsSourceOrDict +from .common import IntegratedGradientsAttribution +from .common import IntegratedGradientsAttributionDict +from .common import IntegratedGradientsAttributionOrDict from .common import InteractionsDataSource from .common import InteractionsDataSourceDict from .common import InteractionsDataSourceOrDict @@ -1150,6 +1240,7 @@ from .common import MetricxResult from .common import MetricxResultDict from .common import MetricxResultOrDict +from .common import Modality from .common import ModelContainerSpec from .common import ModelContainerSpecDict from .common import ModelContainerSpecOrDict @@ -1181,6 +1272,7 @@ from .common import OptimizeResponseEndpointOrDict from .common import OptimizeResponseOrDict from .common import OptimizeTarget +from .common import OverlayType from .common import PairwiseMetricInput from .common import PairwiseMetricInputDict from .common import PairwiseMetricInputOrDict @@ -1194,13 +1286,32 @@ from .common import PointwiseMetricInstance from .common import PointwiseMetricInstanceDict from .common import PointwiseMetricInstanceOrDict +from .common import Polarity from .common import Port from .common import PortDict from .common import PortOrDict from .common import PostSnapshotAction +from .common import PredictConfig +from .common import PredictConfigDict +from .common import PredictConfigOrDict +from .common import PredictRequestResponseLoggingConfig +from .common import PredictRequestResponseLoggingConfigDict +from .common import PredictRequestResponseLoggingConfigOrDict +from .common import PredictResponse +from .common import PredictResponseDict +from .common import PredictResponseOrDict from .common import PredictSchemata from .common import PredictSchemataDict from .common import PredictSchemataOrDict +from .common import Presets +from .common import PresetsDict +from .common import PresetsOrDict +from .common import PrivateEndpoints +from .common import PrivateEndpointsDict +from .common import PrivateEndpointsOrDict +from .common import PrivateServiceConnectConfig +from .common import PrivateServiceConnectConfigDict +from .common import PrivateServiceConnectConfigOrDict from .common import Probe from .common import ProbeDict from .common import ProbeExecAction @@ -1242,6 +1353,10 @@ from .common import PromptVersionRefDict from .common import PromptVersionRefOrDict from .common import Protocol +from .common import PSCAutomationConfig +from .common import PSCAutomationConfigDict +from .common import PSCAutomationConfigOrDict +from .common import PscAutomationState from .common import PscInterfaceConfig from .common import PscInterfaceConfigDict from .common import PscInterfaceConfigOrDict @@ -1606,6 +1721,9 @@ from .common import RollbackMemoryOperation from .common import RollbackMemoryOperationDict from .common import RollbackMemoryOperationOrDict +from .common import RolloutOptions +from .common import RolloutOptionsDict +from .common import RolloutOptionsOrDict from .common import RougeInput from .common import RougeInputDict from .common import RougeInputOrDict @@ -1656,6 +1774,9 @@ from .common import RuntimeFeedbackEntryOperation from .common import RuntimeFeedbackEntryOperationDict from .common import RuntimeFeedbackEntryOperationOrDict +from .common import SampledShapleyAttribution +from .common import SampledShapleyAttributionDict +from .common import SampledShapleyAttributionOrDict from .common import SamplingConfig from .common import SamplingConfigDict from .common import SamplingConfigOrDict @@ -1820,6 +1941,18 @@ from .common import SlackSourceSlackChannelsSlackChannel from .common import SlackSourceSlackChannelsSlackChannelDict from .common import SlackSourceSlackChannelsSlackChannelOrDict +from .common import SmoothGradConfig +from .common import SmoothGradConfigDict +from .common import SmoothGradConfigOrDict +from .common import SpeculativeDecodingSpec +from .common import SpeculativeDecodingSpecDict +from .common import SpeculativeDecodingSpecDraftModelSpeculation +from .common import SpeculativeDecodingSpecDraftModelSpeculationDict +from .common import SpeculativeDecodingSpecDraftModelSpeculationOrDict +from .common import SpeculativeDecodingSpecNgramSpeculation +from .common import SpeculativeDecodingSpecNgramSpeculationDict +from .common import SpeculativeDecodingSpecNgramSpeculationOrDict +from .common import SpeculativeDecodingSpecOrDict from .common import State from .common import Strategy from .common import StructuredMemoryConfig @@ -1937,6 +2070,12 @@ from .common import TuningValidationAssessmentResultDict from .common import TuningValidationAssessmentResultOrDict from .common import Type +from .common import UndeployModelConfig +from .common import UndeployModelConfigDict +from .common import UndeployModelConfigOrDict +from .common import UndeployModelOperation +from .common import UndeployModelOperationDict +from .common import UndeployModelOperationOrDict from .common import UnifiedMetric from .common import UnifiedMetricDict from .common import UnifiedMetricOrDict @@ -2001,6 +2140,9 @@ from .common import WorkerPoolSpec from .common import WorkerPoolSpecDict from .common import WorkerPoolSpecOrDict +from .common import XraiAttribution +from .common import XraiAttributionDict +from .common import XraiAttributionOrDict __all__ = [ "DeleteAgentEngineTaskConfig", @@ -2084,6 +2226,9 @@ "CandidateResponse", "CandidateResponseDict", "CandidateResponseOrDict", + "RubricGroup", + "RubricGroupDict", + "RubricGroupOrDict", "EvaluationItemRequest", "EvaluationItemRequestDict", "EvaluationItemRequestOrDict", @@ -3317,6 +3462,12 @@ "SchemaPredictParamsGroundingConfig", "SchemaPredictParamsGroundingConfigDict", "SchemaPredictParamsGroundingConfigOrDict", + "SchemaPromptSpecPartList", + "SchemaPromptSpecPartListDict", + "SchemaPromptSpecPartListOrDict", + "SchemaPromptInstanceVariableValue", + "SchemaPromptInstanceVariableValueDict", + "SchemaPromptInstanceVariableValueOrDict", "SchemaPromptInstancePromptExecution", "SchemaPromptInstancePromptExecutionDict", "SchemaPromptInstancePromptExecutionOrDict", @@ -3332,9 +3483,6 @@ "SchemaPromptSpecAppBuilderData", "SchemaPromptSpecAppBuilderDataDict", "SchemaPromptSpecAppBuilderDataOrDict", - "SchemaPromptSpecPartList", - "SchemaPromptSpecPartListDict", - "SchemaPromptSpecPartListOrDict", "SchemaPromptSpecInteractionData", "SchemaPromptSpecInteractionDataDict", "SchemaPromptSpecInteractionDataOrDict", @@ -3632,6 +3780,135 @@ "UpdateRuntimeFeedbackContextConfig", "UpdateRuntimeFeedbackContextConfigDict", "UpdateRuntimeFeedbackContextConfigOrDict", + "UndeployModelConfig", + "UndeployModelConfigDict", + "UndeployModelConfigOrDict", + "UndeployModelOperation", + "UndeployModelOperationDict", + "UndeployModelOperationOrDict", + "PredictConfig", + "PredictConfigDict", + "PredictConfigOrDict", + "PredictResponse", + "PredictResponseDict", + "PredictResponseOrDict", + "DeleteEndpointConfig", + "DeleteEndpointConfigDict", + "DeleteEndpointConfigOrDict", + "DeleteEndpointOperation", + "DeleteEndpointOperationDict", + "DeleteEndpointOperationOrDict", + "GetEndpointConfig", + "GetEndpointConfigDict", + "GetEndpointConfigOrDict", + "ExplanationMetadataInputMetadataFeatureValueDomain", + "ExplanationMetadataInputMetadataFeatureValueDomainDict", + "ExplanationMetadataInputMetadataFeatureValueDomainOrDict", + "ExplanationMetadataInputMetadataVisualization", + "ExplanationMetadataInputMetadataVisualizationDict", + "ExplanationMetadataInputMetadataVisualizationOrDict", + "ExplanationMetadataInputMetadata", + "ExplanationMetadataInputMetadataDict", + "ExplanationMetadataInputMetadataOrDict", + "ExplanationMetadataOutputMetadata", + "ExplanationMetadataOutputMetadataDict", + "ExplanationMetadataOutputMetadataOrDict", + "ExplanationMetadata", + "ExplanationMetadataDict", + "ExplanationMetadataOrDict", + "ExamplesExampleGcsSource", + "ExamplesExampleGcsSourceDict", + "ExamplesExampleGcsSourceOrDict", + "Presets", + "PresetsDict", + "PresetsOrDict", + "Examples", + "ExamplesDict", + "ExamplesOrDict", + "BlurBaselineConfig", + "BlurBaselineConfigDict", + "BlurBaselineConfigOrDict", + "FeatureNoiseSigmaNoiseSigmaForFeature", + "FeatureNoiseSigmaNoiseSigmaForFeatureDict", + "FeatureNoiseSigmaNoiseSigmaForFeatureOrDict", + "FeatureNoiseSigma", + "FeatureNoiseSigmaDict", + "FeatureNoiseSigmaOrDict", + "SmoothGradConfig", + "SmoothGradConfigDict", + "SmoothGradConfigOrDict", + "IntegratedGradientsAttribution", + "IntegratedGradientsAttributionDict", + "IntegratedGradientsAttributionOrDict", + "SampledShapleyAttribution", + "SampledShapleyAttributionDict", + "SampledShapleyAttributionOrDict", + "XraiAttribution", + "XraiAttributionDict", + "XraiAttributionOrDict", + "ExplanationParameters", + "ExplanationParametersDict", + "ExplanationParametersOrDict", + "ExplanationSpec", + "ExplanationSpecDict", + "ExplanationSpecOrDict", + "FasterDeploymentConfig", + "FasterDeploymentConfigDict", + "FasterDeploymentConfigOrDict", + "FullFineTunedResources", + "FullFineTunedResourcesDict", + "FullFineTunedResourcesOrDict", + "PrivateEndpoints", + "PrivateEndpointsDict", + "PrivateEndpointsOrDict", + "RolloutOptions", + "RolloutOptionsDict", + "RolloutOptionsOrDict", + "SpeculativeDecodingSpecDraftModelSpeculation", + "SpeculativeDecodingSpecDraftModelSpeculationDict", + "SpeculativeDecodingSpecDraftModelSpeculationOrDict", + "SpeculativeDecodingSpecNgramSpeculation", + "SpeculativeDecodingSpecNgramSpeculationDict", + "SpeculativeDecodingSpecNgramSpeculationOrDict", + "SpeculativeDecodingSpec", + "SpeculativeDecodingSpecDict", + "SpeculativeDecodingSpecOrDict", + "DeployedModelStatus", + "DeployedModelStatusDict", + "DeployedModelStatusOrDict", + "DeployedModel", + "DeployedModelDict", + "DeployedModelOrDict", + "ClientConnectionConfig", + "ClientConnectionConfigDict", + "ClientConnectionConfigOrDict", + "GdcConfig", + "GdcConfigDict", + "GdcConfigOrDict", + "GenAiAdvancedFeaturesConfigRagConfig", + "GenAiAdvancedFeaturesConfigRagConfigDict", + "GenAiAdvancedFeaturesConfigRagConfigOrDict", + "GenAiAdvancedFeaturesConfig", + "GenAiAdvancedFeaturesConfigDict", + "GenAiAdvancedFeaturesConfigOrDict", + "PredictRequestResponseLoggingConfig", + "PredictRequestResponseLoggingConfigDict", + "PredictRequestResponseLoggingConfigOrDict", + "PSCAutomationConfig", + "PSCAutomationConfigDict", + "PSCAutomationConfigOrDict", + "PrivateServiceConnectConfig", + "PrivateServiceConnectConfigDict", + "PrivateServiceConnectConfigOrDict", + "Endpoint", + "EndpointDict", + "EndpointOrDict", + "GetEndpointOperationConfig", + "GetEndpointOperationConfigDict", + "GetEndpointOperationConfigOrDict", + "EndpointOperation", + "EndpointOperationDict", + "EndpointOperationOrDict", "PromptOptimizerConfig", "PromptOptimizerConfigDict", "PromptOptimizerConfigOrDict", @@ -3656,9 +3933,6 @@ "ObservabilityEvalCase", "ObservabilityEvalCaseDict", "ObservabilityEvalCaseOrDict", - "RubricGroup", - "RubricGroupDict", - "RubricGroupOrDict", "PromptTemplate", "PromptTemplateDict", "PromptTemplateOrDict", @@ -3698,9 +3972,6 @@ "Prompt", "PromptDict", "PromptOrDict", - "SchemaPromptInstanceVariableValue", - "SchemaPromptInstanceVariableValueDict", - "SchemaPromptInstanceVariableValueOrDict", "CreatePromptConfig", "CreatePromptConfigDict", "CreatePromptConfigOrDict", @@ -3767,6 +4038,14 @@ "VersionState", "QuotaState", "FeedbackType", + "Encoding", + "ColorMap", + "OverlayType", + "Polarity", + "DataFormat", + "Modality", + "DeploymentType", + "PscAutomationState", "EvaluationExperimentMergeStrategy", "EvaluationItemType", "SamplingMethod", @@ -3948,6 +4227,11 @@ "_GetRuntimeFeedbackContextRequestParameters", "_GetRuntimeFeedbackContextOperationParameters", "_UpdateRuntimeFeedbackContextRequestParameters", + "_UndeployModelRequestParameters", + "_PredictParameters", + "_DeleteEndpointRequestParameters", + "_GetEndpointParameters", + "_GetEndpointOperationParameters", "evals", "agent_engines", "prompts", diff --git a/agentplatform/_genai/types/common.py b/agentplatform/_genai/types/common.py index b0343429c1..c10685596d 100644 --- a/agentplatform/_genai/types/common.py +++ b/agentplatform/_genai/types/common.py @@ -498,6 +498,116 @@ class FeedbackType(_common.CaseInSensitiveEnum): """Indicates a thumbs down feedback (e.g., a "thumbs down").""" +class Encoding(_common.CaseInSensitiveEnum): + """Defines how the feature is encoded into the input tensor. Defaults to IDENTITY.""" + + ENCODING_UNSPECIFIED = "ENCODING_UNSPECIFIED" + """Default value. This is the same as IDENTITY.""" + IDENTITY = "IDENTITY" + """The tensor represents one feature.""" + BAG_OF_FEATURES = "BAG_OF_FEATURES" + """The tensor represents a bag of features where each index maps to a feature. InputMetadata.index_feature_mapping must be provided for this encoding. For example: ``` input = [27, 6.0, 150] index_feature_mapping = ["age", "height", "weight"] ```""" + BAG_OF_FEATURES_SPARSE = "BAG_OF_FEATURES_SPARSE" + """The tensor represents a bag of features where each index maps to a feature. Zero values in the tensor indicates feature being non-existent. InputMetadata.index_feature_mapping must be provided for this encoding. For example: ``` input = [2, 0, 5, 0, 1] index_feature_mapping = ["a", "b", "c", "d", "e"] ```""" + INDICATOR = "INDICATOR" + """The tensor is a list of binaries representing whether a feature exists or not (1 indicates existence). InputMetadata.index_feature_mapping must be provided for this encoding. For example: ``` input = [1, 0, 1, 0, 1] index_feature_mapping = ["a", "b", "c", "d", "e"] ```""" + COMBINED_EMBEDDING = "COMBINED_EMBEDDING" + """The tensor is encoded into a 1-dimensional array represented by an encoded tensor. InputMetadata.encoded_tensor_name must be provided for this encoding. For example: ``` input = ["This", "is", "a", "test", "."] encoded = [0.1, 0.2, 0.3, 0.4, 0.5] ```""" + CONCAT_EMBEDDING = "CONCAT_EMBEDDING" + """Select this encoding when the input tensor is encoded into a 2-dimensional array represented by an encoded tensor. InputMetadata.encoded_tensor_name must be provided for this encoding. The first dimension of the encoded tensor's shape is the same as the input tensor's shape. For example: ``` input = ["This", "is", "a", "test", "."] encoded = [[0.1, 0.2, 0.3, 0.4, 0.5], [0.2, 0.1, 0.4, 0.3, 0.5], [0.5, 0.1, 0.3, 0.5, 0.4], [0.5, 0.3, 0.1, 0.2, 0.4], [0.4, 0.3, 0.2, 0.5, 0.1]] ```""" + + +class ColorMap(_common.CaseInSensitiveEnum): + """The color scheme used for the highlighted areas. Defaults to PINK_GREEN for Integrated Gradients attribution, which shows positive attributions in green and negative in pink. Defaults to VIRIDIS for XRAI attribution, which highlights the most influential regions in yellow and the least influential in blue.""" + + COLOR_MAP_UNSPECIFIED = "COLOR_MAP_UNSPECIFIED" + """Should not be used.""" + PINK_GREEN = "PINK_GREEN" + """Positive: green. Negative: pink.""" + VIRIDIS = "VIRIDIS" + """Viridis color map: A perceptually uniform color mapping which is easier to see by those with colorblindness and progresses from yellow to green to blue. Positive: yellow. Negative: blue.""" + RED = "RED" + """Positive: red. Negative: red.""" + GREEN = "GREEN" + """Positive: green. Negative: green.""" + RED_GREEN = "RED_GREEN" + """Positive: green. Negative: red.""" + PINK_WHITE_GREEN = "PINK_WHITE_GREEN" + """PiYG palette.""" + + +class OverlayType(_common.CaseInSensitiveEnum): + """How the original image is displayed in the visualization. Adjusting the overlay can help increase visual clarity if the original image makes it difficult to view the visualization. Defaults to NONE.""" + + OVERLAY_TYPE_UNSPECIFIED = "OVERLAY_TYPE_UNSPECIFIED" + """Default value. This is the same as NONE.""" + NONE = "NONE" + """No overlay.""" + ORIGINAL = "ORIGINAL" + """The attributions are shown on top of the original image.""" + GRAYSCALE = "GRAYSCALE" + """The attributions are shown on top of grayscaled version of the original image.""" + MASK_BLACK = "MASK_BLACK" + """The attributions are used as a mask to reveal predictive parts of the image and hide the un-predictive parts.""" + + +class Polarity(_common.CaseInSensitiveEnum): + """Whether to only highlight pixels with positive contributions, negative or both. Defaults to POSITIVE.""" + + POLARITY_UNSPECIFIED = "POLARITY_UNSPECIFIED" + """Default value. This is the same as POSITIVE.""" + POSITIVE = "POSITIVE" + """Highlights the pixels/outlines that were most influential to the model's prediction.""" + NEGATIVE = "NEGATIVE" + """Setting polarity to negative highlights areas that does not lead to the models's current prediction.""" + BOTH = "BOTH" + """Shows both positive and negative attributions.""" + + +class DataFormat(_common.CaseInSensitiveEnum): + """The format in which instances are given, if not specified, assume it's JSONL format. Currently only JSONL format is supported.""" + + DATA_FORMAT_UNSPECIFIED = "DATA_FORMAT_UNSPECIFIED" + """Format unspecified, used when unset.""" + JSONL = "JSONL" + """Examples are stored in JSONL files.""" + + +class Modality(_common.CaseInSensitiveEnum): + """The modality of the uploaded model, which automatically configures the distance measurement and feature normalization for the underlying example index and queries. If your model does not precisely fit one of these types, it is okay to choose the closest type.""" + + MODALITY_UNSPECIFIED = "MODALITY_UNSPECIFIED" + """Should not be set. Added as a recommended best practice for enums""" + IMAGE = "IMAGE" + """IMAGE modality""" + TEXT = "TEXT" + """TEXT modality""" + TABULAR = "TABULAR" + """TABULAR modality""" + + +class DeploymentType(_common.CaseInSensitiveEnum): + """The kind of deployment.""" + + DEPLOYMENT_TYPE_UNSPECIFIED = "DEPLOYMENT_TYPE_UNSPECIFIED" + """Unspecified deployment type.""" + DEPLOYMENT_TYPE_EVAL = "DEPLOYMENT_TYPE_EVAL" + """Eval deployment type.""" + DEPLOYMENT_TYPE_PROD = "DEPLOYMENT_TYPE_PROD" + """Prod deployment type.""" + + +class PscAutomationState(_common.CaseInSensitiveEnum): + """Output only. The state of the PSC service automation.""" + + PSC_AUTOMATION_STATE_UNSPECIFIED = "PSC_AUTOMATION_STATE_UNSPECIFIED" + """Should not be used.""" + PSC_AUTOMATION_STATE_SUCCESSFUL = "PSC_AUTOMATION_STATE_SUCCESSFUL" + """The PSC service automation is successful.""" + PSC_AUTOMATION_STATE_FAILED = "PSC_AUTOMATION_STATE_FAILED" + """The PSC service automation has failed.""" + + class EvaluationExperimentMergeStrategy(_common.CaseInSensitiveEnum): """Merge strategy for the evaluation experiment.""" @@ -1785,6 +1895,49 @@ class CandidateResponseDict(TypedDict, total=False): CandidateResponseOrDict = Union[CandidateResponse, CandidateResponseDict] +class RubricGroup(_common.BaseModel): + """A group of rubrics. + + Used for grouping rubrics based on a metric or a version. + """ + + group_id: Optional[str] = Field( + default=None, description="""Unique identifier for the group.""" + ) + display_name: Optional[str] = Field( + default=None, + description="""Human-readable name for the group. This should be unique + within a given context if used for display or selection. + Example: "Instruction Following V1", "Content Quality - Summarization + Task".""", + ) + rubrics: Optional[list[evals_types.Rubric]] = Field( + default=None, description="""Rubrics that are part of this group.""" + ) + + +class RubricGroupDict(TypedDict, total=False): + """A group of rubrics. + + Used for grouping rubrics based on a metric or a version. + """ + + group_id: Optional[str] + """Unique identifier for the group.""" + + display_name: Optional[str] + """Human-readable name for the group. This should be unique + within a given context if used for display or selection. + Example: "Instruction Following V1", "Content Quality - Summarization + Task".""" + + rubrics: Optional[list[evals_types.Rubric]] + """Rubrics that are part of this group.""" + + +RubricGroupOrDict = Union[RubricGroup, RubricGroupDict] + + class EvaluationItemRequest(_common.BaseModel): """Single evaluation request.""" @@ -1794,7 +1947,7 @@ class EvaluationItemRequest(_common.BaseModel): golden_response: Optional[CandidateResponse] = Field( default=None, description="""The ideal response or ground truth.""" ) - rubrics: Optional[dict[str, "RubricGroup"]] = Field( + rubrics: Optional[dict[str, RubricGroup]] = Field( default=None, description="""Named groups of rubrics associated with this prompt. The key is a user-defined name for the rubric group.""", ) @@ -1813,7 +1966,7 @@ class EvaluationItemRequestDict(TypedDict, total=False): golden_response: Optional[CandidateResponseDict] """The ideal response or ground truth.""" - rubrics: Optional[dict[str, "RubricGroupDict"]] + rubrics: Optional[dict[str, RubricGroupDict]] """Named groups of rubrics associated with this prompt. The key is a user-defined name for the rubric group.""" candidate_responses: Optional[list[CandidateResponseDict]] @@ -3619,7 +3772,7 @@ class EvalCase(_common.BaseModel): default=None, description="""List of all prior messages in the conversation (chat history).""", ) - rubric_groups: Optional[dict[str, "RubricGroup"]] = Field( + rubric_groups: Optional[dict[str, RubricGroup]] = Field( default=None, description="""Named groups of rubrics associated with this prompt. The key is a user-defined name for the rubric group.""", ) @@ -3666,7 +3819,7 @@ class EvalCaseDict(TypedDict, total=False): conversation_history: Optional[list[evals_types.Message]] """List of all prior messages in the conversation (chat history).""" - rubric_groups: Optional[dict[str, "RubricGroupDict"]] + rubric_groups: Optional[dict[str, RubricGroupDict]] """Named groups of rubrics associated with this prompt. The key is a user-defined name for the rubric group.""" eval_case_id: Optional[str] @@ -4907,7 +5060,7 @@ class EvaluationInstance(_common.BaseModel): agent_data: Optional[evals_types.AgentData] = Field( default=None, description="""Data used for agent evaluation.""" ) - rubric_groups: Optional[dict[str, "RubricGroup"]] = Field( + rubric_groups: Optional[dict[str, RubricGroup]] = Field( default=None, description="""Named groups of rubrics associated with this prompt. The key is a user-defined name for the rubric group.""", ) @@ -4938,7 +5091,7 @@ class EvaluationInstanceDict(TypedDict, total=False): agent_data: Optional[evals_types.AgentData] """Data used for agent evaluation.""" - rubric_groups: Optional[dict[str, "RubricGroupDict"]] + rubric_groups: Optional[dict[str, RubricGroupDict]] """Named groups of rubrics associated with this prompt. The key is a user-defined name for the rubric group.""" interactions_data_source: Optional[InteractionsDataSourceDict] @@ -20271,10 +20424,50 @@ class SchemaPredictParamsGroundingConfigDict(TypedDict, total=False): ] +class SchemaPromptSpecPartList(_common.BaseModel): + """Represents a prompt spec part list.""" + + parts: Optional[list[genai_types.Part]] = Field( + default=None, description="""A list of elements that can be part of a prompt.""" + ) + + +class SchemaPromptSpecPartListDict(TypedDict, total=False): + """Represents a prompt spec part list.""" + + parts: Optional[list[genai_types.Part]] + """A list of elements that can be part of a prompt.""" + + +SchemaPromptSpecPartListOrDict = Union[ + SchemaPromptSpecPartList, SchemaPromptSpecPartListDict +] + + +class SchemaPromptInstanceVariableValue(_common.BaseModel): + """Represents a prompt instance variable.""" + + part_list: Optional[SchemaPromptSpecPartList] = Field( + default=None, description="""The parts of the variable value.""" + ) + + +class SchemaPromptInstanceVariableValueDict(TypedDict, total=False): + """Represents a prompt instance variable.""" + + part_list: Optional[SchemaPromptSpecPartListDict] + """The parts of the variable value.""" + + +SchemaPromptInstanceVariableValueOrDict = Union[ + SchemaPromptInstanceVariableValue, SchemaPromptInstanceVariableValueDict +] + + class SchemaPromptInstancePromptExecution(_common.BaseModel): """A prompt instance's parameters set that contains a set of variable values.""" - arguments: Optional[dict[str, "SchemaPromptInstanceVariableValue"]] = Field( + arguments: Optional[dict[str, SchemaPromptInstanceVariableValue]] = Field( default=None, description="""Maps variable names to their value.""" ) @@ -20282,7 +20475,7 @@ class SchemaPromptInstancePromptExecution(_common.BaseModel): class SchemaPromptInstancePromptExecutionDict(TypedDict, total=False): """A prompt instance's parameters set that contains a set of variable values.""" - arguments: Optional[dict[str, "SchemaPromptInstanceVariableValueDict"]] + arguments: Optional[dict[str, SchemaPromptInstanceVariableValueDict]] """Maps variable names to their value.""" @@ -20449,26 +20642,6 @@ class SchemaPromptSpecAppBuilderDataDict(TypedDict, total=False): ] -class SchemaPromptSpecPartList(_common.BaseModel): - """Represents a prompt spec part list.""" - - parts: Optional[list[genai_types.Part]] = Field( - default=None, description="""A list of elements that can be part of a prompt.""" - ) - - -class SchemaPromptSpecPartListDict(TypedDict, total=False): - """Represents a prompt spec part list.""" - - parts: Optional[list[genai_types.Part]] - """A list of elements that can be part of a prompt.""" - - -SchemaPromptSpecPartListOrDict = Union[ - SchemaPromptSpecPartList, SchemaPromptSpecPartListDict -] - - class SchemaPromptSpecInteractionData(_common.BaseModel): """Defines data for an interaction prompt.""" @@ -25479,166 +25652,2077 @@ class _UpdateRuntimeFeedbackContextRequestParametersDict(TypedDict, total=False) ] -class PromptOptimizerConfig(_common.BaseModel): - """VAPO Prompt Optimizer Config.""" +class UndeployModelConfig(_common.BaseModel): + """Config for a Vertex SDK undeploy model from endpoint.""" - config_path: Optional[str] = Field( - default=None, - description="""The gcs path to the config file, e.g. gs://bucket/config.json.""", - ) - service_account: Optional[str] = Field( - default=None, - description="""The service account to use for the custom job. Cannot be provided at the same time as service_account_project_number.""", - ) - service_account_project_number: Optional[Union[int, str]] = Field( - default=None, - description="""The project number used to construct the default service account:{service_account_project_number}-compute@developer.gserviceaccount.comCannot be provided at the same time as "service_account".""", + http_options: Optional[genai_types.HttpOptions] = Field( + default=None, description="""Used to override HTTP request options.""" ) + traffic_split: Optional[dict[str, int]] = Field(default=None, description="""""") wait_for_completion: Optional[bool] = Field( default=True, - description="""Whether to wait for the job tocomplete. Ignored for async jobs.""", - ) - optimizer_job_display_name: Optional[str] = Field( - default=None, - description="""The display name of the optimization job. If not provided, a display name in the format of "vapo-optimizer-{timestamp}" will be used.""", + description="""Whether to wait for the long running operation to complete.""", ) -class PromptOptimizerConfigDict(TypedDict, total=False): - """VAPO Prompt Optimizer Config.""" - - config_path: Optional[str] - """The gcs path to the config file, e.g. gs://bucket/config.json.""" +class UndeployModelConfigDict(TypedDict, total=False): + """Config for a Vertex SDK undeploy model from endpoint.""" - service_account: Optional[str] - """The service account to use for the custom job. Cannot be provided at the same time as service_account_project_number.""" + http_options: Optional[genai_types.HttpOptions] + """Used to override HTTP request options.""" - service_account_project_number: Optional[Union[int, str]] - """The project number used to construct the default service account:{service_account_project_number}-compute@developer.gserviceaccount.comCannot be provided at the same time as "service_account".""" + traffic_split: Optional[dict[str, int]] + """""" wait_for_completion: Optional[bool] - """Whether to wait for the job tocomplete. Ignored for async jobs.""" - - optimizer_job_display_name: Optional[str] - """The display name of the optimization job. If not provided, a display name in the format of "vapo-optimizer-{timestamp}" will be used.""" + """Whether to wait for the long running operation to complete.""" -PromptOptimizerConfigOrDict = Union[PromptOptimizerConfig, PromptOptimizerConfigDict] +UndeployModelConfigOrDict = Union[UndeployModelConfig, UndeployModelConfigDict] -class OptimizeResponse(_common.BaseModel): - """Response for the optimize_prompt method.""" +class _UndeployModelRequestParameters(_common.BaseModel): + """Parameters for undeploying a model from an endpoint.""" - raw_text_response: Optional[str] = Field(default=None, description="""""") - parsed_response: Optional["ParsedResponseUnion"] = Field( - default=None, description="""""" + name: Optional[str] = Field( + default=None, description="""ID of the endpoint to undeploy the model from.""" ) + deployed_model_id: Optional[str] = Field( + default=None, description="""ID of the deployed model to be undeployed.""" + ) + config: Optional[UndeployModelConfig] = Field(default=None, description="""""") -class OptimizeResponseDict(TypedDict, total=False): - """Response for the optimize_prompt method.""" +class _UndeployModelRequestParametersDict(TypedDict, total=False): + """Parameters for undeploying a model from an endpoint.""" - raw_text_response: Optional[str] - """""" + name: Optional[str] + """ID of the endpoint to undeploy the model from.""" - parsed_response: Optional["ParsedResponseUnionDict"] + deployed_model_id: Optional[str] + """ID of the deployed model to be undeployed.""" + + config: Optional[UndeployModelConfigDict] """""" -OptimizeResponseOrDict = Union[OptimizeResponse, OptimizeResponseDict] +_UndeployModelRequestParametersOrDict = Union[ + _UndeployModelRequestParameters, _UndeployModelRequestParametersDict +] -class ContentMapContents(_common.BaseModel): - """Map of placeholder in metric prompt template to contents of model input.""" +class UndeployModelOperation(_common.BaseModel): + """Operation for undeploying a model.""" - contents: Optional[list[genai_types.Content]] = Field( - default=None, description="""Contents of the model input.""" + name: Optional[str] = Field( + default=None, + description="""The server-assigned name, which is only unique within the same service that originally returns it. If you use the default HTTP mapping, the `name` should be a resource name ending with `operations/{unique_id}`.""", + ) + metadata: Optional[dict[str, Any]] = Field( + default=None, + description="""Service-specific metadata associated with the operation. It typically contains progress information and common metadata such as create time. Some services might not provide such metadata. Any method that returns a long-running operation should document the metadata type, if any.""", + ) + done: Optional[bool] = Field( + default=None, + description="""If the value is `false`, it means the operation is still in progress. If `true`, the operation is completed, and either `error` or `response` is available.""", + ) + error: Optional[dict[str, Any]] = Field( + default=None, + description="""The error result of the operation in case of failure or cancellation.""", ) -class ContentMapContentsDict(TypedDict, total=False): - """Map of placeholder in metric prompt template to contents of model input.""" +class UndeployModelOperationDict(TypedDict, total=False): + """Operation for undeploying a model.""" - contents: Optional[list[genai_types.Content]] - """Contents of the model input.""" + name: Optional[str] + """The server-assigned name, which is only unique within the same service that originally returns it. If you use the default HTTP mapping, the `name` should be a resource name ending with `operations/{unique_id}`.""" + metadata: Optional[dict[str, Any]] + """Service-specific metadata associated with the operation. It typically contains progress information and common metadata such as create time. Some services might not provide such metadata. Any method that returns a long-running operation should document the metadata type, if any.""" -ContentMapContentsOrDict = Union[ContentMapContents, ContentMapContentsDict] + done: Optional[bool] + """If the value is `false`, it means the operation is still in progress. If `true`, the operation is completed, and either `error` or `response` is available.""" + error: Optional[dict[str, Any]] + """The error result of the operation in case of failure or cancellation.""" -class EvaluateMethodConfig(_common.BaseModel): - """Optional parameters for the evaluate method.""" + +UndeployModelOperationOrDict = Union[UndeployModelOperation, UndeployModelOperationDict] + + +class PredictConfig(_common.BaseModel): + """Config for a Vertex SDK predict endpoint.""" http_options: Optional[genai_types.HttpOptions] = Field( default=None, description="""Used to override HTTP request options.""" ) - dataset_schema: Optional[Literal["GEMINI", "FLATTEN", "OPENAI"]] = Field( - default=None, - description="""The schema to use for the dataset. - If not specified, the dataset schema will be inferred from the first - example in the dataset.""", - ) - dest: Optional[str] = Field( - default=None, description="""The destination path for the evaluation results.""" - ) - evaluation_service_qps: Optional[float] = Field( + parameters: Optional[str] = Field( default=None, - description="""The rate limit (queries per second) for calls to the - evaluation service. Defaults to 10. Increase this value if your - project has a higher EvaluateInstances API quota.""", + description="""The parameters that govern the prediction. The schema of the + parameters may be specified via Endpoint's DeployedModels' [Model's ][ + DeployedModel.model] [PredictSchemata's][Model.predict_schemata] + [parameters_schema_uri][PredictSchemata.parameters_schema_uri]. + """, ) -class EvaluateMethodConfigDict(TypedDict, total=False): - """Optional parameters for the evaluate method.""" +class PredictConfigDict(TypedDict, total=False): + """Config for a Vertex SDK predict endpoint.""" http_options: Optional[genai_types.HttpOptions] """Used to override HTTP request options.""" - dataset_schema: Optional[Literal["GEMINI", "FLATTEN", "OPENAI"]] - """The schema to use for the dataset. - If not specified, the dataset schema will be inferred from the first - example in the dataset.""" + parameters: Optional[str] + """The parameters that govern the prediction. The schema of the + parameters may be specified via Endpoint's DeployedModels' [Model's ][ + DeployedModel.model] [PredictSchemata's][Model.predict_schemata] + [parameters_schema_uri][PredictSchemata.parameters_schema_uri]. + """ - dest: Optional[str] - """The destination path for the evaluation results.""" - evaluation_service_qps: Optional[float] - """The rate limit (queries per second) for calls to the - evaluation service. Defaults to 10. Increase this value if your - project has a higher EvaluateInstances API quota.""" +PredictConfigOrDict = Union[PredictConfig, PredictConfigDict] -EvaluateMethodConfigOrDict = Union[EvaluateMethodConfig, EvaluateMethodConfigDict] +class _PredictParameters(_common.BaseModel): + """Parameters for deleting a multimodal dataset.""" + instances: Optional[list[dict[str, Any]]] = Field( + default=None, + description="""The instances that are the input to the prediction call. The + schema of any single instance may be specified via Endpoint's DeployedModels' + [Model's ][DeployedModel.model] [PredictSchemata's][Model.predict_schemata] + [instance_schema_uri][PredictSchemata.instance_schema_uri]. + """, + ) + config: Optional[PredictConfig] = Field(default=None, description="""""") + name: Optional[str] = Field( + default=None, + description="""The endpoint that serves the prediction. It could be endpoints/... + or publisher/.../models/... + """, + ) -class EvaluateDatasetConfig(_common.BaseModel): - """Config for evaluate instances.""" - http_options: Optional[genai_types.HttpOptions] = Field( - default=None, description="""Used to override HTTP request options.""" - ) +class _PredictParametersDict(TypedDict, total=False): + """Parameters for deleting a multimodal dataset.""" + instances: Optional[list[dict[str, Any]]] + """The instances that are the input to the prediction call. The + schema of any single instance may be specified via Endpoint's DeployedModels' + [Model's ][DeployedModel.model] [PredictSchemata's][Model.predict_schemata] + [instance_schema_uri][PredictSchemata.instance_schema_uri]. + """ -class EvaluateDatasetConfigDict(TypedDict, total=False): - """Config for evaluate instances.""" + config: Optional[PredictConfigDict] + """""" - http_options: Optional[genai_types.HttpOptions] - """Used to override HTTP request options.""" + name: Optional[str] + """The endpoint that serves the prediction. It could be endpoints/... + or publisher/.../models/... + """ -EvaluateDatasetConfigOrDict = Union[EvaluateDatasetConfig, EvaluateDatasetConfigDict] +_PredictParametersOrDict = Union[_PredictParameters, _PredictParametersDict] -class EvaluateDatasetOperation(_common.BaseModel): +class PredictResponse(_common.BaseModel): + """Response message for PredictionService.Predict API.""" - name: Optional[str] = Field( + deployed_model_id: Optional[str] = Field( default=None, - description="""The server-assigned name, which is only unique within the same service that originally returns it. If you use the default HTTP mapping, the `name` should be a resource name ending with `operations/{unique_id}`.""", + description="""ID of the Endpoint's DeployedModel that served this prediction.""", ) - metadata: Optional[dict[str, Any]] = Field( + metadata: Optional[Any] = Field( default=None, - description="""Service-specific metadata associated with the operation. It typically contains progress information and common metadata such as create time. Some services might not provide such metadata. Any method that returns a long-running operation should document the metadata type, if any.""", + description="""Output only. Request-level metadata returned by the model. The metadata type will be dependent upon the model implementation.""", + ) + model: Optional[str] = Field( + default=None, + description="""Output only. The resource name of the Model which is deployed as the DeployedModel that this prediction hits.""", + ) + model_display_name: Optional[str] = Field( + default=None, + description="""Output only. The display name of the Model which is deployed as the DeployedModel that this prediction hits.""", + ) + model_version_id: Optional[str] = Field( + default=None, + description="""Output only. The version ID of the Model which is deployed as the DeployedModel that this prediction hits.""", + ) + predictions: Optional[list[Any]] = Field( + default=None, + description="""The predictions that are the output of the predictions call. The schema of any single prediction may be specified via Endpoint's DeployedModels' Model's PredictSchemata's prediction_schema_uri.""", + ) + + +class PredictResponseDict(TypedDict, total=False): + """Response message for PredictionService.Predict API.""" + + deployed_model_id: Optional[str] + """ID of the Endpoint's DeployedModel that served this prediction.""" + + metadata: Optional[Any] + """Output only. Request-level metadata returned by the model. The metadata type will be dependent upon the model implementation.""" + + model: Optional[str] + """Output only. The resource name of the Model which is deployed as the DeployedModel that this prediction hits.""" + + model_display_name: Optional[str] + """Output only. The display name of the Model which is deployed as the DeployedModel that this prediction hits.""" + + model_version_id: Optional[str] + """Output only. The version ID of the Model which is deployed as the DeployedModel that this prediction hits.""" + + predictions: Optional[list[Any]] + """The predictions that are the output of the predictions call. The schema of any single prediction may be specified via Endpoint's DeployedModels' Model's PredictSchemata's prediction_schema_uri.""" + + +PredictResponseOrDict = Union[PredictResponse, PredictResponseDict] + + +class DeleteEndpointConfig(_common.BaseModel): + """Config for a Vertex SDK delete endpoint.""" + + http_options: Optional[genai_types.HttpOptions] = Field( + default=None, description="""Used to override HTTP request options.""" + ) + wait_for_completion: Optional[bool] = Field( + default=True, + description="""Whether to wait for the long running operation to complete.""", + ) + + +class DeleteEndpointConfigDict(TypedDict, total=False): + """Config for a Vertex SDK delete endpoint.""" + + http_options: Optional[genai_types.HttpOptions] + """Used to override HTTP request options.""" + + wait_for_completion: Optional[bool] + """Whether to wait for the long running operation to complete.""" + + +DeleteEndpointConfigOrDict = Union[DeleteEndpointConfig, DeleteEndpointConfigDict] + + +class _DeleteEndpointRequestParameters(_common.BaseModel): + """Parameters for deleting an endpoint.""" + + name: Optional[str] = Field( + default=None, + description="""Required. The resource name of the endpoint to be deleted.""", + ) + config: Optional[DeleteEndpointConfig] = Field(default=None, description="""""") + + +class _DeleteEndpointRequestParametersDict(TypedDict, total=False): + """Parameters for deleting an endpoint.""" + + name: Optional[str] + """Required. The resource name of the endpoint to be deleted.""" + + config: Optional[DeleteEndpointConfigDict] + """""" + + +_DeleteEndpointRequestParametersOrDict = Union[ + _DeleteEndpointRequestParameters, _DeleteEndpointRequestParametersDict +] + + +class DeleteEndpointOperation(_common.BaseModel): + """Operation for deleting a endpoint.""" + + name: Optional[str] = Field( + default=None, + description="""The server-assigned name, which is only unique within the same service that originally returns it. If you use the default HTTP mapping, the `name` should be a resource name ending with `operations/{unique_id}`.""", + ) + metadata: Optional[dict[str, Any]] = Field( + default=None, + description="""Service-specific metadata associated with the operation. It typically contains progress information and common metadata such as create time. Some services might not provide such metadata. Any method that returns a long-running operation should document the metadata type, if any.""", + ) + done: Optional[bool] = Field( + default=None, + description="""If the value is `false`, it means the operation is still in progress. If `true`, the operation is completed, and either `error` or `response` is available.""", + ) + error: Optional[dict[str, Any]] = Field( + default=None, + description="""The error result of the operation in case of failure or cancellation.""", + ) + + +class DeleteEndpointOperationDict(TypedDict, total=False): + """Operation for deleting a endpoint.""" + + name: Optional[str] + """The server-assigned name, which is only unique within the same service that originally returns it. If you use the default HTTP mapping, the `name` should be a resource name ending with `operations/{unique_id}`.""" + + metadata: Optional[dict[str, Any]] + """Service-specific metadata associated with the operation. It typically contains progress information and common metadata such as create time. Some services might not provide such metadata. Any method that returns a long-running operation should document the metadata type, if any.""" + + done: Optional[bool] + """If the value is `false`, it means the operation is still in progress. If `true`, the operation is completed, and either `error` or `response` is available.""" + + error: Optional[dict[str, Any]] + """The error result of the operation in case of failure or cancellation.""" + + +DeleteEndpointOperationOrDict = Union[ + DeleteEndpointOperation, DeleteEndpointOperationDict +] + + +class GetEndpointConfig(_common.BaseModel): + """Optional parameters for endpoints.get method.""" + + http_options: Optional[genai_types.HttpOptions] = Field( + default=None, description="""Used to override HTTP request options.""" + ) + + +class GetEndpointConfigDict(TypedDict, total=False): + """Optional parameters for endpoints.get method.""" + + http_options: Optional[genai_types.HttpOptions] + """Used to override HTTP request options.""" + + +GetEndpointConfigOrDict = Union[GetEndpointConfig, GetEndpointConfigDict] + + +class _GetEndpointParameters(_common.BaseModel): + + name: Optional[str] = Field( + default=None, + description="""Required. The resource name of the Endpoint to get.""", + ) + config: Optional[GetEndpointConfig] = Field( + default=None, description="""Optional parameters for the request.""" + ) + + +class _GetEndpointParametersDict(TypedDict, total=False): + + name: Optional[str] + """Required. The resource name of the Endpoint to get.""" + + config: Optional[GetEndpointConfigDict] + """Optional parameters for the request.""" + + +_GetEndpointParametersOrDict = Union[_GetEndpointParameters, _GetEndpointParametersDict] + + +class ExplanationMetadataInputMetadataFeatureValueDomain(_common.BaseModel): + """Domain details of the input feature value. Provides numeric information about the feature, such as its range (min, max). If the feature has been pre-processed, for example with z-scoring, then it provides information about how to recover the original feature. For example, if the input feature is an image and it has been pre-processed to obtain 0-mean and stddev = 1 values, then original_mean, and original_stddev refer to the mean and stddev of the original feature (e.g. image tensor) from which input feature (with mean = 0 and stddev = 1) was obtained.""" + + max_value: Optional[float] = Field( + default=None, description="""The maximum permissible value for this feature.""" + ) + min_value: Optional[float] = Field( + default=None, description="""The minimum permissible value for this feature.""" + ) + original_mean: Optional[float] = Field( + default=None, + description="""If this input feature has been normalized to a mean value of 0, the original_mean specifies the mean value of the domain prior to normalization.""", + ) + original_stddev: Optional[float] = Field( + default=None, + description="""If this input feature has been normalized to a standard deviation of 1.0, the original_stddev specifies the standard deviation of the domain prior to normalization.""", + ) + + +class ExplanationMetadataInputMetadataFeatureValueDomainDict(TypedDict, total=False): + """Domain details of the input feature value. Provides numeric information about the feature, such as its range (min, max). If the feature has been pre-processed, for example with z-scoring, then it provides information about how to recover the original feature. For example, if the input feature is an image and it has been pre-processed to obtain 0-mean and stddev = 1 values, then original_mean, and original_stddev refer to the mean and stddev of the original feature (e.g. image tensor) from which input feature (with mean = 0 and stddev = 1) was obtained.""" + + max_value: Optional[float] + """The maximum permissible value for this feature.""" + + min_value: Optional[float] + """The minimum permissible value for this feature.""" + + original_mean: Optional[float] + """If this input feature has been normalized to a mean value of 0, the original_mean specifies the mean value of the domain prior to normalization.""" + + original_stddev: Optional[float] + """If this input feature has been normalized to a standard deviation of 1.0, the original_stddev specifies the standard deviation of the domain prior to normalization.""" + + +ExplanationMetadataInputMetadataFeatureValueDomainOrDict = Union[ + ExplanationMetadataInputMetadataFeatureValueDomain, + ExplanationMetadataInputMetadataFeatureValueDomainDict, +] + + +class ExplanationMetadataInputMetadataVisualization(_common.BaseModel): + """Visualization configurations for image explanation.""" + + clip_percent_lowerbound: Optional[float] = Field( + default=None, + description="""Excludes attributions below the specified percentile, from the highlighted areas. Defaults to 62.""", + ) + clip_percent_upperbound: Optional[float] = Field( + default=None, + description="""Excludes attributions above the specified percentile from the highlighted areas. Using the clip_percent_upperbound and clip_percent_lowerbound together can be useful for filtering out noise and making it easier to see areas of strong attribution. Defaults to 99.9.""", + ) + color_map: Optional[ColorMap] = Field( + default=None, + description="""The color scheme used for the highlighted areas. Defaults to PINK_GREEN for Integrated Gradients attribution, which shows positive attributions in green and negative in pink. Defaults to VIRIDIS for XRAI attribution, which highlights the most influential regions in yellow and the least influential in blue.""", + ) + overlay_type: Optional[OverlayType] = Field( + default=None, + description="""How the original image is displayed in the visualization. Adjusting the overlay can help increase visual clarity if the original image makes it difficult to view the visualization. Defaults to NONE.""", + ) + polarity: Optional[Polarity] = Field( + default=None, + description="""Whether to only highlight pixels with positive contributions, negative or both. Defaults to POSITIVE.""", + ) + type: Optional[Type] = Field( + default=None, + description="""Type of the image visualization. Only applicable to Integrated Gradients attribution. OUTLINES shows regions of attribution, while PIXELS shows per-pixel attribution. Defaults to OUTLINES.""", + ) + + +class ExplanationMetadataInputMetadataVisualizationDict(TypedDict, total=False): + """Visualization configurations for image explanation.""" + + clip_percent_lowerbound: Optional[float] + """Excludes attributions below the specified percentile, from the highlighted areas. Defaults to 62.""" + + clip_percent_upperbound: Optional[float] + """Excludes attributions above the specified percentile from the highlighted areas. Using the clip_percent_upperbound and clip_percent_lowerbound together can be useful for filtering out noise and making it easier to see areas of strong attribution. Defaults to 99.9.""" + + color_map: Optional[ColorMap] + """The color scheme used for the highlighted areas. Defaults to PINK_GREEN for Integrated Gradients attribution, which shows positive attributions in green and negative in pink. Defaults to VIRIDIS for XRAI attribution, which highlights the most influential regions in yellow and the least influential in blue.""" + + overlay_type: Optional[OverlayType] + """How the original image is displayed in the visualization. Adjusting the overlay can help increase visual clarity if the original image makes it difficult to view the visualization. Defaults to NONE.""" + + polarity: Optional[Polarity] + """Whether to only highlight pixels with positive contributions, negative or both. Defaults to POSITIVE.""" + + type: Optional[Type] + """Type of the image visualization. Only applicable to Integrated Gradients attribution. OUTLINES shows regions of attribution, while PIXELS shows per-pixel attribution. Defaults to OUTLINES.""" + + +ExplanationMetadataInputMetadataVisualizationOrDict = Union[ + ExplanationMetadataInputMetadataVisualization, + ExplanationMetadataInputMetadataVisualizationDict, +] + + +class ExplanationMetadataInputMetadata(_common.BaseModel): + """Metadata of the input of a feature. Fields other than InputMetadata.input_baselines are applicable only for Models that are using Vertex AI-provided images for Tensorflow.""" + + dense_shape_tensor_name: Optional[str] = Field( + default=None, + description="""Specifies the shape of the values of the input if the input is a sparse representation. Refer to Tensorflow documentation for more details: https://www.tensorflow.org/api_docs/python/tf/sparse/SparseTensor.""", + ) + encoded_baselines: Optional[list[Any]] = Field( + default=None, + description="""A list of baselines for the encoded tensor. The shape of each baseline should match the shape of the encoded tensor. If a scalar is provided, Vertex AI broadcasts to the same shape as the encoded tensor.""", + ) + encoded_tensor_name: Optional[str] = Field( + default=None, + description="""Encoded tensor is a transformation of the input tensor. Must be provided if choosing Integrated Gradients attribution or XRAI attribution and the input tensor is not differentiable. An encoded tensor is generated if the input tensor is encoded by a lookup table.""", + ) + encoding: Optional[Encoding] = Field( + default=None, + description="""Defines how the feature is encoded into the input tensor. Defaults to IDENTITY.""", + ) + feature_value_domain: Optional[ + ExplanationMetadataInputMetadataFeatureValueDomain + ] = Field( + default=None, + description="""The domain details of the input feature value. Like min/max, original mean or standard deviation if normalized.""", + ) + group_name: Optional[str] = Field( + default=None, + description="""Name of the group that the input belongs to. Features with the same group name will be treated as one feature when computing attributions. Features grouped together can have different shapes in value. If provided, there will be one single attribution generated in Attribution.feature_attributions, keyed by the group name.""", + ) + index_feature_mapping: Optional[list[str]] = Field( + default=None, + description="""A list of feature names for each index in the input tensor. Required when the input InputMetadata.encoding is BAG_OF_FEATURES, BAG_OF_FEATURES_SPARSE, INDICATOR.""", + ) + indices_tensor_name: Optional[str] = Field( + default=None, + description="""Specifies the index of the values of the input tensor. Required when the input tensor is a sparse representation. Refer to Tensorflow documentation for more details: https://www.tensorflow.org/api_docs/python/tf/sparse/SparseTensor.""", + ) + input_baselines: Optional[list[Any]] = Field( + default=None, + description="""Baseline inputs for this feature. If no baseline is specified, Vertex AI chooses the baseline for this feature. If multiple baselines are specified, Vertex AI returns the average attributions across them in Attribution.feature_attributions. For Vertex AI-provided Tensorflow images (both 1.x and 2.x), the shape of each baseline must match the shape of the input tensor. If a scalar is provided, we broadcast to the same shape as the input tensor. For custom images, the element of the baselines must be in the same format as the feature's input in the instance[]. The schema of any single instance may be specified via Endpoint's DeployedModels' Model's PredictSchemata's instance_schema_uri.""", + ) + input_tensor_name: Optional[str] = Field( + default=None, + description="""Name of the input tensor for this feature. Required and is only applicable to Vertex AI-provided images for Tensorflow.""", + ) + modality: Optional[str] = Field( + default=None, + description="""Modality of the feature. Valid values are: numeric, image. Defaults to numeric.""", + ) + visualization: Optional[ExplanationMetadataInputMetadataVisualization] = Field( + default=None, + description="""Visualization configurations for image explanation.""", + ) + + +class ExplanationMetadataInputMetadataDict(TypedDict, total=False): + """Metadata of the input of a feature. Fields other than InputMetadata.input_baselines are applicable only for Models that are using Vertex AI-provided images for Tensorflow.""" + + dense_shape_tensor_name: Optional[str] + """Specifies the shape of the values of the input if the input is a sparse representation. Refer to Tensorflow documentation for more details: https://www.tensorflow.org/api_docs/python/tf/sparse/SparseTensor.""" + + encoded_baselines: Optional[list[Any]] + """A list of baselines for the encoded tensor. The shape of each baseline should match the shape of the encoded tensor. If a scalar is provided, Vertex AI broadcasts to the same shape as the encoded tensor.""" + + encoded_tensor_name: Optional[str] + """Encoded tensor is a transformation of the input tensor. Must be provided if choosing Integrated Gradients attribution or XRAI attribution and the input tensor is not differentiable. An encoded tensor is generated if the input tensor is encoded by a lookup table.""" + + encoding: Optional[Encoding] + """Defines how the feature is encoded into the input tensor. Defaults to IDENTITY.""" + + feature_value_domain: Optional[ + ExplanationMetadataInputMetadataFeatureValueDomainDict + ] + """The domain details of the input feature value. Like min/max, original mean or standard deviation if normalized.""" + + group_name: Optional[str] + """Name of the group that the input belongs to. Features with the same group name will be treated as one feature when computing attributions. Features grouped together can have different shapes in value. If provided, there will be one single attribution generated in Attribution.feature_attributions, keyed by the group name.""" + + index_feature_mapping: Optional[list[str]] + """A list of feature names for each index in the input tensor. Required when the input InputMetadata.encoding is BAG_OF_FEATURES, BAG_OF_FEATURES_SPARSE, INDICATOR.""" + + indices_tensor_name: Optional[str] + """Specifies the index of the values of the input tensor. Required when the input tensor is a sparse representation. Refer to Tensorflow documentation for more details: https://www.tensorflow.org/api_docs/python/tf/sparse/SparseTensor.""" + + input_baselines: Optional[list[Any]] + """Baseline inputs for this feature. If no baseline is specified, Vertex AI chooses the baseline for this feature. If multiple baselines are specified, Vertex AI returns the average attributions across them in Attribution.feature_attributions. For Vertex AI-provided Tensorflow images (both 1.x and 2.x), the shape of each baseline must match the shape of the input tensor. If a scalar is provided, we broadcast to the same shape as the input tensor. For custom images, the element of the baselines must be in the same format as the feature's input in the instance[]. The schema of any single instance may be specified via Endpoint's DeployedModels' Model's PredictSchemata's instance_schema_uri.""" + + input_tensor_name: Optional[str] + """Name of the input tensor for this feature. Required and is only applicable to Vertex AI-provided images for Tensorflow.""" + + modality: Optional[str] + """Modality of the feature. Valid values are: numeric, image. Defaults to numeric.""" + + visualization: Optional[ExplanationMetadataInputMetadataVisualizationDict] + """Visualization configurations for image explanation.""" + + +ExplanationMetadataInputMetadataOrDict = Union[ + ExplanationMetadataInputMetadata, ExplanationMetadataInputMetadataDict +] + + +class ExplanationMetadataOutputMetadata(_common.BaseModel): + """Metadata of the prediction output to be explained.""" + + display_name_mapping_key: Optional[str] = Field( + default=None, + description="""Specify a field name in the prediction to look for the display name. Use this if the prediction contains the display names for the outputs. The display names in the prediction must have the same shape of the outputs, so that it can be located by Attribution.output_index for a specific output.""", + ) + index_display_name_mapping: Optional[Any] = Field( + default=None, + description="""Static mapping between the index and display name. Use this if the outputs are a deterministic n-dimensional array, e.g. a list of scores of all the classes in a pre-defined order for a multi-classification Model. It's not feasible if the outputs are non-deterministic, e.g. the Model produces top-k classes or sort the outputs by their values. The shape of the value must be an n-dimensional array of strings. The number of dimensions must match that of the outputs to be explained. The Attribution.output_display_name is populated by locating in the mapping with Attribution.output_index.""", + ) + output_tensor_name: Optional[str] = Field( + default=None, + description="""Name of the output tensor. Required and is only applicable to Vertex AI provided images for Tensorflow.""", + ) + + +class ExplanationMetadataOutputMetadataDict(TypedDict, total=False): + """Metadata of the prediction output to be explained.""" + + display_name_mapping_key: Optional[str] + """Specify a field name in the prediction to look for the display name. Use this if the prediction contains the display names for the outputs. The display names in the prediction must have the same shape of the outputs, so that it can be located by Attribution.output_index for a specific output.""" + + index_display_name_mapping: Optional[Any] + """Static mapping between the index and display name. Use this if the outputs are a deterministic n-dimensional array, e.g. a list of scores of all the classes in a pre-defined order for a multi-classification Model. It's not feasible if the outputs are non-deterministic, e.g. the Model produces top-k classes or sort the outputs by their values. The shape of the value must be an n-dimensional array of strings. The number of dimensions must match that of the outputs to be explained. The Attribution.output_display_name is populated by locating in the mapping with Attribution.output_index.""" + + output_tensor_name: Optional[str] + """Name of the output tensor. Required and is only applicable to Vertex AI provided images for Tensorflow.""" + + +ExplanationMetadataOutputMetadataOrDict = Union[ + ExplanationMetadataOutputMetadata, ExplanationMetadataOutputMetadataDict +] + + +class ExplanationMetadata(_common.BaseModel): + """Metadata describing the Model's input and output for explanation.""" + + feature_attributions_schema_uri: Optional[str] = Field( + default=None, + description="""Points to a YAML file stored on Google Cloud Storage describing the format of the feature attributions. The schema is defined as an OpenAPI 3.0.2 [Schema Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.2.md#schemaObject). AutoML tabular Models always have this field populated by Vertex AI. Note: The URI given on output may be different, including the URI scheme, than the one given on input. The output URI will point to a location where the user only has a read access.""", + ) + inputs: Optional[dict[str, ExplanationMetadataInputMetadata]] = Field( + default=None, + description="""Required. Map from feature names to feature input metadata. Keys are the name of the features. Values are the specification of the feature. An empty InputMetadata is valid. It describes a text feature which has the name specified as the key in ExplanationMetadata.inputs. The baseline of the empty feature is chosen by Vertex AI. For Vertex AI-provided Tensorflow images, the key can be any friendly name of the feature. Once specified, featureAttributions are keyed by this key (if not grouped with another feature). For custom images, the key must match with the key in instance.""", + ) + latent_space_source: Optional[str] = Field( + default=None, + description="""Name of the source to generate embeddings for example based explanations.""", + ) + outputs: Optional[dict[str, ExplanationMetadataOutputMetadata]] = Field( + default=None, + description="""Required. Map from output names to output metadata. For Vertex AI-provided Tensorflow images, keys can be any user defined string that consists of any UTF-8 characters. For custom images, keys are the name of the output field in the prediction to be explained. Currently only one key is allowed.""", + ) + + +class ExplanationMetadataDict(TypedDict, total=False): + """Metadata describing the Model's input and output for explanation.""" + + feature_attributions_schema_uri: Optional[str] + """Points to a YAML file stored on Google Cloud Storage describing the format of the feature attributions. The schema is defined as an OpenAPI 3.0.2 [Schema Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.2.md#schemaObject). AutoML tabular Models always have this field populated by Vertex AI. Note: The URI given on output may be different, including the URI scheme, than the one given on input. The output URI will point to a location where the user only has a read access.""" + + inputs: Optional[dict[str, ExplanationMetadataInputMetadataDict]] + """Required. Map from feature names to feature input metadata. Keys are the name of the features. Values are the specification of the feature. An empty InputMetadata is valid. It describes a text feature which has the name specified as the key in ExplanationMetadata.inputs. The baseline of the empty feature is chosen by Vertex AI. For Vertex AI-provided Tensorflow images, the key can be any friendly name of the feature. Once specified, featureAttributions are keyed by this key (if not grouped with another feature). For custom images, the key must match with the key in instance.""" + + latent_space_source: Optional[str] + """Name of the source to generate embeddings for example based explanations.""" + + outputs: Optional[dict[str, ExplanationMetadataOutputMetadataDict]] + """Required. Map from output names to output metadata. For Vertex AI-provided Tensorflow images, keys can be any user defined string that consists of any UTF-8 characters. For custom images, keys are the name of the output field in the prediction to be explained. Currently only one key is allowed.""" + + +ExplanationMetadataOrDict = Union[ExplanationMetadata, ExplanationMetadataDict] + + +class ExamplesExampleGcsSource(_common.BaseModel): + """The Cloud Storage input instances.""" + + data_format: Optional[DataFormat] = Field( + default=None, + description="""The format in which instances are given, if not specified, assume it's JSONL format. Currently only JSONL format is supported.""", + ) + gcs_source: Optional[genai_types.GcsSource] = Field( + default=None, + description="""The Cloud Storage location for the input instances.""", + ) + + +class ExamplesExampleGcsSourceDict(TypedDict, total=False): + """The Cloud Storage input instances.""" + + data_format: Optional[DataFormat] + """The format in which instances are given, if not specified, assume it's JSONL format. Currently only JSONL format is supported.""" + + gcs_source: Optional[genai_types.GcsSourceDict] + """The Cloud Storage location for the input instances.""" + + +ExamplesExampleGcsSourceOrDict = Union[ + ExamplesExampleGcsSource, ExamplesExampleGcsSourceDict +] + + +class Presets(_common.BaseModel): + """Preset configuration for example-based explanations""" + + modality: Optional[Modality] = Field( + default=None, + description="""The modality of the uploaded model, which automatically configures the distance measurement and feature normalization for the underlying example index and queries. If your model does not precisely fit one of these types, it is okay to choose the closest type.""", + ) + query: Optional[Literal["PRECISE", "FAST"]] = Field( + default=None, + description="""Preset option controlling parameters for speed-precision trade-off when querying for examples. If omitted, defaults to `PRECISE`.""", + ) + + +class PresetsDict(TypedDict, total=False): + """Preset configuration for example-based explanations""" + + modality: Optional[Modality] + """The modality of the uploaded model, which automatically configures the distance measurement and feature normalization for the underlying example index and queries. If your model does not precisely fit one of these types, it is okay to choose the closest type.""" + + query: Optional[Literal["PRECISE", "FAST"]] + """Preset option controlling parameters for speed-precision trade-off when querying for examples. If omitted, defaults to `PRECISE`.""" + + +PresetsOrDict = Union[Presets, PresetsDict] + + +class Examples(_common.BaseModel): + """Example-based explainability that returns the nearest neighbors from the provided dataset.""" + + example_gcs_source: Optional[ExamplesExampleGcsSource] = Field( + default=None, description="""The Cloud Storage input instances.""" + ) + gcs_source: Optional[genai_types.GcsSource] = Field( + default=None, + description="""The Cloud Storage locations that contain the instances to be indexed for approximate nearest neighbor search.""", + ) + nearest_neighbor_search_config: Optional[Any] = Field( + default=None, + description="""The full configuration for the generated index, the semantics are the same as metadata and should match [NearestNeighborSearchConfig](https://cloud.google.com/vertex-ai/docs/explainable-ai/configuring-explanations-example-based#nearest-neighbor-search-config).""", + ) + neighbor_count: Optional[int] = Field( + default=None, + description="""The number of neighbors to return when querying for examples.""", + ) + presets: Optional[Presets] = Field( + default=None, + description="""Simplified preset configuration, which automatically sets configuration values based on the desired query speed-precision trade-off and modality.""", + ) + + +class ExamplesDict(TypedDict, total=False): + """Example-based explainability that returns the nearest neighbors from the provided dataset.""" + + example_gcs_source: Optional[ExamplesExampleGcsSourceDict] + """The Cloud Storage input instances.""" + + gcs_source: Optional[genai_types.GcsSourceDict] + """The Cloud Storage locations that contain the instances to be indexed for approximate nearest neighbor search.""" + + nearest_neighbor_search_config: Optional[Any] + """The full configuration for the generated index, the semantics are the same as metadata and should match [NearestNeighborSearchConfig](https://cloud.google.com/vertex-ai/docs/explainable-ai/configuring-explanations-example-based#nearest-neighbor-search-config).""" + + neighbor_count: Optional[int] + """The number of neighbors to return when querying for examples.""" + + presets: Optional[PresetsDict] + """Simplified preset configuration, which automatically sets configuration values based on the desired query speed-precision trade-off and modality.""" + + +ExamplesOrDict = Union[Examples, ExamplesDict] + + +class BlurBaselineConfig(_common.BaseModel): + """Config for blur baseline. When enabled, a linear path from the maximally blurred image to the input image is created. Using a blurred baseline instead of zero (black image) is motivated by the BlurIG approach explained here: https://arxiv.org/abs/2004.03383""" + + max_blur_sigma: Optional[float] = Field( + default=None, + description="""The standard deviation of the blur kernel for the blurred baseline. The same blurring parameter is used for both the height and the width dimension. If not set, the method defaults to the zero (i.e. black for images) baseline.""", + ) + + +class BlurBaselineConfigDict(TypedDict, total=False): + """Config for blur baseline. When enabled, a linear path from the maximally blurred image to the input image is created. Using a blurred baseline instead of zero (black image) is motivated by the BlurIG approach explained here: https://arxiv.org/abs/2004.03383""" + + max_blur_sigma: Optional[float] + """The standard deviation of the blur kernel for the blurred baseline. The same blurring parameter is used for both the height and the width dimension. If not set, the method defaults to the zero (i.e. black for images) baseline.""" + + +BlurBaselineConfigOrDict = Union[BlurBaselineConfig, BlurBaselineConfigDict] + + +class FeatureNoiseSigmaNoiseSigmaForFeature(_common.BaseModel): + """Noise sigma for a single feature.""" + + name: Optional[str] = Field( + default=None, + description="""The name of the input feature for which noise sigma is provided. The features are defined in explanation metadata inputs.""", + ) + sigma: Optional[float] = Field( + default=None, + description="""This represents the standard deviation of the Gaussian kernel that will be used to add noise to the feature prior to computing gradients. Similar to noise_sigma but represents the noise added to the current feature. Defaults to 0.1.""", + ) + + +class FeatureNoiseSigmaNoiseSigmaForFeatureDict(TypedDict, total=False): + """Noise sigma for a single feature.""" + + name: Optional[str] + """The name of the input feature for which noise sigma is provided. The features are defined in explanation metadata inputs.""" + + sigma: Optional[float] + """This represents the standard deviation of the Gaussian kernel that will be used to add noise to the feature prior to computing gradients. Similar to noise_sigma but represents the noise added to the current feature. Defaults to 0.1.""" + + +FeatureNoiseSigmaNoiseSigmaForFeatureOrDict = Union[ + FeatureNoiseSigmaNoiseSigmaForFeature, FeatureNoiseSigmaNoiseSigmaForFeatureDict +] + + +class FeatureNoiseSigma(_common.BaseModel): + """Noise sigma by features. Noise sigma represents the standard deviation of the gaussian kernel that will be used to add noise to interpolated inputs prior to computing gradients.""" + + noise_sigma: Optional[list[FeatureNoiseSigmaNoiseSigmaForFeature]] = Field( + default=None, + description="""Noise sigma per feature. No noise is added to features that are not set.""", + ) + + +class FeatureNoiseSigmaDict(TypedDict, total=False): + """Noise sigma by features. Noise sigma represents the standard deviation of the gaussian kernel that will be used to add noise to interpolated inputs prior to computing gradients.""" + + noise_sigma: Optional[list[FeatureNoiseSigmaNoiseSigmaForFeatureDict]] + """Noise sigma per feature. No noise is added to features that are not set.""" + + +FeatureNoiseSigmaOrDict = Union[FeatureNoiseSigma, FeatureNoiseSigmaDict] + + +class SmoothGradConfig(_common.BaseModel): + """Config for SmoothGrad approximation of gradients. When enabled, the gradients are approximated by averaging the gradients from noisy samples in the vicinity of the inputs. Adding noise can help improve the computed gradients. Refer to this paper for more details: https://arxiv.org/pdf/1706.03825.pdf""" + + feature_noise_sigma: Optional[FeatureNoiseSigma] = Field( + default=None, + description="""This is similar to noise_sigma, but provides additional flexibility. A separate noise sigma can be provided for each feature, which is useful if their distributions are different. No noise is added to features that are not set. If this field is unset, noise_sigma will be used for all features.""", + ) + noise_sigma: Optional[float] = Field( + default=None, + description="""This is a single float value and will be used to add noise to all the features. Use this field when all features are normalized to have the same distribution: scale to range [0, 1], [-1, 1] or z-scoring, where features are normalized to have 0-mean and 1-variance. Learn more about [normalization](https://developers.google.com/machine-learning/data-prep/transform/normalization). For best results the recommended value is about 10% - 20% of the standard deviation of the input feature. Refer to section 3.2 of the SmoothGrad paper: https://arxiv.org/pdf/1706.03825.pdf. Defaults to 0.1. If the distribution is different per feature, set feature_noise_sigma instead for each feature.""", + ) + noisy_sample_count: Optional[int] = Field( + default=None, + description="""The number of gradient samples to use for approximation. The higher this number, the more accurate the gradient is, but the runtime complexity increases by this factor as well. Valid range of its value is [1, 50]. Defaults to 3.""", + ) + + +class SmoothGradConfigDict(TypedDict, total=False): + """Config for SmoothGrad approximation of gradients. When enabled, the gradients are approximated by averaging the gradients from noisy samples in the vicinity of the inputs. Adding noise can help improve the computed gradients. Refer to this paper for more details: https://arxiv.org/pdf/1706.03825.pdf""" + + feature_noise_sigma: Optional[FeatureNoiseSigmaDict] + """This is similar to noise_sigma, but provides additional flexibility. A separate noise sigma can be provided for each feature, which is useful if their distributions are different. No noise is added to features that are not set. If this field is unset, noise_sigma will be used for all features.""" + + noise_sigma: Optional[float] + """This is a single float value and will be used to add noise to all the features. Use this field when all features are normalized to have the same distribution: scale to range [0, 1], [-1, 1] or z-scoring, where features are normalized to have 0-mean and 1-variance. Learn more about [normalization](https://developers.google.com/machine-learning/data-prep/transform/normalization). For best results the recommended value is about 10% - 20% of the standard deviation of the input feature. Refer to section 3.2 of the SmoothGrad paper: https://arxiv.org/pdf/1706.03825.pdf. Defaults to 0.1. If the distribution is different per feature, set feature_noise_sigma instead for each feature.""" + + noisy_sample_count: Optional[int] + """The number of gradient samples to use for approximation. The higher this number, the more accurate the gradient is, but the runtime complexity increases by this factor as well. Valid range of its value is [1, 50]. Defaults to 3.""" + + +SmoothGradConfigOrDict = Union[SmoothGradConfig, SmoothGradConfigDict] + + +class IntegratedGradientsAttribution(_common.BaseModel): + """An attribution method that computes the Aumann-Shapley value taking advantage of the model's fully differentiable structure. Refer to this paper for more details: https://arxiv.org/abs/1703.01365""" + + blur_baseline_config: Optional[BlurBaselineConfig] = Field( + default=None, + description="""Config for IG with blur baseline. When enabled, a linear path from the maximally blurred image to the input image is created. Using a blurred baseline instead of zero (black image) is motivated by the BlurIG approach explained here: https://arxiv.org/abs/2004.03383""", + ) + smooth_grad_config: Optional[SmoothGradConfig] = Field( + default=None, + description="""Config for SmoothGrad approximation of gradients. When enabled, the gradients are approximated by averaging the gradients from noisy samples in the vicinity of the inputs. Adding noise can help improve the computed gradients. Refer to this paper for more details: https://arxiv.org/pdf/1706.03825.pdf""", + ) + step_count: Optional[int] = Field( + default=None, + description="""Required. The number of steps for approximating the path integral. A good value to start is 50 and gradually increase until the sum to diff property is within the desired error range. Valid range of its value is [1, 100], inclusively.""", + ) + + +class IntegratedGradientsAttributionDict(TypedDict, total=False): + """An attribution method that computes the Aumann-Shapley value taking advantage of the model's fully differentiable structure. Refer to this paper for more details: https://arxiv.org/abs/1703.01365""" + + blur_baseline_config: Optional[BlurBaselineConfigDict] + """Config for IG with blur baseline. When enabled, a linear path from the maximally blurred image to the input image is created. Using a blurred baseline instead of zero (black image) is motivated by the BlurIG approach explained here: https://arxiv.org/abs/2004.03383""" + + smooth_grad_config: Optional[SmoothGradConfigDict] + """Config for SmoothGrad approximation of gradients. When enabled, the gradients are approximated by averaging the gradients from noisy samples in the vicinity of the inputs. Adding noise can help improve the computed gradients. Refer to this paper for more details: https://arxiv.org/pdf/1706.03825.pdf""" + + step_count: Optional[int] + """Required. The number of steps for approximating the path integral. A good value to start is 50 and gradually increase until the sum to diff property is within the desired error range. Valid range of its value is [1, 100], inclusively.""" + + +IntegratedGradientsAttributionOrDict = Union[ + IntegratedGradientsAttribution, IntegratedGradientsAttributionDict +] + + +class SampledShapleyAttribution(_common.BaseModel): + """An attribution method that approximates Shapley values for features that contribute to the label being predicted. A sampling strategy is used to approximate the value rather than considering all subsets of features.""" + + path_count: Optional[int] = Field( + default=None, + description="""Required. The number of feature permutations to consider when approximating the Shapley values. Valid range of its value is [1, 50], inclusively.""", + ) + + +class SampledShapleyAttributionDict(TypedDict, total=False): + """An attribution method that approximates Shapley values for features that contribute to the label being predicted. A sampling strategy is used to approximate the value rather than considering all subsets of features.""" + + path_count: Optional[int] + """Required. The number of feature permutations to consider when approximating the Shapley values. Valid range of its value is [1, 50], inclusively.""" + + +SampledShapleyAttributionOrDict = Union[ + SampledShapleyAttribution, SampledShapleyAttributionDict +] + + +class XraiAttribution(_common.BaseModel): + """An explanation method that redistributes Integrated Gradients attributions to segmented regions, taking advantage of the model's fully differentiable structure. Refer to this paper for more details: https://arxiv.org/abs/1906.02825 Supported only by image Models.""" + + blur_baseline_config: Optional[BlurBaselineConfig] = Field( + default=None, + description="""Config for XRAI with blur baseline. When enabled, a linear path from the maximally blurred image to the input image is created. Using a blurred baseline instead of zero (black image) is motivated by the BlurIG approach explained here: https://arxiv.org/abs/2004.03383""", + ) + smooth_grad_config: Optional[SmoothGradConfig] = Field( + default=None, + description="""Config for SmoothGrad approximation of gradients. When enabled, the gradients are approximated by averaging the gradients from noisy samples in the vicinity of the inputs. Adding noise can help improve the computed gradients. Refer to this paper for more details: https://arxiv.org/pdf/1706.03825.pdf""", + ) + step_count: Optional[int] = Field( + default=None, + description="""Required. The number of steps for approximating the path integral. A good value to start is 50 and gradually increase until the sum to diff property is met within the desired error range. Valid range of its value is [1, 100], inclusively.""", + ) + + +class XraiAttributionDict(TypedDict, total=False): + """An explanation method that redistributes Integrated Gradients attributions to segmented regions, taking advantage of the model's fully differentiable structure. Refer to this paper for more details: https://arxiv.org/abs/1906.02825 Supported only by image Models.""" + + blur_baseline_config: Optional[BlurBaselineConfigDict] + """Config for XRAI with blur baseline. When enabled, a linear path from the maximally blurred image to the input image is created. Using a blurred baseline instead of zero (black image) is motivated by the BlurIG approach explained here: https://arxiv.org/abs/2004.03383""" + + smooth_grad_config: Optional[SmoothGradConfigDict] + """Config for SmoothGrad approximation of gradients. When enabled, the gradients are approximated by averaging the gradients from noisy samples in the vicinity of the inputs. Adding noise can help improve the computed gradients. Refer to this paper for more details: https://arxiv.org/pdf/1706.03825.pdf""" + + step_count: Optional[int] + """Required. The number of steps for approximating the path integral. A good value to start is 50 and gradually increase until the sum to diff property is met within the desired error range. Valid range of its value is [1, 100], inclusively.""" + + +XraiAttributionOrDict = Union[XraiAttribution, XraiAttributionDict] + + +class ExplanationParameters(_common.BaseModel): + """Parameters to configure explaining for Model's predictions.""" + + examples: Optional[Examples] = Field( + default=None, + description="""Example-based explanations that returns the nearest neighbors from the provided dataset.""", + ) + integrated_gradients_attribution: Optional[IntegratedGradientsAttribution] = Field( + default=None, + description="""An attribution method that computes Aumann-Shapley values taking advantage of the model's fully differentiable structure. Refer to this paper for more details: https://arxiv.org/abs/1703.01365""", + ) + output_indices: Optional[list[Any]] = Field( + default=None, + description="""If populated, only returns attributions that have output_index contained in output_indices. It must be an ndarray of integers, with the same shape of the output it's explaining. If not populated, returns attributions for top_k indices of outputs. If neither top_k nor output_indices is populated, returns the argmax index of the outputs. Only applicable to Models that predict multiple outputs (e,g, multi-class Models that predict multiple classes).""", + ) + sampled_shapley_attribution: Optional[SampledShapleyAttribution] = Field( + default=None, + description="""An attribution method that approximates Shapley values for features that contribute to the label being predicted. A sampling strategy is used to approximate the value rather than considering all subsets of features. Refer to this paper for model details: https://arxiv.org/abs/1306.4265.""", + ) + top_k: Optional[int] = Field( + default=None, + description="""If populated, returns attributions for top K indices of outputs (defaults to 1). Only applies to Models that predicts more than one outputs (e,g, multi-class Models). When set to -1, returns explanations for all outputs.""", + ) + xrai_attribution: Optional[XraiAttribution] = Field( + default=None, + description="""An attribution method that redistributes Integrated Gradients attribution to segmented regions, taking advantage of the model's fully differentiable structure. Refer to this paper for more details: https://arxiv.org/abs/1906.02825 XRAI currently performs better on natural images, like a picture of a house or an animal. If the images are taken in artificial environments, like a lab or manufacturing line, or from diagnostic equipment, like x-rays or quality-control cameras, use Integrated Gradients instead.""", + ) + + +class ExplanationParametersDict(TypedDict, total=False): + """Parameters to configure explaining for Model's predictions.""" + + examples: Optional[ExamplesDict] + """Example-based explanations that returns the nearest neighbors from the provided dataset.""" + + integrated_gradients_attribution: Optional[IntegratedGradientsAttributionDict] + """An attribution method that computes Aumann-Shapley values taking advantage of the model's fully differentiable structure. Refer to this paper for more details: https://arxiv.org/abs/1703.01365""" + + output_indices: Optional[list[Any]] + """If populated, only returns attributions that have output_index contained in output_indices. It must be an ndarray of integers, with the same shape of the output it's explaining. If not populated, returns attributions for top_k indices of outputs. If neither top_k nor output_indices is populated, returns the argmax index of the outputs. Only applicable to Models that predict multiple outputs (e,g, multi-class Models that predict multiple classes).""" + + sampled_shapley_attribution: Optional[SampledShapleyAttributionDict] + """An attribution method that approximates Shapley values for features that contribute to the label being predicted. A sampling strategy is used to approximate the value rather than considering all subsets of features. Refer to this paper for model details: https://arxiv.org/abs/1306.4265.""" + + top_k: Optional[int] + """If populated, returns attributions for top K indices of outputs (defaults to 1). Only applies to Models that predicts more than one outputs (e,g, multi-class Models). When set to -1, returns explanations for all outputs.""" + + xrai_attribution: Optional[XraiAttributionDict] + """An attribution method that redistributes Integrated Gradients attribution to segmented regions, taking advantage of the model's fully differentiable structure. Refer to this paper for more details: https://arxiv.org/abs/1906.02825 XRAI currently performs better on natural images, like a picture of a house or an animal. If the images are taken in artificial environments, like a lab or manufacturing line, or from diagnostic equipment, like x-rays or quality-control cameras, use Integrated Gradients instead.""" + + +ExplanationParametersOrDict = Union[ExplanationParameters, ExplanationParametersDict] + + +class ExplanationSpec(_common.BaseModel): + """Specification of Model explanation.""" + + metadata: Optional[ExplanationMetadata] = Field( + default=None, + description="""Optional. Metadata describing the Model's input and output for explanation.""", + ) + parameters: Optional[ExplanationParameters] = Field( + default=None, + description="""Required. Parameters that configure explaining of the Model's predictions.""", + ) + + +class ExplanationSpecDict(TypedDict, total=False): + """Specification of Model explanation.""" + + metadata: Optional[ExplanationMetadataDict] + """Optional. Metadata describing the Model's input and output for explanation.""" + + parameters: Optional[ExplanationParametersDict] + """Required. Parameters that configure explaining of the Model's predictions.""" + + +ExplanationSpecOrDict = Union[ExplanationSpec, ExplanationSpecDict] + + +class FasterDeploymentConfig(_common.BaseModel): + """Configuration for faster model deployment.""" + + fast_tryout_enabled: Optional[bool] = Field( + default=None, + description="""If true, enable fast tryout feature for this deployed model.""", + ) + + +class FasterDeploymentConfigDict(TypedDict, total=False): + """Configuration for faster model deployment.""" + + fast_tryout_enabled: Optional[bool] + """If true, enable fast tryout feature for this deployed model.""" + + +FasterDeploymentConfigOrDict = Union[FasterDeploymentConfig, FasterDeploymentConfigDict] + + +class FullFineTunedResources(_common.BaseModel): + """Resources for an fft model.""" + + deployment_type: Optional[DeploymentType] = Field( + default=None, description="""Required. The kind of deployment.""" + ) + model_inference_unit_count: Optional[int] = Field( + default=None, + description="""Optional. The number of model inference units to use for this deployment. This can only be specified for DEPLOYMENT_TYPE_PROD. The following table lists the number of model inference units for different model types: * Gemini 2.5 Flash * Foundation FMIU: 25 * Expansion FMIU: 4 * Gemini 2.5 Pro * Foundation FMIU: 32 * Expansion FMIU: 16 * Veo 3.0 (undistilled) * Foundation FMIU: 63 * Expansion FMIU: 7 * Veo 3.0 (distilled) * Foundation FMIU: 30 * Expansion FMIU: 10""", + ) + + +class FullFineTunedResourcesDict(TypedDict, total=False): + """Resources for an fft model.""" + + deployment_type: Optional[DeploymentType] + """Required. The kind of deployment.""" + + model_inference_unit_count: Optional[int] + """Optional. The number of model inference units to use for this deployment. This can only be specified for DEPLOYMENT_TYPE_PROD. The following table lists the number of model inference units for different model types: * Gemini 2.5 Flash * Foundation FMIU: 25 * Expansion FMIU: 4 * Gemini 2.5 Pro * Foundation FMIU: 32 * Expansion FMIU: 16 * Veo 3.0 (undistilled) * Foundation FMIU: 63 * Expansion FMIU: 7 * Veo 3.0 (distilled) * Foundation FMIU: 30 * Expansion FMIU: 10""" + + +FullFineTunedResourcesOrDict = Union[FullFineTunedResources, FullFineTunedResourcesDict] + + +class PrivateEndpoints(_common.BaseModel): + """PrivateEndpoints proto is used to provide paths for users to send requests privately. To send request via private service access, use predict_http_uri, explain_http_uri or health_http_uri. To send request via private service connect, use service_attachment.""" + + explain_http_uri: Optional[str] = Field( + default=None, + description="""Output only. Http(s) path to send explain requests.""", + ) + health_http_uri: Optional[str] = Field( + default=None, + description="""Output only. Http(s) path to send health check requests.""", + ) + predict_http_uri: Optional[str] = Field( + default=None, + description="""Output only. Http(s) path to send prediction requests.""", + ) + service_attachment: Optional[str] = Field( + default=None, + description="""Output only. The name of the service attachment resource. Populated if private service connect is enabled.""", + ) + + +class PrivateEndpointsDict(TypedDict, total=False): + """PrivateEndpoints proto is used to provide paths for users to send requests privately. To send request via private service access, use predict_http_uri, explain_http_uri or health_http_uri. To send request via private service connect, use service_attachment.""" + + explain_http_uri: Optional[str] + """Output only. Http(s) path to send explain requests.""" + + health_http_uri: Optional[str] + """Output only. Http(s) path to send health check requests.""" + + predict_http_uri: Optional[str] + """Output only. Http(s) path to send prediction requests.""" + + service_attachment: Optional[str] + """Output only. The name of the service attachment resource. Populated if private service connect is enabled.""" + + +PrivateEndpointsOrDict = Union[PrivateEndpoints, PrivateEndpointsDict] + + +class RolloutOptions(_common.BaseModel): + """Configuration for rolling deployments.""" + + max_surge_percentage: Optional[int] = Field( + default=None, + description="""Percentage of allowed additional replicas. For autoscaling deployments, this refers to the target replica count.""", + ) + max_surge_replicas: Optional[int] = Field( + default=None, description="""Absolute count of allowed additional replicas.""" + ) + max_unavailable_percentage: Optional[int] = Field( + default=None, + description="""Percentage of replicas allowed to be unavailable. For autoscaling deployments, this refers to the target replica count.""", + ) + max_unavailable_replicas: Optional[int] = Field( + default=None, + description="""Absolute count of replicas allowed to be unavailable.""", + ) + previous_deployed_model: Optional[str] = Field( + default=None, + description="""ID of the DeployedModel that this deployment should replace.""", + ) + revision_number: Optional[int] = Field( + default=None, + description="""Output only. Read-only. Revision number determines the relative priority of DeployedModels in the same rollout. The DeployedModel with the largest revision number specifies the intended state of the deployment.""", + ) + + +class RolloutOptionsDict(TypedDict, total=False): + """Configuration for rolling deployments.""" + + max_surge_percentage: Optional[int] + """Percentage of allowed additional replicas. For autoscaling deployments, this refers to the target replica count.""" + + max_surge_replicas: Optional[int] + """Absolute count of allowed additional replicas.""" + + max_unavailable_percentage: Optional[int] + """Percentage of replicas allowed to be unavailable. For autoscaling deployments, this refers to the target replica count.""" + + max_unavailable_replicas: Optional[int] + """Absolute count of replicas allowed to be unavailable.""" + + previous_deployed_model: Optional[str] + """ID of the DeployedModel that this deployment should replace.""" + + revision_number: Optional[int] + """Output only. Read-only. Revision number determines the relative priority of DeployedModels in the same rollout. The DeployedModel with the largest revision number specifies the intended state of the deployment.""" + + +RolloutOptionsOrDict = Union[RolloutOptions, RolloutOptionsDict] + + +class SpeculativeDecodingSpecDraftModelSpeculation(_common.BaseModel): + """Draft model speculation works by using the smaller model to generate candidate tokens for speculative decoding.""" + + draft_model: Optional[str] = Field( + default=None, description="""Required. The resource name of the draft model.""" + ) + + +class SpeculativeDecodingSpecDraftModelSpeculationDict(TypedDict, total=False): + """Draft model speculation works by using the smaller model to generate candidate tokens for speculative decoding.""" + + draft_model: Optional[str] + """Required. The resource name of the draft model.""" + + +SpeculativeDecodingSpecDraftModelSpeculationOrDict = Union[ + SpeculativeDecodingSpecDraftModelSpeculation, + SpeculativeDecodingSpecDraftModelSpeculationDict, +] + + +class SpeculativeDecodingSpecNgramSpeculation(_common.BaseModel): + """N-Gram speculation works by trying to find matching tokens in the previous prompt sequence and use those as speculation for generating new tokens.""" + + ngram_size: Optional[int] = Field( + default=None, + description="""The number of last N input tokens used as ngram to search/match against the previous prompt sequence. This is equal to the N in N-Gram. The default value is 3 if not specified.""", + ) + + +class SpeculativeDecodingSpecNgramSpeculationDict(TypedDict, total=False): + """N-Gram speculation works by trying to find matching tokens in the previous prompt sequence and use those as speculation for generating new tokens.""" + + ngram_size: Optional[int] + """The number of last N input tokens used as ngram to search/match against the previous prompt sequence. This is equal to the N in N-Gram. The default value is 3 if not specified.""" + + +SpeculativeDecodingSpecNgramSpeculationOrDict = Union[ + SpeculativeDecodingSpecNgramSpeculation, SpeculativeDecodingSpecNgramSpeculationDict +] + + +class SpeculativeDecodingSpec(_common.BaseModel): + """Configuration for Speculative Decoding.""" + + draft_model_speculation: Optional[SpeculativeDecodingSpecDraftModelSpeculation] = ( + Field(default=None, description="""draft model speculation.""") + ) + ngram_speculation: Optional[SpeculativeDecodingSpecNgramSpeculation] = Field( + default=None, description="""N-Gram speculation.""" + ) + speculative_token_count: Optional[int] = Field( + default=None, + description="""The number of speculative tokens to generate at each step.""", + ) + + +class SpeculativeDecodingSpecDict(TypedDict, total=False): + """Configuration for Speculative Decoding.""" + + draft_model_speculation: Optional[SpeculativeDecodingSpecDraftModelSpeculationDict] + """draft model speculation.""" + + ngram_speculation: Optional[SpeculativeDecodingSpecNgramSpeculationDict] + """N-Gram speculation.""" + + speculative_token_count: Optional[int] + """The number of speculative tokens to generate at each step.""" + + +SpeculativeDecodingSpecOrDict = Union[ + SpeculativeDecodingSpec, SpeculativeDecodingSpecDict +] + + +class DeployedModelStatus(_common.BaseModel): + """Runtime status of the deployed model.""" + + available_replica_count: Optional[int] = Field( + default=None, + description="""Output only. The number of available replicas of the deployed model.""", + ) + last_update_time: Optional[datetime.datetime] = Field( + default=None, + description="""Output only. The time at which the status was last updated.""", + ) + message: Optional[str] = Field( + default=None, + description="""Output only. The latest deployed model's status message (if any).""", + ) + + +class DeployedModelStatusDict(TypedDict, total=False): + """Runtime status of the deployed model.""" + + available_replica_count: Optional[int] + """Output only. The number of available replicas of the deployed model.""" + + last_update_time: Optional[datetime.datetime] + """Output only. The time at which the status was last updated.""" + + message: Optional[str] + """Output only. The latest deployed model's status message (if any).""" + + +DeployedModelStatusOrDict = Union[DeployedModelStatus, DeployedModelStatusDict] + + +class DeployedModel(_common.BaseModel): + """A deployment of a Model. Endpoints contain one or more DeployedModels.""" + + display_name: Optional[str] = Field( + default=None, + description="""The display name of the DeployedModel. If not provided upon creation, the Model's display_name is used.""", + ) + id: Optional[str] = Field( + default=None, + description="""Immutable. The ID of the DeployedModel. If not provided upon deployment, Vertex AI will generate a value for this ID. This value should be 1-10 characters, and valid characters are `/[0-9]/`.""", + ) + automatic_resources: Optional[AutomaticResources] = Field( + default=None, + description="""A description of resources that to large degree are decided by Vertex AI, and require only a modest additional configuration.""", + ) + checkpoint_id: Optional[str] = Field( + default=None, description="""The checkpoint id of the model.""" + ) + create_time: Optional[datetime.datetime] = Field( + default=None, + description="""Output only. Timestamp when the DeployedModel was created.""", + ) + dedicated_resources: Optional[DedicatedResources] = Field( + default=None, + description="""A description of resources that are dedicated to the DeployedModel, and that need a higher degree of manual configuration.""", + ) + disable_container_logging: Optional[bool] = Field( + default=None, + description="""For custom-trained Models and AutoML Tabular Models, the container of the DeployedModel instances will send `stderr` and `stdout` streams to Cloud Logging by default. Please note that the logs incur cost, which are subject to [Cloud Logging pricing](https://cloud.google.com/logging/pricing). User can disable container logging by setting this flag to true.""", + ) + disable_explanations: Optional[bool] = Field( + default=None, + description="""If true, deploy the model without explainable feature, regardless the existence of Model.explanation_spec or explanation_spec.""", + ) + enable_access_logging: Optional[bool] = Field( + default=None, + description="""If true, online prediction access logs are sent to Cloud Logging. These logs are like standard server access logs, containing information like timestamp and latency for each prediction request. Note that logs may incur a cost, especially if your project receives prediction requests at a high queries per second rate (QPS). Estimate your costs before enabling this option.""", + ) + enable_container_logging: Optional[bool] = Field( + default=None, + description="""If true, the container of the DeployedModel instances will send `stderr` and `stdout` streams to Cloud Logging. Only supported for custom-trained Models and AutoML Tabular Models.""", + ) + explanation_spec: Optional[ExplanationSpec] = Field( + default=None, + description="""Explanation configuration for this DeployedModel. When deploying a Model using EndpointService.DeployModel, this value overrides the value of Model.explanation_spec. All fields of explanation_spec are optional in the request. If a field of explanation_spec is not populated, the value of the same field of Model.explanation_spec is inherited. If the corresponding Model.explanation_spec is not populated, all fields of the explanation_spec will be used for the explanation configuration.""", + ) + faster_deployment_config: Optional[FasterDeploymentConfig] = Field( + default=None, description="""Configuration for faster model deployment.""" + ) + full_fine_tuned_resources: Optional[FullFineTunedResources] = Field( + default=None, description="""Optional. Resources for a full fine tuned model.""" + ) + gdc_connected_model: Optional[str] = Field( + default=None, + description="""GDC pretrained / Gemini model name. The model name is a plain model name, e.g. gemini-1.5-flash-002.""", + ) + model: Optional[str] = Field( + default=None, + description="""The resource name of the Model that this is the deployment of. Note that the Model may be in a different location than the DeployedModel's Endpoint. The resource name may contain version id or version alias to specify the version. Example: `projects/{project}/locations/{location}/models/{model}@2` or `projects/{project}/locations/{location}/models/{model}@golden` if no version is specified, the default version will be deployed.""", + ) + model_version_id: Optional[str] = Field( + default=None, + description="""Output only. The version ID of the model that is deployed.""", + ) + private_endpoints: Optional[PrivateEndpoints] = Field( + default=None, + description="""Output only. Provide paths for users to send predict/explain/health requests directly to the deployed model services running on Cloud via private services access. This field is populated if network is configured.""", + ) + rollout_options: Optional[RolloutOptions] = Field( + default=None, description="""Options for configuring rolling deployments.""" + ) + service_account: Optional[str] = Field( + default=None, + description="""The service account that the DeployedModel's container runs as. Specify the email address of the service account. If this service account is not specified, the container runs as a service account that doesn't have access to the resource project. Users deploying the Model must have the `iam.serviceAccounts.actAs` permission on this service account.""", + ) + shared_resources: Optional[str] = Field( + default=None, + description="""The resource name of the shared DeploymentResourcePool to deploy on. Format: `projects/{project}/locations/{location}/deploymentResourcePools/{deployment_resource_pool}`""", + ) + speculative_decoding_spec: Optional[SpeculativeDecodingSpec] = Field( + default=None, + description="""Optional. Spec for configuring speculative decoding.""", + ) + status: Optional[DeployedModelStatus] = Field( + default=None, + description="""Output only. Runtime status of the deployed model.""", + ) + system_labels: Optional[dict[str, str]] = Field( + default=None, + description="""System labels to apply to Model Garden deployments. System labels are managed by Google for internal use only.""", + ) + + +class DeployedModelDict(TypedDict, total=False): + """A deployment of a Model. Endpoints contain one or more DeployedModels.""" + + display_name: Optional[str] + """The display name of the DeployedModel. If not provided upon creation, the Model's display_name is used.""" + + id: Optional[str] + """Immutable. The ID of the DeployedModel. If not provided upon deployment, Vertex AI will generate a value for this ID. This value should be 1-10 characters, and valid characters are `/[0-9]/`.""" + + automatic_resources: Optional[AutomaticResourcesDict] + """A description of resources that to large degree are decided by Vertex AI, and require only a modest additional configuration.""" + + checkpoint_id: Optional[str] + """The checkpoint id of the model.""" + + create_time: Optional[datetime.datetime] + """Output only. Timestamp when the DeployedModel was created.""" + + dedicated_resources: Optional[DedicatedResourcesDict] + """A description of resources that are dedicated to the DeployedModel, and that need a higher degree of manual configuration.""" + + disable_container_logging: Optional[bool] + """For custom-trained Models and AutoML Tabular Models, the container of the DeployedModel instances will send `stderr` and `stdout` streams to Cloud Logging by default. Please note that the logs incur cost, which are subject to [Cloud Logging pricing](https://cloud.google.com/logging/pricing). User can disable container logging by setting this flag to true.""" + + disable_explanations: Optional[bool] + """If true, deploy the model without explainable feature, regardless the existence of Model.explanation_spec or explanation_spec.""" + + enable_access_logging: Optional[bool] + """If true, online prediction access logs are sent to Cloud Logging. These logs are like standard server access logs, containing information like timestamp and latency for each prediction request. Note that logs may incur a cost, especially if your project receives prediction requests at a high queries per second rate (QPS). Estimate your costs before enabling this option.""" + + enable_container_logging: Optional[bool] + """If true, the container of the DeployedModel instances will send `stderr` and `stdout` streams to Cloud Logging. Only supported for custom-trained Models and AutoML Tabular Models.""" + + explanation_spec: Optional[ExplanationSpecDict] + """Explanation configuration for this DeployedModel. When deploying a Model using EndpointService.DeployModel, this value overrides the value of Model.explanation_spec. All fields of explanation_spec are optional in the request. If a field of explanation_spec is not populated, the value of the same field of Model.explanation_spec is inherited. If the corresponding Model.explanation_spec is not populated, all fields of the explanation_spec will be used for the explanation configuration.""" + + faster_deployment_config: Optional[FasterDeploymentConfigDict] + """Configuration for faster model deployment.""" + + full_fine_tuned_resources: Optional[FullFineTunedResourcesDict] + """Optional. Resources for a full fine tuned model.""" + + gdc_connected_model: Optional[str] + """GDC pretrained / Gemini model name. The model name is a plain model name, e.g. gemini-1.5-flash-002.""" + + model: Optional[str] + """The resource name of the Model that this is the deployment of. Note that the Model may be in a different location than the DeployedModel's Endpoint. The resource name may contain version id or version alias to specify the version. Example: `projects/{project}/locations/{location}/models/{model}@2` or `projects/{project}/locations/{location}/models/{model}@golden` if no version is specified, the default version will be deployed.""" + + model_version_id: Optional[str] + """Output only. The version ID of the model that is deployed.""" + + private_endpoints: Optional[PrivateEndpointsDict] + """Output only. Provide paths for users to send predict/explain/health requests directly to the deployed model services running on Cloud via private services access. This field is populated if network is configured.""" + + rollout_options: Optional[RolloutOptionsDict] + """Options for configuring rolling deployments.""" + + service_account: Optional[str] + """The service account that the DeployedModel's container runs as. Specify the email address of the service account. If this service account is not specified, the container runs as a service account that doesn't have access to the resource project. Users deploying the Model must have the `iam.serviceAccounts.actAs` permission on this service account.""" + + shared_resources: Optional[str] + """The resource name of the shared DeploymentResourcePool to deploy on. Format: `projects/{project}/locations/{location}/deploymentResourcePools/{deployment_resource_pool}`""" + + speculative_decoding_spec: Optional[SpeculativeDecodingSpecDict] + """Optional. Spec for configuring speculative decoding.""" + + status: Optional[DeployedModelStatusDict] + """Output only. Runtime status of the deployed model.""" + + system_labels: Optional[dict[str, str]] + """System labels to apply to Model Garden deployments. System labels are managed by Google for internal use only.""" + + +DeployedModelOrDict = Union[DeployedModel, DeployedModelDict] + + +class ClientConnectionConfig(_common.BaseModel): + """Configurations (e.g. inference timeout) that are applied on your endpoints.""" + + inference_timeout: Optional[str] = Field( + default=None, description="""Customizable online prediction request timeout.""" + ) + + +class ClientConnectionConfigDict(TypedDict, total=False): + """Configurations (e.g. inference timeout) that are applied on your endpoints.""" + + inference_timeout: Optional[str] + """Customizable online prediction request timeout.""" + + +ClientConnectionConfigOrDict = Union[ClientConnectionConfig, ClientConnectionConfigDict] + + +class GdcConfig(_common.BaseModel): + """Google Distributed Cloud (GDC) config.""" + + zone: Optional[str] = Field( + default=None, + description="""GDC zone. A cluster will be designated for the Vertex AI workload in this zone.""", + ) + + +class GdcConfigDict(TypedDict, total=False): + """Google Distributed Cloud (GDC) config.""" + + zone: Optional[str] + """GDC zone. A cluster will be designated for the Vertex AI workload in this zone.""" + + +GdcConfigOrDict = Union[GdcConfig, GdcConfigDict] + + +class GenAiAdvancedFeaturesConfigRagConfig(_common.BaseModel): + """Configuration for Retrieval Augmented Generation feature.""" + + enable_rag: Optional[bool] = Field( + default=None, + description="""If true, enable Retrieval Augmented Generation in ChatCompletion request. Once enabled, the endpoint will be identified as GenAI endpoint and Arthedain router will be used.""", + ) + + +class GenAiAdvancedFeaturesConfigRagConfigDict(TypedDict, total=False): + """Configuration for Retrieval Augmented Generation feature.""" + + enable_rag: Optional[bool] + """If true, enable Retrieval Augmented Generation in ChatCompletion request. Once enabled, the endpoint will be identified as GenAI endpoint and Arthedain router will be used.""" + + +GenAiAdvancedFeaturesConfigRagConfigOrDict = Union[ + GenAiAdvancedFeaturesConfigRagConfig, GenAiAdvancedFeaturesConfigRagConfigDict +] + + +class GenAiAdvancedFeaturesConfig(_common.BaseModel): + """Configuration for GenAiAdvancedFeatures.""" + + rag_config: Optional[GenAiAdvancedFeaturesConfigRagConfig] = Field( + default=None, + description="""Configuration for Retrieval Augmented Generation feature.""", + ) + + +class GenAiAdvancedFeaturesConfigDict(TypedDict, total=False): + """Configuration for GenAiAdvancedFeatures.""" + + rag_config: Optional[GenAiAdvancedFeaturesConfigRagConfigDict] + """Configuration for Retrieval Augmented Generation feature.""" + + +GenAiAdvancedFeaturesConfigOrDict = Union[ + GenAiAdvancedFeaturesConfig, GenAiAdvancedFeaturesConfigDict +] + + +class PredictRequestResponseLoggingConfig(_common.BaseModel): + """Configuration for logging request-response to a BigQuery table.""" + + bigquery_destination: Optional[BigQueryDestination] = Field( + default=None, + description="""BigQuery table for logging. If only given a project, a new dataset will be created with name `logging__` where will be made BigQuery-dataset-name compatible (e.g. most special characters will become underscores). If no table name is given, a new table will be created with name `request_response_logging`""", + ) + enable_otel_logging: Optional[bool] = Field( + default=None, + description="""This field is used for large models. If true, in addition to the original large model logs, logs will be converted in OTel schema format, and saved in otel_log column. Default value is false.""", + ) + enabled: Optional[bool] = Field( + default=None, description="""If logging is enabled or not.""" + ) + error_sampling_rate: Optional[float] = Field( + default=None, + description="""Optional. Percentage of failed requests to be logged, expressed as a fraction in range [0,1]. Only non-transient errors will be logged (currently `500/Internal` errors).""", + ) + request_response_logging_schema_version: Optional[str] = Field( + default=None, + description="""Output only. The schema version used in creating the BigQuery table for the request response logging. The versions are "v1" and "v2". The current default version is "v1".""", + ) + sampling_rate: Optional[float] = Field( + default=None, + description="""Percentage of requests to be logged, expressed as a fraction in range(0,1].""", + ) + + +class PredictRequestResponseLoggingConfigDict(TypedDict, total=False): + """Configuration for logging request-response to a BigQuery table.""" + + bigquery_destination: Optional[BigQueryDestinationDict] + """BigQuery table for logging. If only given a project, a new dataset will be created with name `logging__` where will be made BigQuery-dataset-name compatible (e.g. most special characters will become underscores). If no table name is given, a new table will be created with name `request_response_logging`""" + + enable_otel_logging: Optional[bool] + """This field is used for large models. If true, in addition to the original large model logs, logs will be converted in OTel schema format, and saved in otel_log column. Default value is false.""" + + enabled: Optional[bool] + """If logging is enabled or not.""" + + error_sampling_rate: Optional[float] + """Optional. Percentage of failed requests to be logged, expressed as a fraction in range [0,1]. Only non-transient errors will be logged (currently `500/Internal` errors).""" + + request_response_logging_schema_version: Optional[str] + """Output only. The schema version used in creating the BigQuery table for the request response logging. The versions are "v1" and "v2". The current default version is "v1".""" + + sampling_rate: Optional[float] + """Percentage of requests to be logged, expressed as a fraction in range(0,1].""" + + +PredictRequestResponseLoggingConfigOrDict = Union[ + PredictRequestResponseLoggingConfig, PredictRequestResponseLoggingConfigDict +] + + +class PSCAutomationConfig(_common.BaseModel): + """PSC config that is used to automatically create PSC endpoints in the user projects.""" + + error_message: Optional[str] = Field( + default=None, + description="""Output only. Error message if the PSC service automation failed.""", + ) + forwarding_rule: Optional[str] = Field( + default=None, + description="""Output only. Forwarding rule created by the PSC service automation.""", + ) + ip_address: Optional[str] = Field( + default=None, + description="""Output only. IP address rule created by the PSC service automation.""", + ) + network: Optional[str] = Field( + default=None, + description="""Required. The full name of the Google Compute Engine [network](https://cloud.google.com/compute/docs/networks-and-firewalls#networks). [Format](https://cloud.google.com/compute/docs/reference/rest/v1/networks/get): `projects/{project}/global/networks/{network}`.""", + ) + project_id: Optional[str] = Field( + default=None, + description="""Required. Project id used to create forwarding rule.""", + ) + state: Optional[PscAutomationState] = Field( + default=None, + description="""Output only. The state of the PSC service automation.""", + ) + + +class PSCAutomationConfigDict(TypedDict, total=False): + """PSC config that is used to automatically create PSC endpoints in the user projects.""" + + error_message: Optional[str] + """Output only. Error message if the PSC service automation failed.""" + + forwarding_rule: Optional[str] + """Output only. Forwarding rule created by the PSC service automation.""" + + ip_address: Optional[str] + """Output only. IP address rule created by the PSC service automation.""" + + network: Optional[str] + """Required. The full name of the Google Compute Engine [network](https://cloud.google.com/compute/docs/networks-and-firewalls#networks). [Format](https://cloud.google.com/compute/docs/reference/rest/v1/networks/get): `projects/{project}/global/networks/{network}`.""" + + project_id: Optional[str] + """Required. Project id used to create forwarding rule.""" + + state: Optional[PscAutomationState] + """Output only. The state of the PSC service automation.""" + + +PSCAutomationConfigOrDict = Union[PSCAutomationConfig, PSCAutomationConfigDict] + + +class PrivateServiceConnectConfig(_common.BaseModel): + """Represents configuration for private service connect.""" + + enable_private_service_connect: Optional[bool] = Field( + default=None, + description="""Required. If true, expose the IndexEndpoint via private service connect.""", + ) + enable_secure_private_service_connect: Optional[bool] = Field( + default=None, + description="""Optional. If set to true, enable secure private service connect with IAM authorization. Otherwise, private service connect will be done without authorization. Note latency will be slightly increased if authorization is enabled.""", + ) + project_allowlist: Optional[list[str]] = Field( + default=None, + description="""A list of Projects from which the forwarding rule will target the service attachment.""", + ) + psc_automation_configs: Optional[list[PSCAutomationConfig]] = Field( + default=None, + description="""Optional. List of projects and networks where the PSC endpoints will be created. This field is used by Online Inference(Prediction) only.""", + ) + service_attachment: Optional[str] = Field( + default=None, + description="""Output only. The name of the generated service attachment resource. This is only populated if the endpoint is deployed with PrivateServiceConnect.""", + ) + + +class PrivateServiceConnectConfigDict(TypedDict, total=False): + """Represents configuration for private service connect.""" + + enable_private_service_connect: Optional[bool] + """Required. If true, expose the IndexEndpoint via private service connect.""" + + enable_secure_private_service_connect: Optional[bool] + """Optional. If set to true, enable secure private service connect with IAM authorization. Otherwise, private service connect will be done without authorization. Note latency will be slightly increased if authorization is enabled.""" + + project_allowlist: Optional[list[str]] + """A list of Projects from which the forwarding rule will target the service attachment.""" + + psc_automation_configs: Optional[list[PSCAutomationConfigDict]] + """Optional. List of projects and networks where the PSC endpoints will be created. This field is used by Online Inference(Prediction) only.""" + + service_attachment: Optional[str] + """Output only. The name of the generated service attachment resource. This is only populated if the endpoint is deployed with PrivateServiceConnect.""" + + +PrivateServiceConnectConfigOrDict = Union[ + PrivateServiceConnectConfig, PrivateServiceConnectConfigDict +] + + +class Endpoint(_common.BaseModel): + """An endpoint where you deploy models.""" + + dedicated_endpoint_dns: Optional[str] = Field( + default=None, + description="""Output only. DNS of the dedicated endpoint. Will only be populated if dedicated_endpoint_enabled is true. Depending on the features enabled, uid might be a random number or a string. For example, if fast_tryout is enabled, uid will be fasttryout. Format: `https://{endpoint_id}.{region}-{uid}.prediction.vertexai.goog`.""", + ) + dedicated_endpoint_enabled: Optional[bool] = Field( + default=None, + description="""If true, the endpoint will be exposed through a dedicated DNS [Endpoint.dedicated_endpoint_dns]. Your request to the dedicated DNS will be isolated from other users' traffic and will have better performance and reliability. Note: Once you enabled dedicated endpoint, you won't be able to send request to the shared DNS {region}-aiplatform.googleapis.com. The limitation will be removed soon.""", + ) + deployed_models: Optional[list[DeployedModel]] = Field( + default=None, + description="""Output only. The models deployed in this Endpoint. To add or remove DeployedModels use EndpointService.DeployModel and EndpointService.UndeployModel respectively.""", + ) + description: Optional[str] = Field( + default=None, description="""The description of the Endpoint.""" + ) + display_name: Optional[str] = Field( + default=None, + description="""Required. The display name of the Endpoint. The name can be up to 128 characters long and can consist of any UTF-8 characters.""", + ) + name: Optional[str] = Field( + default=None, description="""Identifier. The resource name of the Endpoint.""" + ) + traffic_split: Optional[dict[str, int]] = Field( + default=None, + description="""A map from a DeployedModel's ID to the percentage of this Endpoint's traffic that should be forwarded to that DeployedModel. If a DeployedModel's ID is not listed in this map, then it receives no traffic. The traffic percentage values must add up to 100, or map must be empty if the Endpoint is to not accept any traffic at a moment.""", + ) + client_connection_config: Optional[ClientConnectionConfig] = Field( + default=None, + description="""Configurations that are applied to the endpoint for online prediction.""", + ) + create_time: Optional[datetime.datetime] = Field( + default=None, + description="""Output only. Timestamp when this Endpoint was created.""", + ) + enable_private_service_connect: Optional[bool] = Field( + default=None, + description="""Deprecated: If true, expose the Endpoint via private service connect. Only one of the fields, network or enable_private_service_connect, can be set.""", + ) + encryption_spec: Optional[genai_types.EncryptionSpec] = Field( + default=None, + description="""Customer-managed encryption key spec for an Endpoint. If set, this Endpoint and all sub-resources of this Endpoint will be secured by this key.""", + ) + etag: Optional[str] = Field( + default=None, + description="""Used to perform consistent read-modify-write updates. If not set, a blind "overwrite" update happens.""", + ) + gdc_config: Optional[GdcConfig] = Field( + default=None, + description="""Configures the Google Distributed Cloud (GDC) environment for online prediction. Only set this field when the Endpoint is to be deployed in a GDC environment.""", + ) + gen_ai_advanced_features_config: Optional[GenAiAdvancedFeaturesConfig] = Field( + default=None, + description="""Optional. Configuration for GenAiAdvancedFeatures. If the endpoint is serving GenAI models, advanced features like native RAG integration can be configured. Currently, only Model Garden models are supported.""", + ) + labels: Optional[dict[str, str]] = Field( + default=None, + description="""The labels with user-defined metadata to organize your Endpoints. Label keys and values can be no longer than 64 characters (Unicode codepoints), can only contain lowercase letters, numeric characters, underscores and dashes. International characters are allowed. See https://goo.gl/xmQnxf for more information and examples of labels.""", + ) + model_deployment_monitoring_job: Optional[str] = Field( + default=None, + description="""Output only. Resource name of the Model Monitoring job associated with this Endpoint if monitoring is enabled by JobService.CreateModelDeploymentMonitoringJob. Format: `projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}`""", + ) + network: Optional[str] = Field( + default=None, + description="""Optional. The full name of the Google Compute Engine [network](https://cloud.google.com//compute/docs/networks-and-firewalls#networks) to which the Endpoint should be peered. Private services access must already be configured for the network. If left unspecified, the Endpoint is not peered with any network. Only one of the fields, network or enable_private_service_connect, can be set. [Format](https://cloud.google.com/compute/docs/reference/rest/v1/networks/insert): `projects/{project}/global/networks/{network}`. Where `{project}` is a project number, as in `12345`, and `{network}` is network name.""", + ) + predict_request_response_logging_config: Optional[ + PredictRequestResponseLoggingConfig + ] = Field( + default=None, + description="""Configures the request-response logging for online prediction.""", + ) + private_service_connect_config: Optional[PrivateServiceConnectConfig] = Field( + default=None, + description="""Optional. Configuration for private service connect. network and private_service_connect_config are mutually exclusive.""", + ) + satisfies_pzi: Optional[bool] = Field( + default=None, description="""Output only. Reserved for future use.""" + ) + satisfies_pzs: Optional[bool] = Field( + default=None, description="""Output only. Reserved for future use.""" + ) + update_time: Optional[datetime.datetime] = Field( + default=None, + description="""Output only. Timestamp when this Endpoint was last updated.""", + ) + + +class EndpointDict(TypedDict, total=False): + """An endpoint where you deploy models.""" + + dedicated_endpoint_dns: Optional[str] + """Output only. DNS of the dedicated endpoint. Will only be populated if dedicated_endpoint_enabled is true. Depending on the features enabled, uid might be a random number or a string. For example, if fast_tryout is enabled, uid will be fasttryout. Format: `https://{endpoint_id}.{region}-{uid}.prediction.vertexai.goog`.""" + + dedicated_endpoint_enabled: Optional[bool] + """If true, the endpoint will be exposed through a dedicated DNS [Endpoint.dedicated_endpoint_dns]. Your request to the dedicated DNS will be isolated from other users' traffic and will have better performance and reliability. Note: Once you enabled dedicated endpoint, you won't be able to send request to the shared DNS {region}-aiplatform.googleapis.com. The limitation will be removed soon.""" + + deployed_models: Optional[list[DeployedModelDict]] + """Output only. The models deployed in this Endpoint. To add or remove DeployedModels use EndpointService.DeployModel and EndpointService.UndeployModel respectively.""" + + description: Optional[str] + """The description of the Endpoint.""" + + display_name: Optional[str] + """Required. The display name of the Endpoint. The name can be up to 128 characters long and can consist of any UTF-8 characters.""" + + name: Optional[str] + """Identifier. The resource name of the Endpoint.""" + + traffic_split: Optional[dict[str, int]] + """A map from a DeployedModel's ID to the percentage of this Endpoint's traffic that should be forwarded to that DeployedModel. If a DeployedModel's ID is not listed in this map, then it receives no traffic. The traffic percentage values must add up to 100, or map must be empty if the Endpoint is to not accept any traffic at a moment.""" + + client_connection_config: Optional[ClientConnectionConfigDict] + """Configurations that are applied to the endpoint for online prediction.""" + + create_time: Optional[datetime.datetime] + """Output only. Timestamp when this Endpoint was created.""" + + enable_private_service_connect: Optional[bool] + """Deprecated: If true, expose the Endpoint via private service connect. Only one of the fields, network or enable_private_service_connect, can be set.""" + + encryption_spec: Optional[genai_types.EncryptionSpecDict] + """Customer-managed encryption key spec for an Endpoint. If set, this Endpoint and all sub-resources of this Endpoint will be secured by this key.""" + + etag: Optional[str] + """Used to perform consistent read-modify-write updates. If not set, a blind "overwrite" update happens.""" + + gdc_config: Optional[GdcConfigDict] + """Configures the Google Distributed Cloud (GDC) environment for online prediction. Only set this field when the Endpoint is to be deployed in a GDC environment.""" + + gen_ai_advanced_features_config: Optional[GenAiAdvancedFeaturesConfigDict] + """Optional. Configuration for GenAiAdvancedFeatures. If the endpoint is serving GenAI models, advanced features like native RAG integration can be configured. Currently, only Model Garden models are supported.""" + + labels: Optional[dict[str, str]] + """The labels with user-defined metadata to organize your Endpoints. Label keys and values can be no longer than 64 characters (Unicode codepoints), can only contain lowercase letters, numeric characters, underscores and dashes. International characters are allowed. See https://goo.gl/xmQnxf for more information and examples of labels.""" + + model_deployment_monitoring_job: Optional[str] + """Output only. Resource name of the Model Monitoring job associated with this Endpoint if monitoring is enabled by JobService.CreateModelDeploymentMonitoringJob. Format: `projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}`""" + + network: Optional[str] + """Optional. The full name of the Google Compute Engine [network](https://cloud.google.com//compute/docs/networks-and-firewalls#networks) to which the Endpoint should be peered. Private services access must already be configured for the network. If left unspecified, the Endpoint is not peered with any network. Only one of the fields, network or enable_private_service_connect, can be set. [Format](https://cloud.google.com/compute/docs/reference/rest/v1/networks/insert): `projects/{project}/global/networks/{network}`. Where `{project}` is a project number, as in `12345`, and `{network}` is network name.""" + + predict_request_response_logging_config: Optional[ + PredictRequestResponseLoggingConfigDict + ] + """Configures the request-response logging for online prediction.""" + + private_service_connect_config: Optional[PrivateServiceConnectConfigDict] + """Optional. Configuration for private service connect. network and private_service_connect_config are mutually exclusive.""" + + satisfies_pzi: Optional[bool] + """Output only. Reserved for future use.""" + + satisfies_pzs: Optional[bool] + """Output only. Reserved for future use.""" + + update_time: Optional[datetime.datetime] + """Output only. Timestamp when this Endpoint was last updated.""" + + +EndpointOrDict = Union[Endpoint, EndpointDict] + + +class GetEndpointOperationConfig(_common.BaseModel): + + http_options: Optional[genai_types.HttpOptions] = Field( + default=None, description="""Used to override HTTP request options.""" + ) + + +class GetEndpointOperationConfigDict(TypedDict, total=False): + + http_options: Optional[genai_types.HttpOptions] + """Used to override HTTP request options.""" + + +GetEndpointOperationConfigOrDict = Union[ + GetEndpointOperationConfig, GetEndpointOperationConfigDict +] + + +class _GetEndpointOperationParameters(_common.BaseModel): + """Parameters for getting an operation.""" + + operation_name: Optional[str] = Field( + default=None, description="""The server-assigned name for the operation.""" + ) + config: Optional[GetEndpointOperationConfig] = Field( + default=None, description="""Used to override the default configuration.""" + ) + + +class _GetEndpointOperationParametersDict(TypedDict, total=False): + """Parameters for getting an operation.""" + + operation_name: Optional[str] + """The server-assigned name for the operation.""" + + config: Optional[GetEndpointOperationConfigDict] + """Used to override the default configuration.""" + + +_GetEndpointOperationParametersOrDict = Union[ + _GetEndpointOperationParameters, _GetEndpointOperationParametersDict +] + + +class EndpointOperation(_common.BaseModel): + """Operation that has an endpoint as a response.""" + + name: Optional[str] = Field( + default=None, + description="""The server-assigned name, which is only unique within the same service that originally returns it. If you use the default HTTP mapping, the `name` should be a resource name ending with `operations/{unique_id}`.""", + ) + metadata: Optional[dict[str, Any]] = Field( + default=None, + description="""Service-specific metadata associated with the operation. It typically contains progress information and common metadata such as create time. Some services might not provide such metadata. Any method that returns a long-running operation should document the metadata type, if any.""", + ) + done: Optional[bool] = Field( + default=None, + description="""If the value is `false`, it means the operation is still in progress. If `true`, the operation is completed, and either `error` or `response` is available.""", + ) + error: Optional[dict[str, Any]] = Field( + default=None, + description="""The error result of the operation in case of failure or cancellation.""", + ) + response: Optional[Endpoint] = Field( + default=None, description="""The created Endpoint.""" + ) + + +class EndpointOperationDict(TypedDict, total=False): + """Operation that has an endpoint as a response.""" + + name: Optional[str] + """The server-assigned name, which is only unique within the same service that originally returns it. If you use the default HTTP mapping, the `name` should be a resource name ending with `operations/{unique_id}`.""" + + metadata: Optional[dict[str, Any]] + """Service-specific metadata associated with the operation. It typically contains progress information and common metadata such as create time. Some services might not provide such metadata. Any method that returns a long-running operation should document the metadata type, if any.""" + + done: Optional[bool] + """If the value is `false`, it means the operation is still in progress. If `true`, the operation is completed, and either `error` or `response` is available.""" + + error: Optional[dict[str, Any]] + """The error result of the operation in case of failure or cancellation.""" + + response: Optional[EndpointDict] + """The created Endpoint.""" + + +EndpointOperationOrDict = Union[EndpointOperation, EndpointOperationDict] + + +class PromptOptimizerConfig(_common.BaseModel): + """VAPO Prompt Optimizer Config.""" + + config_path: Optional[str] = Field( + default=None, + description="""The gcs path to the config file, e.g. gs://bucket/config.json.""", + ) + service_account: Optional[str] = Field( + default=None, + description="""The service account to use for the custom job. Cannot be provided at the same time as service_account_project_number.""", + ) + service_account_project_number: Optional[Union[int, str]] = Field( + default=None, + description="""The project number used to construct the default service account:{service_account_project_number}-compute@developer.gserviceaccount.comCannot be provided at the same time as "service_account".""", + ) + wait_for_completion: Optional[bool] = Field( + default=True, + description="""Whether to wait for the job tocomplete. Ignored for async jobs.""", + ) + optimizer_job_display_name: Optional[str] = Field( + default=None, + description="""The display name of the optimization job. If not provided, a display name in the format of "vapo-optimizer-{timestamp}" will be used.""", + ) + + +class PromptOptimizerConfigDict(TypedDict, total=False): + """VAPO Prompt Optimizer Config.""" + + config_path: Optional[str] + """The gcs path to the config file, e.g. gs://bucket/config.json.""" + + service_account: Optional[str] + """The service account to use for the custom job. Cannot be provided at the same time as service_account_project_number.""" + + service_account_project_number: Optional[Union[int, str]] + """The project number used to construct the default service account:{service_account_project_number}-compute@developer.gserviceaccount.comCannot be provided at the same time as "service_account".""" + + wait_for_completion: Optional[bool] + """Whether to wait for the job tocomplete. Ignored for async jobs.""" + + optimizer_job_display_name: Optional[str] + """The display name of the optimization job. If not provided, a display name in the format of "vapo-optimizer-{timestamp}" will be used.""" + + +PromptOptimizerConfigOrDict = Union[PromptOptimizerConfig, PromptOptimizerConfigDict] + + +class OptimizeResponse(_common.BaseModel): + """Response for the optimize_prompt method.""" + + raw_text_response: Optional[str] = Field(default=None, description="""""") + parsed_response: Optional["ParsedResponseUnion"] = Field( + default=None, description="""""" + ) + + +class OptimizeResponseDict(TypedDict, total=False): + """Response for the optimize_prompt method.""" + + raw_text_response: Optional[str] + """""" + + parsed_response: Optional["ParsedResponseUnionDict"] + """""" + + +OptimizeResponseOrDict = Union[OptimizeResponse, OptimizeResponseDict] + + +class ContentMapContents(_common.BaseModel): + """Map of placeholder in metric prompt template to contents of model input.""" + + contents: Optional[list[genai_types.Content]] = Field( + default=None, description="""Contents of the model input.""" + ) + + +class ContentMapContentsDict(TypedDict, total=False): + """Map of placeholder in metric prompt template to contents of model input.""" + + contents: Optional[list[genai_types.Content]] + """Contents of the model input.""" + + +ContentMapContentsOrDict = Union[ContentMapContents, ContentMapContentsDict] + + +class EvaluateMethodConfig(_common.BaseModel): + """Optional parameters for the evaluate method.""" + + http_options: Optional[genai_types.HttpOptions] = Field( + default=None, description="""Used to override HTTP request options.""" + ) + dataset_schema: Optional[Literal["GEMINI", "FLATTEN", "OPENAI"]] = Field( + default=None, + description="""The schema to use for the dataset. + If not specified, the dataset schema will be inferred from the first + example in the dataset.""", + ) + dest: Optional[str] = Field( + default=None, description="""The destination path for the evaluation results.""" + ) + evaluation_service_qps: Optional[float] = Field( + default=None, + description="""The rate limit (queries per second) for calls to the + evaluation service. Defaults to 10. Increase this value if your + project has a higher EvaluateInstances API quota.""", + ) + + +class EvaluateMethodConfigDict(TypedDict, total=False): + """Optional parameters for the evaluate method.""" + + http_options: Optional[genai_types.HttpOptions] + """Used to override HTTP request options.""" + + dataset_schema: Optional[Literal["GEMINI", "FLATTEN", "OPENAI"]] + """The schema to use for the dataset. + If not specified, the dataset schema will be inferred from the first + example in the dataset.""" + + dest: Optional[str] + """The destination path for the evaluation results.""" + + evaluation_service_qps: Optional[float] + """The rate limit (queries per second) for calls to the + evaluation service. Defaults to 10. Increase this value if your + project has a higher EvaluateInstances API quota.""" + + +EvaluateMethodConfigOrDict = Union[EvaluateMethodConfig, EvaluateMethodConfigDict] + + +class EvaluateDatasetConfig(_common.BaseModel): + """Config for evaluate instances.""" + + http_options: Optional[genai_types.HttpOptions] = Field( + default=None, description="""Used to override HTTP request options.""" + ) + + +class EvaluateDatasetConfigDict(TypedDict, total=False): + """Config for evaluate instances.""" + + http_options: Optional[genai_types.HttpOptions] + """Used to override HTTP request options.""" + + +EvaluateDatasetConfigOrDict = Union[EvaluateDatasetConfig, EvaluateDatasetConfigDict] + + +class EvaluateDatasetOperation(_common.BaseModel): + + name: Optional[str] = Field( + default=None, + description="""The server-assigned name, which is only unique within the same service that originally returns it. If you use the default HTTP mapping, the `name` should be a resource name ending with `operations/{unique_id}`.""", + ) + metadata: Optional[dict[str, Any]] = Field( + default=None, + description="""Service-specific metadata associated with the operation. It typically contains progress information and common metadata such as create time. Some services might not provide such metadata. Any method that returns a long-running operation should document the metadata type, if any.""", ) done: Optional[bool] = Field( default=None, @@ -25752,49 +27836,6 @@ class ObservabilityEvalCaseDict(TypedDict, total=False): ObservabilityEvalCaseOrDict = Union[ObservabilityEvalCase, ObservabilityEvalCaseDict] -class RubricGroup(_common.BaseModel): - """A group of rubrics. - - Used for grouping rubrics based on a metric or a version. - """ - - group_id: Optional[str] = Field( - default=None, description="""Unique identifier for the group.""" - ) - display_name: Optional[str] = Field( - default=None, - description="""Human-readable name for the group. This should be unique - within a given context if used for display or selection. - Example: "Instruction Following V1", "Content Quality - Summarization - Task".""", - ) - rubrics: Optional[list[evals_types.Rubric]] = Field( - default=None, description="""Rubrics that are part of this group.""" - ) - - -class RubricGroupDict(TypedDict, total=False): - """A group of rubrics. - - Used for grouping rubrics based on a metric or a version. - """ - - group_id: Optional[str] - """Unique identifier for the group.""" - - display_name: Optional[str] - """Human-readable name for the group. This should be unique - within a given context if used for display or selection. - Example: "Instruction Following V1", "Content Quality - Summarization - Task".""" - - rubrics: Optional[list[evals_types.Rubric]] - """Rubrics that are part of this group.""" - - -RubricGroupOrDict = Union[RubricGroup, RubricGroupDict] - - class PromptTemplate(_common.BaseModel): """A prompt template for creating prompts with variables.""" @@ -27119,26 +29160,6 @@ class PromptDict(TypedDict, total=False): PromptOrDict = Union[Prompt, PromptDict] -class SchemaPromptInstanceVariableValue(_common.BaseModel): - """Represents a prompt instance variable.""" - - part_list: Optional[SchemaPromptSpecPartList] = Field( - default=None, description="""The parts of the variable value.""" - ) - - -class SchemaPromptInstanceVariableValueDict(TypedDict, total=False): - """Represents a prompt instance variable.""" - - part_list: Optional[SchemaPromptSpecPartListDict] - """The parts of the variable value.""" - - -SchemaPromptInstanceVariableValueOrDict = Union[ - SchemaPromptInstanceVariableValue, SchemaPromptInstanceVariableValueDict -] - - class CreatePromptConfig(_common.BaseModel): """Config for creating a prompt.""" @@ -27585,7 +29606,7 @@ class ListCustomModelDeployOptionsConfigDict(TypedDict, total=False): class ExportOpenModelConfig(_common.BaseModel): - """Config for ``export_open_model``.""" + """Config for export_open_model.""" wait_for_completion: Optional[bool] = Field( default=True, @@ -27609,7 +29630,7 @@ class ExportOpenModelConfig(_common.BaseModel): class ExportOpenModelConfigDict(TypedDict, total=False): - """Config for ``export_open_model``.""" + """Config for export_open_model.""" wait_for_completion: Optional[bool] """Whether to block on the export long-running operation. When diff --git a/tests/unit/agentplatform/genai/replays/test_endpoints.py b/tests/unit/agentplatform/genai/replays/test_endpoints.py new file mode 100644 index 0000000000..87d0a40faf --- /dev/null +++ b/tests/unit/agentplatform/genai/replays/test_endpoints.py @@ -0,0 +1,80 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# pylint: disable=protected-access,bad-continuation,missing-function-docstring + +from agentplatform._genai import types +from tests.unit.agentplatform.genai.replays import pytest_helper + +pytestmark = pytest_helper.setup( + file=__file__, +) + + +GEMMA_3_ENDPOINT = "endpoints/mg-endpoint-7a076560-158a-4726-89f4-64b01874aac9" +DEDICATED_ENDPOINT = "https://mg-endpoint-7a076560-158a-4726-89f4-64b01874aac9.us-central1-410364378237.prediction.vertexai.goog/" +ENDPOINT_TO_BE_DELETED = ( + "endpoints/mg-endpoint-40845fbb-96d3-4bbd-828f-08ea2003aeba" +) +DEPLOYED_MODEL_ID = "1206978444030640128" + + +def test_get_endpoint(client): + """Test get an endpoint.""" + response = client.endpoints.get(name=ENDPOINT_TO_BE_DELETED) + assert isinstance(response, types.Endpoint) + assert response.dedicated_endpoint_dns + + +def test_predict_gemma3(client): + # Tests prediction on an endpoint which deploys a Gemma 3 model. + response = client.endpoints._predict( + name=GEMMA_3_ENDPOINT, + instances=[{ + "prompt": "Hello world!", + }], + config={ + "http_options": {"base_url": DEDICATED_ENDPOINT, "api_version": "v1"} + }, + ) + assert isinstance(response, types.PredictResponse) + assert response.predictions + + +def test_predict_public_gemma3(client): + # Tests prediction on an endpoint which deploys a Gemma 3 model. + response = client.endpoints.predict( + name=GEMMA_3_ENDPOINT, + instances=[{ + "prompt": "Hello world!", + }], + ) + assert isinstance(response, types.PredictResponse) + assert response.predictions + + +def test_undeploy_model(client): + # Tests undeploy model on an endpoint which deploys a Gemma 3 model. + response = client.endpoints.undeploy( + name=ENDPOINT_TO_BE_DELETED, + deployed_model_id=DEPLOYED_MODEL_ID, + config=types.UndeployModelConfig(wait_for_completion=True), + ) + assert response is None + + +def test_delete_endpoint(client): + # Tests delete endpoint. + response = client.endpoints.delete(name=ENDPOINT_TO_BE_DELETED) + assert response is None