code: def extract_deployments_from_serve_dag(
      serve_dag_root: DAGNode,
  ) -> List[Deployment]:
      """Extract deployment python objects from a transformed serve DAG. Should
      only be called after `transform_ray_dag_to_serve_dag`, otherwise nothing
      to return.
  
      Args:
          serve_dag_root: Transformed serve dag root node.
      Returns:
          deployments (List[Deployment]): List of deployment python objects
              fetched from serve dag.
      """
      deployments = OrderedDict()
  
      def extractor(dag_node):
          if isinstance(
              dag_node, (DeploymentNode, DeploymentFunctionNode)
          ):
              deployment = dag_node._deployment
              # In case same deployment is used in multiple DAGNodes
              deployments[deployment.name] = deployment
          return dag_node
  
      serve_dag_root.apply_recursive(extractor)
  
      return list(deployments.values())
  
imports: import inspect
  from collections import OrderedDict
  from typing import List
  from ray.dag import ClassNode, DAGNode
  from ray.dag.function_node import FunctionNode
  from ray.dag.utils import _DAGNodeNameGenerator
  from ray.experimental.gradio_utils import type_to_string
  from ray.serve._private.constants import RAY_SERVE_ENABLE_NEW_HANDLE_API, SERVE_DEFAULT_APP_NAME
  from ray.serve._private.deployment_executor_node import DeploymentExecutorNode
  from ray.serve._private.deployment_function_executor_node import DeploymentFunctionExecutorNode
  from ray.serve._private.deployment_function_node import DeploymentFunctionNode
  from ray.serve._private.deployment_node import DeploymentNode
  from ray.serve.deployment import Deployment, schema_to_deployment
  from ray.serve.handle import DeploymentHandle, RayServeHandle
  from ray.serve.schema import DeploymentSchema
label_desc: Use image node_id 4 for calling a global function with example usage: extract_deployments_from_serve_dag(serve_dag_root) and returns: list, dag_node