def _encode_selected_predictions_csv(predictions, ordered_keys_list):
    """Encode predictions in csv format.

    For each prediction, the order of the content is determined by 'ordered_keys_list'.

    :param predictions: output of serve_utils.get_selected_predictions(...) (list of dict)
    :param ordered_keys_list: list of selected content keys (list of str)
    :return: predictions in csv response format (str)
    """
    def _generate_single_csv_line_selected_prediction(predictions, ordered_keys_list):
        """Generate a single csv line response for selectable inference predictions

        :param predictions: output of serve_utils.get_selected_predictions(...) (list of dict)
        :param ordered_keys_list: list of selected content keys (list of str)
        :return: yields a single csv row for each prediction (generator)
        """
        for single_prediction in predictions:
            values = []
            for key in ordered_keys_list:
                if isinstance(single_prediction[key], list):
                    value = '"{}"'.format(single_prediction[key])
                else:
                    value = str(single_prediction[key])
                values.append(value)
            yield ','.join(values)

    return '\n'.join(_generate_single_csv_line_selected_prediction(predictions, ordered_keys_list))