code: def ensure_bytes(
      data: Union[bytes, dict, ServerSentEvent, Any]
  ) -> bytes:
      """
      helper to convert data to bytes
      :param data: data to convert
      :return: bytes
      """
      if isinstance(data, bytes):
          return data
      elif isinstance(data, ServerSentEvent):
          return data.encode()
      elif isinstance(data, dict):
          return ServerSentEvent(**data).encode()
      else:
          return ServerSentEvent(str(data)).encode()
  
imports: import enum
  import io
  import json
  import logging
  import re
  from datetime import datetime
  from functools import partial
  from typing import Any, AsyncIterable, Callable, Coroutine, Dict, Optional, Union
  import anyio
  from starlette.background import BackgroundTask
  from starlette.concurrency import iterate_in_threadpool
  from starlette.responses import Response
  from starlette.types import Receive, Scope, Send
label_desc: Use image node_id 1 for calling a global function with example usage: ensure_bytes(data) and returns: data, data, ServerSentEvent, ServerSentEvent