Exemplo n.º 1
0
def get_model_response():
    params = request.get_json()
    _logger.info('request params: %s' % params)

    try:
        dialog_context = parse_dataset_param(params, param_name='context')
    except KeyError as e:
        return get_api_error_response(
            'Malformed request, no "%s" param was found' % e.message, 400,
            _logger)
    except ValueError as e:
        return get_api_error_response('Malformed request: %s' % e.message, 400,
                                      _logger)

    emotion = params.get('emotion', DEFAULT_CONDITION)
    if emotion not in EMOTIONS_TYPES:
        return get_api_error_response(
            'Malformed request, emotion param "%s" is not in emotion list %s' %
            (emotion, list(EMOTIONS_TYPES)), 400, _logger)

    response = get_response(dialog_context, emotion)

    if not response:
        _logger.error('No response for context: %s; emotion "%s"' %
                      (dialog_context, emotion))
        return jsonify({}), 200

    _logger.info('Given response: "%s" for context: %s; emotion "%s"' %
                 (response, dialog_context, emotion))

    return jsonify({'response': response}), 200
Exemplo n.º 2
0
def get_model_response():
    params = request.get_json()
    _logger.info('request params: %s' % params)

    try:
        dialog_context = parse_dataset_param(params, param_name='context')
    except KeyError as e:
        return get_api_error_response('Malformed request, no "%s" param was found' % e.message, 400, _logger)
    except ValueError as e:
        return get_api_error_response('Malformed request: %s' % e.message, 400, _logger)

    emotion = params.get('emotion', DEFAULT_CONDITION)
    if emotion not in EMOTIONS_TYPES:
        return get_api_error_response('Malformed request, emotion param "%s" is not in emotion list %s' %
                                      (emotion, list(EMOTIONS_TYPES)), 400, _logger)

    response = get_response(dialog_context, emotion)

    if not response:
        _logger.error('No response for context: %s; emotion "%s"' % (dialog_context, emotion))
        return jsonify({}), 200

    _logger.info('Given response: "%s" for context: %s; emotion "%s"' % (response, dialog_context, emotion))

    return jsonify({'response': response}), 200
Exemplo n.º 3
0
def get_model_response():
    params = request.get_json()
    _logger.info('request params: {}'.format(params))

    try:
        dialog_context = parse_dataset_param(params, param_name='context')
    except KeyError as e:
        return get_api_error_response(
            'Malformed request, no "{}" param was found'.format(e), 400,
            _logger)
    except ValueError as e:
        return get_api_error_response('Malformed request: {}'.format(e), 400,
                                      _logger)

    emotion = params.get('emotion', DEFAULT_CONDITION)
    if emotion not in EMOTIONS_TYPES:
        return get_api_error_response(
            'Malformed request, emotion param "{}" is not in emotion list {}'.
            format(emotion, list(EMOTIONS_TYPES)), 400, _logger)

    response = get_response(dialog_context, emotion)
    _logger.info('Given response: "{}" for context: {}; emotion "{}"'.format(
        response, dialog_context, emotion))

    return jsonify({'response': response}), 200
Exemplo n.º 4
0
def get_model_response():
    params = request.get_json()
    _logger.info('request params: %s' % params)

    try:
        dialog_context = parse_dataset_param(params, param_name='context')
    except KeyError as e:
        return get_api_error_response(
            'Malformed request, no "%s" param was found' % str(e), 400,
            _logger)
    except ValueError as e:
        return get_api_error_response('Malformed request: %s' % str(e), 400,
                                      _logger)

    emotion = params.get('emotion', DEFAULT_CONDITION)
    custom_chatbot = chatbots.get(emotion)

    if emotion not in EMOTIONS_TYPES and not custom_chatbot:
        return get_api_error_response(
            'Malformed request, emotion param "%s" is not in emotion list %s' %
            (emotion, list(EMOTIONS_TYPES)), 400, _logger)
    if custom_chatbot:
        try:
            response = custom_chatbot.make_prediction(dialog_context[-1])[0]
        except IndexError:
            response = "I'm not sure."
    else:
        response = get_response(dialog_context, emotion)

    if not response:
        _logger.error('No response for context: %s; emotion "%s"' %
                      (dialog_context, emotion))
        return jsonify({}), 200

    _logger.info('Given response: "%s" for context: %s; emotion "%s"' %
                 (response, dialog_context, emotion))

    return jsonify({'response': response}), 200
Exemplo n.º 5
0
def on_exception(exception):
    return get_api_error_response(
        'Can\'t process request: {}'.format(exception), 500, _logger)