code: def _connect(
      raise_if_no_controller_running: bool = True,
  ) -> ServeControllerClient:
      """Connect to an existing Serve application on this Ray cluster.
  
      If called from within a replica, this will connect to the same Serve
      app that the replica is running in.
  
      Returns:
          ServeControllerClient that encapsulates a Ray actor handle to the
          existing Serve application's Serve Controller. None if there is
          no running Serve controller actor and raise_if_no_controller_running
          is set to False.
      Raises:
          RayServeException: if there is no running Serve controller actor
          and raise_if_no_controller_running is set to True.
      """
  
      # Initialize ray if needed.
      ray._private.worker.global_worker._filter_logs_by_job = False
      if not ray.is_initialized():
          ray.init(namespace=SERVE_NAMESPACE)
  
      # Try to get serve controller if it exists
      try:
          controller = ray.get_actor(
              SERVE_CONTROLLER_NAME, namespace=SERVE_NAMESPACE
          )
      except ValueError:
          if raise_if_no_controller_running:
              raise RayServeException(
                  "There is no Serve instance running on this Ray cluster."
              )
          return
  
      client = ServeControllerClient(
          controller,
      )
      _set_global_client(client)
      return client
  
imports: import contextvars
  import logging
  from dataclasses import dataclass
  from typing import Callable, Optional
  import ray
  from ray.exceptions import RayActorError
  from ray.serve._private.client import ServeControllerClient
  from ray.serve._private.common import ReplicaTag
  from ray.serve._private.constants import SERVE_CONTROLLER_NAME, SERVE_NAMESPACE
  from ray.serve.exceptions import RayServeException
  from ray.serve.grpc_util import RayServegRPCContext
  from ray.util.annotations import DeveloperAPI
label_desc: Use image node_id 5 for calling a global function with example usage: _connect(raise_if_no_controller_running) and returns: client