code: def _update_requirements(config: dict) -> dict:
      """
      Generates requirements for DeepPavlov model and adds them as ``metadata.requirements`` field to the returned dict.
  
      Searches for the ``class_name`` keys in the passed config at all nesting levels. For each found component,
      function looks for dependencies in the requirements registry. Found dependencies are added to the returned copy of
      the config as ``metadata.requirements``. If the config already has ``metadata.requirements``, the existing one
      is complemented by the found requirements.
  
      Args:
          config: DeepPavlov model config
      Returns:
          config copy with updated ``metadata.requirements`` field according to the config components.
      """
      components = get_all_elems_from_json(config, "class_name")
      components = {
          inverted_registry.get(component, component)
          for component in components
      }
      requirements_registry_path = (
          Path(__file__).parents[1]
          / "common"
          / "requirements_registry.json"
      )
      requirements_registry = read_json(requirements_registry_path)
      requirements = []
      for component in components:
          requirements.extend(requirements_registry.get(component, []))
      requirements.extend(
          config.get("metadata", {}).get("requirements", [])
      )
      response = deepcopy(config)
      response["metadata"] = response.get("metadata", {})
      response["metadata"]["requirements"] = list(set(requirements))
      return response
  
file_path: DeepPavlov/deeppavlov/core/commands/utils.py
imports: import os
  from copy import deepcopy
  from pathlib import Path
  from typing import Any, Union, Dict, TypeVar, Optional
  from deeppavlov.core.common.file import read_json, find_config
  from deeppavlov.core.common.registry import inverted_registry
  from deeppavlov.core.data.utils import get_all_elems_from_json
label_desc: Use image node_id 3 for calling a global function with example usage: _update_requirements(config) and returns: response