public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); UsedCarPricePrediction prediction = null; try { UsedCarModel data = JsonConvert.DeserializeObject <UsedCarModel>(requestBody); UsedCarMlModel mlModel = data.ToMlModel(); prediction = _predictionEnginePool.Predict(modelName: "UsedCarsPricePredictionModel", example: mlModel); } catch (Exception e) { log.LogError(e, $"Error trying to estimate the price for {requestBody}"); } return(new OkObjectResult(prediction?.Price)); }
public ActionResult <string> EstimateUsedCarPrice([FromBody] UsedCarViewModel input) { _logger.LogInformation("Trying to estimate price for input: ", JsonConvert.SerializeObject(input)); double price; if (!ModelState.IsValid) { return(BadRequest()); } try { UsedCarPricePrediction prediction = _predictionEnginePool.Predict(input.ToMlModel()); price = prediction.Price; } catch (Exception e) { _logger.LogError(e, "Error in EstimateUsedCarPrice()", e.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } return(Ok(price)); }