Exemple #1
0
def test_jsonify(app, skip_encoding, response, expected):
    with app.app_context():
        json_response = None
        if skip_encoding is None:
            json_response = jsonify(response)
        else:
            json_response = jsonify(response, skip_encoding=skip_encoding)

    assert json_response.status_code == HTTPStatus.OK
    assert json_response.get_data() == expected
Exemple #2
0
 def TransformOutput():
     requestJson = get_request()
     logger.debug("REST Request: %s", request)
     response = seldon_core.seldon_methods.transform_output(
         user_model, requestJson, seldon_metrics)
     logger.debug("REST Response: %s", response)
     return jsonify(response)
Exemple #3
0
 def Aggregate():
     requestJson = get_request()
     logger.debug("REST Request: %s", request)
     response = seldon_core.seldon_methods.aggregate(
         user_model, requestJson, seldon_metrics)
     logger.debug("REST Response: %s", response)
     return jsonify(response)
Exemple #4
0
 def SendFeedback():
     requestJson = get_request()
     logger.debug("REST Request: %s", request)
     requestProto = json_to_feedback(requestJson)
     logger.debug("Proto Request: %s", requestProto)
     responseProto = seldon_core.seldon_methods.send_feedback(
         user_model, requestProto, PRED_UNIT_ID, seldon_metrics)
     jsonDict = seldon_message_to_json(responseProto)
     return jsonify(jsonDict)
Exemple #5
0
 def handle_generic_exception(e):
     error = SeldonMicroserviceException(
         message=str(e),
         status_code=500,
         reason="MICROSERVICE_INTERNAL_ERROR")
     response = jsonify(error.to_dict())
     logger.error("%s", error.to_dict())
     response.status_code = error.status_code
     return response
Exemple #6
0
 def Metadata():
     if metadata_data is None:
         # None value represents validation error in current implementation
         # if user_model would not define init_metadata than metadata_data
         # would just contain a default values
         raise SeldonMicroserviceException(
             "Model metadata unavailable",
             status_code=500,
             reason="MICROSERVICE_BAD_METADATA",
         )
     logger.debug("REST Metadata Request")
     logger.debug("REST Metadata Response: %s", metadata_data)
     return jsonify(metadata_data)
Exemple #7
0
    def Predict():
        requestJson = get_request(skip_decoding=PAYLOAD_PASSTHROUGH)
        logger.debug("REST Request: %s", request)
        response = seldon_core.seldon_methods.predict(user_model, requestJson,
                                                      seldon_metrics)

        json_response = jsonify(response, skip_encoding=PAYLOAD_PASSTHROUGH)
        if (isinstance(response, dict) and "status" in response
                and "code" in response["status"]):
            json_response.status_code = response["status"]["code"]

        logger.debug("REST Response: %s", response)
        return json_response
Exemple #8
0
 def handle_invalid_usage(error):
     response = jsonify(error.to_dict())
     logger.error("%s", error.to_dict())
     response.status_code = error.status_code
     return response
Exemple #9
0
 def HealthStatus():
     logger.debug("REST Health Status Request")
     response = seldon_core.seldon_methods.health_status(user_model, seldon_metrics)
     logger.debug("REST Health Status Response: %s", response)
     return jsonify(response)