From 73bbd741350820d2e23946f5f43bec399b15f066 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 2 Dec 2024 11:20:39 +0700 Subject: [PATCH] fix: floating point for models endpoint --- engine/controllers/models.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/engine/controllers/models.cc b/engine/controllers/models.cc index af8061269..2760663d0 100644 --- a/engine/controllers/models.cc +++ b/engine/controllers/models.cc @@ -12,6 +12,14 @@ #include "utils/logging_utils.h" #include "utils/string_utils.h" +namespace { +std::string ToJsonStringWithPrecision(Json::Value& input, int precision = 2) { + Json::StreamWriterBuilder wbuilder; + wbuilder.settings_["precision"] = 2; + return Json::writeString(wbuilder, input); +} +} // namespace + void Models::PullModel(const HttpRequestPtr& req, std::function&& callback) { if (!http_util::HasFieldInReq(req, callback, "model")) { @@ -182,9 +190,11 @@ void Models::ListModel( << model_entry.path_to_model_yaml << ", error: " << e.what(); } } + ret["data"] = data; ret["result"] = "OK"; - auto resp = cortex_utils::CreateCortexHttpJsonResponse(ret); + auto ret_str = ToJsonStringWithPrecision(ret); + auto resp = cortex_utils::CreateCortexHttpTextAsJsonResponse(ret_str); resp->setStatusCode(k200OK); callback(resp); } else {