diff --git a/engines/python/setup/djl_python/input_parser.py b/engines/python/setup/djl_python/input_parser.py index 4169840bb..af06ca61d 100644 --- a/engines/python/setup/djl_python/input_parser.py +++ b/engines/python/setup/djl_python/input_parser.py @@ -266,6 +266,16 @@ def parse_lmi_default_request_rolling_batch(payload): f"Invalid request payload. Request payload should be a json object specifying the 'inputs' field. Received payload {payload}" ) + if not isinstance(inputs, str): + raise ValueError( + f"Invalid request payload. The 'inputs' field must be a string. Received type {type(inputs)}" + ) + + if len(inputs) == 0: + raise ValueError( + f"Invalid request payload. The 'inputs' field does not contain any content. Received payload {payload}" + ) + parameters = payload.get("parameters", {}) if not isinstance(parameters, dict): raise ValueError( diff --git a/serving/src/main/java/ai/djl/serving/http/InferenceRequestHandler.java b/serving/src/main/java/ai/djl/serving/http/InferenceRequestHandler.java index 308145649..73b98e9de 100644 --- a/serving/src/main/java/ai/djl/serving/http/InferenceRequestHandler.java +++ b/serving/src/main/java/ai/djl/serving/http/InferenceRequestHandler.java @@ -420,7 +420,11 @@ void sendOutput(Output output, ChannelHandlerContext ctx) { // This allows inference update HTTP code. // If this is the first and last chunk, we're in a non-streaming case and can // use default response without chunked transfer encoding + // Note, we have to read the code and message from output AGAIN here. + // They get changed to different values from when we read them at the start of + // this method if (first && !supplier.hasNext()) { + status = new HttpResponseStatus(output.getCode(), output.getMessage()); FullHttpResponse resp = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status); for (Map.Entry entry : output.getProperties().entrySet()) { @@ -433,8 +437,7 @@ void sendOutput(Output output, ChannelHandlerContext ctx) { return; } if (first) { - code = output.getCode(); - status = new HttpResponseStatus(code, output.getMessage()); + status = new HttpResponseStatus(output.getCode(), output.getMessage()); HttpResponse resp = new DefaultHttpResponse(HttpVersion.HTTP_1_1, status); for (Map.Entry entry : output.getProperties().entrySet()) { resp.headers().set(entry.getKey(), entry.getValue());