code: def write_file(
      path: Union[str, Path],
      content: Union[str, bytes],
      mode: str = "w",
  ):
      """Writes content to a file, creating any necessary directories.
  
      Args:
        path: The file path to write to
        content: The content to write.
        mode: The mode to open the file in. Defaults to 'w'.
  
      Raises:
        ValueError: If an invalid mode is provided.
      """
      os.makedirs(os.path.dirname(path), exist_ok=True)
      with open(path, mode) as f:
          f.write(content)
  
file_path: model-card-toolkit/model_card_toolkit/utils/io_utils.py
imports: import os
  from pathlib import Path
  from typing import Union
  from google.protobuf.message import Message
label_desc: Use image node_id 2 for calling a global function with example usage: write_file(path, content, mode) without return types