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

Commit 43dab3b

Browse files
authored
Merge pull request #1743 from janhq/j/fix-rounding-float
fix: rounding float
2 parents 7dd43fb + 7b93a71 commit 43dab3b

File tree

5 files changed

+26
-15
lines changed

5 files changed

+26
-15
lines changed

engine/config/model_config.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#pragma once
22

33
#include <json/json.h>
4-
#include <cmath>
5-
#include <iomanip>
64
#include <limits>
75
#include <sstream>
86
#include <string>
97
#include <vector>
108
#include "utils/format_utils.h"
9+
1110
namespace config {
1211
struct ModelConfig {
1312
std::string name;
@@ -173,6 +172,15 @@ struct ModelConfig {
173172
tp = json["tp"].asInt();
174173
}
175174
}
175+
176+
std::string ToJsonString() const {
177+
auto obj = ToJson();
178+
obj["id"] = obj["model"].asString();
179+
Json::StreamWriterBuilder wbuilder;
180+
wbuilder.settings_["precision"] = 2;
181+
return Json::writeString(wbuilder, obj);
182+
}
183+
176184
Json::Value ToJson() const {
177185
Json::Value obj;
178186

engine/config/yaml_config.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <string>
55

66
#include "model_config.h"
7-
#include "yaml-cpp/yaml.h"
87

98
namespace config {
109
class YamlHandler {

engine/controllers/models.cc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,9 @@ void Models::GetModel(const HttpRequestPtr& req,
224224
.string());
225225
auto model_config = yaml_handler.GetModelConfig();
226226

227-
ret = model_config.ToJson();
228-
229-
ret["id"] = model_config.model;
230-
ret["object"] = "model";
231-
ret["result"] = "OK";
232-
auto resp = cortex_utils::CreateCortexHttpJsonResponse(ret);
233-
resp->setStatusCode(k200OK);
227+
auto ret = model_config.ToJsonString();
228+
auto resp = cortex_utils::CreateCortexHttpTextAsJsonResponse(ret);
229+
resp->setStatusCode(drogon::k200OK);
234230
callback(resp);
235231
} catch (const std::exception& e) {
236232
std::string message =

engine/database/models.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
#include "models.h"
22
#include <algorithm>
3-
#include <iostream>
43
#include <sstream>
54
#include "database.h"
65
#include "utils/result.hpp"
76
#include "utils/scope_exit.h"
87

98
namespace cortex::db {
109

11-
Models::Models() : db_(cortex::db::Database::GetInstance().db()) {
12-
}
10+
Models::Models() : db_(cortex::db::Database::GetInstance().db()) {}
1311

14-
Models::Models(SQLite::Database& db) : db_(db) {
15-
}
12+
Models::Models(SQLite::Database& db) : db_(db) {}
1613

1714
Models::~Models() {}
1815

engine/utils/cortex_utils.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ inline drogon::HttpResponsePtr CreateCortexHttpResponse() {
4343
return res;
4444
}
4545

46+
inline drogon::HttpResponsePtr CreateCortexHttpTextAsJsonResponse(
47+
const std::string& data) {
48+
auto res = drogon::HttpResponse::newHttpResponse();
49+
res->setBody(data);
50+
res->setContentTypeCode(drogon::CT_APPLICATION_JSON);
51+
#if defined(_WIN32)
52+
res->addHeader("date", GetDateRFC1123());
53+
#endif
54+
return res;
55+
};
56+
4657
inline drogon::HttpResponsePtr CreateCortexHttpJsonResponse(
4758
const Json::Value& data) {
4859
auto res = drogon::HttpResponse::newHttpJsonResponse(data);

0 commit comments

Comments
 (0)