code: def save_detector_legacy(detector, filepath):
      detector_name = detector.meta["name"]
  
      # save metadata
      logger.info("Saving metadata and detector to {}".format(filepath))
  
      with open(filepath.joinpath("meta.dill"), "wb") as f:
          dill.dump(detector.meta, f)
  
      # save detector specific parameters
      if isinstance(detector, OutlierAE):
          state_dict = state_ae(detector)
      elif isinstance(detector, OutlierVAE):
          state_dict = state_vae(detector)
      elif isinstance(detector, Mahalanobis):
          state_dict = state_mahalanobis(detector)
      elif isinstance(detector, IForest):
          state_dict = state_iforest(detector)
      elif isinstance(detector, ChiSquareDrift):
          (
              state_dict,
              model,
              embed,
              embed_args,
              tokenizer,
          ) = state_chisquaredrift(detector)
      elif isinstance(detector, ClassifierDrift):
          (
              state_dict,
              clf_drift,
              model,
              embed,
              embed_args,
              tokenizer,
          ) = state_classifierdrift(detector)
      elif isinstance(detector, TabularDrift):
          (
              state_dict,
              model,
              embed,
              embed_args,
              tokenizer,
          ) = state_tabulardrift(detector)
      elif isinstance(detector, KSDrift):
          (
              state_dict,
              model,
              embed,
              embed_args,
              tokenizer,
          ) = state_ksdrift(detector)
      elif isinstance(detector, MMDDrift):
          (
              state_dict,
              model,
              embed,
              embed_args,
              tokenizer,
          ) = state_mmddrift(detector)
      elif isinstance(detector, OutlierAEGMM):
          state_dict = state_aegmm(detector)
      elif isinstance(detector, OutlierVAEGMM):
          state_dict = state_vaegmm(detector)
      elif isinstance(detector, AdversarialAE):
          state_dict = state_adv_ae(detector)
      elif isinstance(detector, ModelDistillation):
          state_dict = state_adv_md(detector)
      elif not isinstance(
          OutlierProphet, MissingDependency
      ) and isinstance(detector, OutlierProphet):
          state_dict = state_prophet(detector)
      elif isinstance(detector, SpectralResidual):
          state_dict = state_sr(detector)
      elif isinstance(detector, OutlierSeq2Seq):
          state_dict = state_s2s(detector)
      elif isinstance(detector, LLR):
          state_dict = state_llr(detector)
      else:
          raise NotImplementedError(
              "The %s detector does not have a legacy save method."
              % detector_name
          )
  
      with open(filepath.joinpath(detector_name + ".dill"), "wb") as f:
          dill.dump(state_dict, f)
  
      # save detector specific TensorFlow models
      model_dir = filepath.joinpath("model")
      if isinstance(detector, OutlierAE):
          save_tf_ae(detector, filepath)
      elif isinstance(detector, OutlierVAE):
          save_tf_vae(detector, filepath)
      elif isinstance(
          detector,
          (
              ChiSquareDrift,
              ClassifierDrift,
              KSDrift,
              MMDDrift,
              TabularDrift,
          ),
      ):
          if model is not None:
              save_model(model, model_dir, filename="encoder")
          if embed is not None:
              save_embedding_legacy(embed, embed_args, filepath)
          if tokenizer is not None:
              tokenizer.save_pretrained(filepath.joinpath("model"))
          if detector_name == "ClassifierDriftTF":
              save_model(clf_drift, model_dir, filename="clf_drift")
      elif isinstance(detector, OutlierAEGMM):
          save_tf_aegmm(detector, filepath)
      elif isinstance(detector, OutlierVAEGMM):
          save_tf_vaegmm(detector, filepath)
      elif isinstance(detector, AdversarialAE):
          save_tf_ae(detector, filepath)
          save_model(detector.model, model_dir)
          save_tf_hl(detector.model_hl, filepath)
      elif isinstance(detector, ModelDistillation):
          save_model(
              detector.distilled_model,
              model_dir,
              filename="distilled_model",
          )
          save_model(detector.model, model_dir, filename="model")
      elif isinstance(detector, OutlierSeq2Seq):
          save_tf_s2s(detector, filepath)
      elif isinstance(detector, LLR):
          save_tf_llr(detector, filepath)
  
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 6 for calling a global function with example usage: save_detector_legacy(detector, filepath) without return types