code: def safe_call(func, to_json=True):
      try:
          if to_json:
              bottle.response.content_type = "application/json"
  
          if bottle.request.method in ["DELETE", "POST", "PUT"]:
              if bottle.request.content_type == "application/json":
                  params = bottle.request.json
              else:
                  params = bottle.request.forms
          else:
              # bottle.request.query doesn't decode unicode properly, so do it ourselves
              params = {}
              if bottle.request.query_string != "":
                  for item in bottle.request.query_string.split("&"):
                      key, value = item.split("=", 1)
                      # Replaces "+" with " " and then unquote
                      params[key] = unquote_plus(value)
          start_time = time.time()
          result = func(params)
          end_time = time.time()
          result = json.dumps(result) if to_json else result
          hlog(
              "REQUEST {}: {} seconds, {} bytes".format(
                  bottle.request, end_time - start_time, len(result)
              )
          )
          return result
      except Exception as e:
          import traceback
  
          if not isinstance(e, ValueError):
              traceback.print_exc()
          exc_type, exc_value, exc_traceback = sys.exc_info()
          error_str = (
              "EXCEPTION: "
              + str(e)
              + "\n"
              + "\n".join(traceback.format_tb(exc_traceback))
          )
          return (
              json.dumps({"error": error_str}) if to_json else error_str
          )
  
imports: from urllib.parse import unquote_plus
  import argparse
  import dataclasses
  import json
  import os
  import sys
  import time
  from dacite import from_dict
  import bottle
  from helm.common.authentication import Authentication
  from helm.common.hierarchical_logger import hlog
  from helm.common.request import Request
  from helm.common.perspective_api_request import PerspectiveAPIRequest
  from helm.common.tokenization_request import TokenizationRequest, DecodeRequest
  from .accounts import Account
  from .services.server_service import ServerService
  from .query import Query
label_desc: Use image node_id 1 for calling a global function with example usage: safe_call(func, to_json) and returns: result, unknown