class_docstr: Class for interacting with CAIP Prediction service.
class_docstr_tok: ["Class","for","interacting","with","CAIP","Prediction","service","."]
docstr: Deletes a model from Google Cloud AI Platform if exists.
  
  Args:
    ai_platform_serving_args: Dictionary containing arguments for pushing to
      AI Platform. For the full set of parameters supported, refer to
      https://cloud.google.com/ml-engine/reference/rest/v1/projects.models
    model_version_name: Version of the CAIP model being deleted. Required if
      delete_model_endpoint is False, otherwise not needed.
    delete_model_endpoint: If True, deletes the CAIP model, which
      automatically deletes all model versions. If False, deletes only the
      model version with model_version_name.
  
  Raises:
    RuntimeError: if an error is encountered when trying to delete.
docstr_tok: ["Deletes","a","model","from","Google","Cloud","AI","Platform","if","exists",".","Args",":","ai_platform_serving_args",":","Dictionary","containing","arguments","for","pushing","to","AI","Platform",".","For","the","full","set","of","parameters","supported",",","refer","to","https",":","\/\/cloud.google.com\/ml-engine\/reference\/rest\/v1\/projects.models","model_version_name",":","Version","of","the","CAIP","model","being","deleted",".","Required","if","delete_model_endpoint","is","False",",","otherwise","not","needed",".","delete_model_endpoint",":","If","True",",","deletes","the","CAIP","model",",","which","automatically","deletes","all","model","versions",".","If","False",",","deletes","only","the","model","version","with","model_version_name",".","Raises",":","RuntimeError",":","if","an","error","is","encountered","when","trying","to","delete","."]
code: def delete_model_from_aip_if_exists(
      self,
      ai_platform_serving_args: Dict[str, Any],
      model_version_name: Optional[str] = None,
      delete_model_endpoint: Optional[bool] = False,
  ) -> None:
      """Deletes a model from Google Cloud AI Platform if exists.
  
      Args:
        ai_platform_serving_args: Dictionary containing arguments for pushing to
          AI Platform. For the full set of parameters supported, refer to
          https://cloud.google.com/ml-engine/reference/rest/v1/projects.models
        model_version_name: Version of the CAIP model being deleted. Required if
          delete_model_endpoint is False, otherwise not needed.
        delete_model_endpoint: If True, deletes the CAIP model, which
          automatically deletes all model versions. If False, deletes only the
          model version with model_version_name.
  
      Raises:
        RuntimeError: if an error is encountered when trying to delete.
      """
      model_name = ai_platform_serving_args["model_name"]
      project_id = ai_platform_serving_args["project_id"]
  
      if delete_model_endpoint:
          logging.info(
              "Deleting model with from AI Platform: %s",
              ai_platform_serving_args,
          )
          name = "projects/{}/models/{}".format(project_id, model_name)
          try:
              operation = (
                  self._client.projects()
                  .models()
                  .delete(name=name)
                  .execute()
              )
              self._wait_for_operation(
                  operation, "projects.models.delete"
              )
          except errors.HttpError as e:
              # If the error is to delete an non-existent model, it's ok to ignore.
              if e.resp.status == 404:
                  logging.warn("Model %s does not exist", model_name)
              else:
                  raise RuntimeError(
                      "Deleting model from AI Platform failed."
                  ) from e
      else:
          if model_version_name is None:
              raise ValueError(
                  "model_version_name is required if"
                  " delete_model_endpoint is False"
              )
          logging.info(
              "Deleting model version %s from AI Platform: %s",
              model_version_name,
              ai_platform_serving_args,
          )
          version_name = "projects/{}/models/{}/versions/{}".format(
              project_id, model_name, model_version_name
          )
          try:
              operation = (
                  self._client.projects()
                  .models()
                  .versions()
                  .delete(name=version_name)
                  .execute()
              )
              self._wait_for_operation(
                  operation, "projects.models.versions.delete"
              )
          except errors.HttpError as e:
              # If the error is to delete an non-existent model version,
              # it's ok to ignore.
              if e.resp.status == 404:
                  logging.warn(
                      "Model version %s does not exist", version_name
                  )
              if e.resp.status == 400:
                  logging.warn(
                      "Model version %s won't be deleted because it is the "
                      "default version and not the only version in the model",
                      version_name,
                  )
              else:
                  raise RuntimeError(
                      "Deleting model version {} from AI Platform failed.".format(
                          version_name
                      )
                  ) from e
  
imports: import abc
  import sys
  import time
  from typing import Any, Dict, Optional, Union
  from absl import logging
  from google.cloud import aiplatform
  from googleapiclient import discovery
  from googleapiclient import errors
  import tensorflow
label_desc: Use image node_id 5 for calling the CAIPTfxPredictionClient obj's underlying member method code with example usage: obj.delete_model_from_aip_if_exists(ai_platform_serving_args, model_version_name, delete_model_endpoint) without return types