def prediction_helper(messages):
    'Processes PubSub messages and calls AI Platform prediction.\n\n    :param messages:\n    :return:\n    '
    if (not isinstance(messages, list)):
        messages = [messages]
    instances = list(map((lambda message: json.loads(message)), messages))
    scores = get_sentiment([instance['text'] for instance in instances if instance.get('text')])
    if (len(scores) == len(instances)):
        for (i, instance) in enumerate(instances):
            logging.info('Processed {} instances.'.format(len(instances)))
            instance['sentiment'] = scores[i]
        return instances
    logging.error('Invalid scores {} instances {}'.format(len(scores), len(instances)))
    logging.error(instances)
    return
Processes PubSub messages and calls AI Platform prediction.

:param messages:
:return:
def prediction_helper(messages):
    'Processes PubSub messages and calls AI Platform prediction.\n\n    :param messages:\n    :return:\n    '
    if (not isinstance(messages, list)):
        messages = [messages]
    instances = list(map((lambda message: json.loads(message)), messages))
    scores = get_sentiment([instance['text'] for instance in instances if instance.get('text')])
    if (len(scores) == len(instances)):
        for (i, instance) in enumerate(instances):
            logging.info('Processed {} instances.'.format(len(instances)))
            instance['sentiment'] = scores[i]
        return instances
    logging.error('Invalid scores {} instances {}'.format(len(scores), len(instances)))
    logging.error(instances)
    return