code: def build_experiment_response(
      experiment: Experiment,
      status: str,
      algorithm: dict,
      best_trial: Trial = None,
  ):
      """
      Build the response representing an experiment response object according to the API
      specification.
  
      Parameters
      ----------
      experiment: Experiment
          The experiment to return to the API
      status: str
          The status of the experiment
      algorithm: dict
          The dictionary containing the algorithm's configuration
      best_trial: Trial (Optional)
          The best trial to date of the experiment
  
      Returns
      -------
      A JSON-serializable experiment response object representing the given experiment.
      """
  
      data = {
          "name": experiment.name,
          "version": experiment.version,
          "status": status,
          "trialsCompleted": 0,
          "startTime": None,
          "endTime": None,
          "user": experiment.metadata["user"],
          "orionVersion": experiment.metadata["orion_version"],
          "config": {
              "maxTrials": experiment.max_trials,
              "maxBroken": experiment.max_broken,
              "algorithm": algorithm,
              "space": experiment.configuration["space"],
          },
          "bestTrial": build_trial_response(best_trial)
          if best_trial
          else {},
      }
  
      stats = experiment.stats
      if stats.trials_completed:
          data["trialsCompleted"] = stats.trials_completed
          data["startTime"] = str(stats.start_time)
          data["endTime"] = str(stats.finish_time)
  
      return data
  
file_path: orion/src/orion/serving/responses.py
imports: from typing import List
  from orion.benchmark import Benchmark
  from orion.core.worker.experiment import Experiment
  from orion.core.worker.trial import Trial
label_desc: Use image node_id 2 for calling a global function with example usage: build_experiment_response(experiment, status, algorithm, best_trial) and returns: data