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

Commit 273c094

Browse files
authored
Merge pull request #1755 from janhq/j/fix-floating-point-models-api
fix: floating point for models endpoint
2 parents 67e3554 + 73bbd74 commit 273c094

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")) {
@@ -182,9 +190,11 @@ void Models::ListModel(
182190
<< model_entry.path_to_model_yaml << ", error: " << e.what();
183191
}
184192
}
193+
185194
ret["data"] = data;
186195
ret["result"] = "OK";
187-
auto resp = cortex_utils::CreateCortexHttpJsonResponse(ret);
196+
auto ret_str = ToJsonStringWithPrecision(ret);
197+
auto resp = cortex_utils::CreateCortexHttpTextAsJsonResponse(ret_str);
188198
resp->setStatusCode(k200OK);
189199
callback(resp);
190200
} else {

0 commit comments

Comments
 (0)