def get_client_options( self, location_override: Optional[str] = None ) -> client_options.ClientOptions: """Creates GAPIC client_options using location and type. Args: location_override (str): Set this parameter to get client options for a location different from location set by initializer. Must be a GCP region supported by AI Platform (Unified). Returns: clients_options (google.api_core.client_options.ClientOptions): A ClientOptions object set with regionalized API endpoint, i.e. { "api_endpoint": "us-central1-aiplatform.googleapis.com" } or { "api_endpoint": "asia-east1-aiplatform.googleapis.com" } """ if not (self.location or location_override): raise ValueError( "No location found. Provide or initialize SDK with a location." ) region = location_override or self.location region = region.lower() utils.validate_region(region) return client_options.ClientOptions( api_endpoint=f"{region}-{constants.API_BASE_PATH}")
def init( self, *, project: Optional[str] = None, location: Optional[str] = None, experiment: Optional[str] = None, experiment_description: Optional[str] = None, staging_bucket: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, encryption_spec_key_name: Optional[str] = None, ): """Updates common initialization parameters with provided options. Args: project (str): The default project to use when making API calls. location (str): The default location to use when making API calls. If not set defaults to us-central-1. experiment (str): The experiment name. experiment_description (str): The description of the experiment. staging_bucket (str): The default staging bucket to use to stage artifacts when making API calls. In the form gs://... credentials (google.auth.credentials.Credentials): The default custom credentials to use when making API calls. If not provided credentials will be ascertained from the environment. encryption_spec_key_name (Optional[str]): Optional. The Cloud KMS resource identifier of the customer managed encryption key used to protect a resource. Has the form: ``projects/my-project/locations/my-region/keyRings/my-kr/cryptoKeys/my-key``. The key needs to be in the same region as where the compute resource is created. If set, this resource and all sub-resources will be secured by this key. """ # reset metadata_service config if project or location is updated. if (project and project != self._project) or ( location and location != self._location): if metadata.metadata_service.experiment_name: logging.info( "project/location updated, reset Metadata config.") metadata.metadata_service.reset() if project: self._project = project if location: utils.validate_region(location) self._location = location if experiment: metadata.metadata_service.set_experiment( experiment=experiment, description=experiment_description) if experiment_description and experiment is None: raise ValueError( "Experiment name needs to be set in `init` in order to add experiment descriptions." ) if staging_bucket: self._staging_bucket = staging_bucket if credentials: self._credentials = credentials if encryption_spec_key_name: self._encryption_spec_key_name = encryption_spec_key_name
def init( self, *, project: Optional[str] = None, location: Optional[str] = None, experiment: Optional[str] = None, staging_bucket: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, encryption_spec_key_name: Optional[str] = None, ): """Updates common initalization parameters with provided options. Args: project (str): The default project to use when making API calls. location (str): The default location to use when making API calls. If not set defaults to us-central-1 experiment (str): The experiment to assign staging_bucket (str): The default staging bucket to use to stage artifacts when making API calls. In the form gs://... credentials (google.auth.crendentials.Credentials): The default custom credentials to use when making API calls. If not provided crendentials will be ascertained from the environment. encryption_spec_key_name (Optional[str]): Optional. The Cloud KMS resource identifier of the customer managed encryption key used to protect a resource. Has the form: ``projects/my-project/locations/my-region/keyRings/my-kr/cryptoKeys/my-key``. The key needs to be in the same region as where the compute resource is created. If set, this resource and all sub-resources will be secured by this key. """ if project: self._project = project if location: utils.validate_region(location) self._location = location if experiment: logging.warning("Experiments currently not supported.") self._experiment = experiment if staging_bucket: self._staging_bucket = staging_bucket if credentials: self._credentials = credentials if encryption_spec_key_name: self._encryption_spec_key_name = encryption_spec_key_name
def common_location_path(self, project: Optional[str] = None, location: Optional[str] = None) -> str: """Get parent resource with optional project and location override. Args: project (str): GCP project. If not provided will use the current project. location (str): Location. If not provided will use the current location. Returns: resource_parent: Formatted parent resource string. """ if location: utils.validate_region(location) return "/".join([ "projects", project or self.project, "locations", location or self.location, ])
def get_client_options( self, location_override: Optional[str] = None, prediction_client: bool = False, api_base_path_override: Optional[str] = None, ) -> client_options.ClientOptions: """Creates GAPIC client_options using location and type. Args: location_override (str): Optional. Set this parameter to get client options for a location different from location set by initializer. Must be a GCP region supported by Vertex AI. prediction_client (str): Optional. flag to use a prediction endpoint. api_base_path_override (str): Optional. Override default API base path. Returns: clients_options (google.api_core.client_options.ClientOptions): A ClientOptions object set with regionalized API endpoint, i.e. { "api_endpoint": "us-central1-aiplatform.googleapis.com" } or { "api_endpoint": "asia-east1-aiplatform.googleapis.com" } """ if not (self.location or location_override): raise ValueError( "No location found. Provide or initialize SDK with a location." ) region = location_override or self.location region = region.lower() utils.validate_region(region) service_base_path = api_base_path_override or ( constants.PREDICTION_API_BASE_PATH if prediction_client else constants.API_BASE_PATH ) return client_options.ClientOptions( api_endpoint=f"{region}-{service_base_path}" )