code: def save_model(
      model: tf.keras.Model,
      filepath: Union[str, os.PathLike],
      filename: str = "model",
      save_format: Literal["tf", "h5"] = "h5",
  ) -> None:  # TODO - change to tf, later PR
      """
      Save TensorFlow model.
  
      Parameters
      ----------
      model
          The tf.keras.Model to save.
      filepath
          Save directory.
      filename
          Name of file to save to within the filepath directory.
      save_format
          The format to save to. 'tf' to save to the newer SavedModel format, 'h5' to save to the lighter-weight
          legacy hdf5 format.
      """
      # create folder to save model in
      model_path = Path(filepath)
      if not model_path.is_dir():
          logger.warning(
              "Directory {} does not exist and is now created.".format(
                  model_path
              )
          )
          model_path.mkdir(parents=True, exist_ok=True)
  
      # save model
      model_path = (
          model_path.joinpath(filename + ".h5")
          if save_format == "h5"
          else model_path
      )
  
      if isinstance(model, tf.keras.Model):
          model.save(model_path, save_format=save_format)
      else:
          raise ValueError(
              "The extracted model to save is not a `tf.keras.Model`. Cannot save."
          )
  
imports: import logging
  import os
  from functools import partial
  from pathlib import Path
  from typing import Any, Callable, Dict, List, Optional, Tuple, Union
  import dill
  import tensorflow
  from tensorflow.keras.layers import Input, InputLayer
  from alibi_detect.ad import AdversarialAE, ModelDistillation
  from alibi_detect.cd import ChiSquareDrift, ClassifierDrift, KSDrift, MMDDrift, TabularDrift
  from alibi_detect.cd.tensorflow import UAE, HiddenOutput
  from alibi_detect.cd.tensorflow.classifier import ClassifierDriftTF
  from alibi_detect.cd.tensorflow.mmd import MMDDriftTF
  from alibi_detect.models.tensorflow import TransformerEmbedding
  from alibi_detect.od import LLR, IForest, Mahalanobis, OutlierAE, OutlierAEGMM, OutlierProphet, OutlierSeq2Seq, OutlierVAE, OutlierVAEGMM, SpectralResidual
  from alibi_detect.utils._types import Literal
  from alibi_detect.utils.tensorflow.kernels import GaussianRBF
  from alibi_detect.utils.missing_optional_dependency import MissingDependency
  from alibi_detect.utils.frameworks import Framework
label_desc: Use image node_id 2 for calling a global function with example usage: save_model(model, filepath, filename, save_format) without return types