Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions engine/config/model_config.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#pragma once

#include <json/json.h>
#include <cmath>
#include <iomanip>
#include <limits>
#include <sstream>
#include <string>
#include <vector>
#include "utils/format_utils.h"

namespace config {
struct ModelConfig {
std::string name;
Expand Down Expand Up @@ -173,6 +172,15 @@ 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;
return Json::writeString(wbuilder, obj);
}

Json::Value ToJson() const {
Json::Value obj;

Expand Down
1 change: 0 additions & 1 deletion engine/config/yaml_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <string>

#include "model_config.h"
#include "yaml-cpp/yaml.h"

namespace config {
class YamlHandler {
Expand Down
10 changes: 3 additions & 7 deletions engine/controllers/models.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
7 changes: 2 additions & 5 deletions engine/database/models.cc
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
#include "models.h"
#include <algorithm>
#include <iostream>
#include <sstream>
#include "database.h"
#include "utils/result.hpp"
#include "utils/scope_exit.h"

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() {}

Expand Down
11 changes: 11 additions & 0 deletions engine/utils/cortex_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down