code: def resolve_config(
      cfg: dict,
      config_dir: Optional[Path],
      enable_unsafe_loading: bool = False,
  ) -> dict:
      """
      Resolves artefacts in a config dict. For example x_ref='x_ref.npy' is resolved by loading the np.ndarray from
      the .npy file. For a list of fields that are resolved, see
      https://docs.seldon.io/projects/alibi-detect/en/stable/overview/config_file.html.
  
      Parameters
      ----------
      cfg
          The unresolved config dict.
      config_dir
          Filepath to directory the `config.toml` is located in. Only required if different from the
          runtime directory, and artefacts are specified with filepaths relative to the config.toml file.
      enable_unsafe_loading
          If set to true, allow_pickle=True is set in np.load(). Needed if you have to load objects.
          It has security implications: https://nvd.nist.gov/vuln/detail/cve-2019-6446
  
      Returns
      -------
      The resolved config dict.
      """
      # Convert selected str's to required dtype's (all other type coercion is performed by pydantic)
      _set_dtypes(cfg)
  
      # Before main resolution, update filepaths relative to config file
      if config_dir is not None:
          _prepend_cfg_filepaths(cfg, config_dir)
  
      # Resolve filepaths (load files) and resolve function/object registries
      for key in FIELDS_TO_RESOLVE:
          logger.info("Resolving config field: {}.".format(key))
          src = _get_nested_value(cfg, key)
          obj = None
  
          # Resolve string references to registered objects and filepaths
          if isinstance(src, str):
              # Resolve registry references
              if src.startswith("@"):
                  src = src[1:]
                  if src in registry.get_all():
                      obj = registry.get(src)
                  else:
                      raise ValueError(
                          f"Can't find {src} in the custom function registry, It may be misspelled or missing "
                          "if you have incorrect optional dependencies installed. Make sure the loading environment"
                          " is the same as the saving environment. For more information, check the Installation "
                          "documentation at "
                          "https://docs.seldon.io/projects/alibi-detect/en/stable/overview/getting_started.html."
                      )
                  logger.info(
                      "Successfully resolved registry entry {}".format(
                          src
                      )
                  )
  
              # Resolve dill or numpy file references
              elif Path(src).is_file():
                  if Path(src).suffix == ".dill":
                      obj = dill.load(open(src, "rb"))
                  if Path(src).suffix == ".npy":
                      obj = np.load(
                          src, allow_pickle=enable_unsafe_loading
                      )
  
          # Resolve artefact dicts
          elif isinstance(src, dict):
              backend = cfg.get("backend", Framework.TENSORFLOW)
              if key[-1] in ("model", "proj"):
                  obj = _load_model_config(src)
              elif key[-1] == "embedding":
                  obj = _load_embedding_config(src)
              elif key[-1] == "tokenizer":
                  obj = _load_tokenizer_config(src)
              elif key[-1] == "optimizer":
                  obj = _load_optimizer_config(src, backend)
              elif key[-1] == "preprocess_fn":
                  obj = _load_preprocess_config(src)
              elif key[-1] in ("kernel", "x_kernel", "c_kernel"):
                  obj = _load_kernel_config(src, backend)
  
          # Put the resolved function into the cfg dict
          if obj is not None:
              _set_nested_value(cfg, key, obj)
  
      return cfg
  
imports: import logging
  import os
  from functools import partial
  from importlib import import_module
  from pathlib import Path
  from typing import Any, Callable, Optional, Union, Type, TYPE_CHECKING
  import dill
  import numpy
  import toml
  from transformers import AutoTokenizer
  from alibi_detect.saving.registry import registry
  from alibi_detect.saving._tensorflow import load_detector_legacy, load_embedding_tf, load_kernel_config_tf, load_model_tf, load_optimizer_tf, prep_model_and_emb_tf, get_tf_dtype
  from alibi_detect.saving._pytorch import load_embedding_pt, load_kernel_config_pt, load_model_pt, load_optimizer_pt, prep_model_and_emb_pt, get_pt_dtype
  from alibi_detect.saving._keops import load_kernel_config_ke
  from alibi_detect.saving._sklearn import load_model_sk
  from alibi_detect.saving.validate import validate_config
  from alibi_detect.base import Detector, ConfigurableDetector, StatefulDetectorOnline
  from alibi_detect.utils.frameworks import has_tensorflow, has_pytorch, Framework
  from alibi_detect.saving.schemas import supported_models_tf, supported_models_torch
  from alibi_detect.utils.missing_optional_dependency import import_optional
label_desc: Use image node_id 14 for calling a global function with example usage: resolve_config(cfg, config_dir, enable_unsafe_loading) and returns: cfg