Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 045762c

Browse files
namchuaisangjanai
authored andcommitted
fix: floating point for models endpoint
1 parent 8749fa0 commit 045762c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

engine/controllers/models.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
#include "utils/logging_utils.h"
1313
#include "utils/string_utils.h"
1414

15+
namespace {
16+
std::string ToJsonStringWithPrecision(Json::Value& input, int precision = 2) {
17+
Json::StreamWriterBuilder wbuilder;
18+
wbuilder.settings_["precision"] = 2;
19+
return Json::writeString(wbuilder, input);
20+
}
21+
} // namespace
22+
1523
void Models::PullModel(const HttpRequestPtr& req,
1624
std::function<void(const HttpResponsePtr&)>&& callback) {
1725
if (!http_util::HasFieldInReq(req, callback, "model")) {
@@ -178,9 +186,11 @@ void Models::ListModel(
178186
<< model_entry.path_to_model_yaml << ", error: " << e.what();
179187
}
180188
}
189+
181190
ret["data"] = data;
182191
ret["result"] = "OK";
183-
auto resp = cortex_utils::CreateCortexHttpJsonResponse(ret);
192+
auto ret_str = ToJsonStringWithPrecision(ret);
193+
auto resp = cortex_utils::CreateCortexHttpTextAsJsonResponse(ret_str);
184194
resp->setStatusCode(k200OK);
185195
callback(resp);
186196
} else {

0 commit comments

Comments
 (0)