diff --git a/engine/config/model_config.h b/engine/config/model_config.h index 044fd8dd3..1db945afb 100644 --- a/engine/config/model_config.h +++ b/engine/config/model_config.h @@ -1,13 +1,12 @@ #pragma once #include -#include -#include #include #include #include #include #include "utils/format_utils.h" + namespace config { struct ModelConfig { std::string name; @@ -173,6 +172,16 @@ struct ModelConfig { tp = json["tp"].asInt(); } } + + std::string ToJsonString() const { + auto obj = ToJson(); + obj["id"] = obj["model"].asString(); + Json::StreamWriterBuilder wbuilder; + wbuilder.settings_["precision"] = 2; + std::string document = Json::writeString(wbuilder, obj); + return document; + } + Json::Value ToJson() const { Json::Value obj; diff --git a/engine/config/yaml_config.h b/engine/config/yaml_config.h index 87b9083a1..fe3bf4d02 100644 --- a/engine/config/yaml_config.h +++ b/engine/config/yaml_config.h @@ -4,7 +4,6 @@ #include #include "model_config.h" -#include "yaml-cpp/yaml.h" namespace config { class YamlHandler { diff --git a/engine/controllers/models.cc b/engine/controllers/models.cc index 888983d7c..c51bb3b77 100644 --- a/engine/controllers/models.cc +++ b/engine/controllers/models.cc @@ -224,13 +224,9 @@ void Models::GetModel(const HttpRequestPtr& req, .string()); auto model_config = yaml_handler.GetModelConfig(); - ret = model_config.ToJson(); - - ret["id"] = model_config.model; - ret["object"] = "model"; - ret["result"] = "OK"; - auto resp = cortex_utils::CreateCortexHttpJsonResponse(ret); - resp->setStatusCode(k200OK); + auto ret = model_config.ToJsonString(); + auto resp = cortex_utils::CreateCortexHttpTextAsJsonResponse(ret); + resp->setStatusCode(drogon::k200OK); callback(resp); } catch (const std::exception& e) { std::string message = diff --git a/engine/database/models.cc b/engine/database/models.cc index b7988e949..3e81fbab2 100644 --- a/engine/database/models.cc +++ b/engine/database/models.cc @@ -1,6 +1,5 @@ #include "models.h" #include -#include #include #include "database.h" #include "utils/result.hpp" @@ -8,11 +7,9 @@ namespace cortex::db { -Models::Models() : db_(cortex::db::Database::GetInstance().db()) { -} +Models::Models() : db_(cortex::db::Database::GetInstance().db()) {} -Models::Models(SQLite::Database& db) : db_(db) { -} +Models::Models(SQLite::Database& db) : db_(db) {} Models::~Models() {} diff --git a/engine/utils/cortex_utils.h b/engine/utils/cortex_utils.h index 50c927365..eb142d6b5 100644 --- a/engine/utils/cortex_utils.h +++ b/engine/utils/cortex_utils.h @@ -43,6 +43,17 @@ inline drogon::HttpResponsePtr CreateCortexHttpResponse() { return res; } +inline drogon::HttpResponsePtr CreateCortexHttpTextAsJsonResponse( + const std::string& data) { + auto res = drogon::HttpResponse::newHttpResponse(); + res->setBody(data); + res->setContentTypeCode(drogon::CT_APPLICATION_JSON); +#if defined(_WIN32) + res->addHeader("date", GetDateRFC1123()); +#endif + return res; +}; + inline drogon::HttpResponsePtr CreateCortexHttpJsonResponse( const Json::Value& data) { auto res = drogon::HttpResponse::newHttpJsonResponse(data);