forked from janhq/cortex.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathengines.h
More file actions
88 lines (74 loc) · 2.31 KB
/
engines.h
File metadata and controls
88 lines (74 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#pragma once
#include <SQLiteCpp/Database.h>
#include <json/json.h>
#include <trantor/utils/Logger.h>
#include <optional>
#include <string>
#include <vector>
namespace cortex::db {
struct EngineEntry {
int id;
std::string engine_name;
std::string type;
std::string api_key;
std::string url;
std::string version;
std::string variant;
std::string status;
std::string metadata;
std::string date_created;
std::string date_updated;
Json::Value ToJson() const {
Json::Value root;
Json::Reader reader;
// Convert basic fields
root["id"] = id;
root["engine"] = engine_name;
root["type"] = type;
root["api_key"] = api_key;
root["url"] = url;
root["version"] = version;
root["variant"] = variant;
root["status"] = status;
root["date_created"] = date_created;
root["date_updated"] = date_updated;
// Parse metadata string into JSON object
Json::Value metadataJson;
if (!metadata.empty()) {
bool success = reader.parse(metadata, metadataJson,
false); // false = don't collect comments
if (success) {
root["metadata"] = metadataJson;
} else {
root["metadata"] = Json::Value::null;
}
} else {
root["metadata"] = Json::Value(Json::objectValue); // empty object
}
return root;
}
};
class Engines {
private:
SQLite::Database& db_;
bool IsUnique(const std::vector<EngineEntry>& entries,
const std::string& model_id,
const std::string& model_alias) const;
std::optional<std::vector<EngineEntry>> LoadModelListNoLock() const;
public:
Engines();
Engines(SQLite::Database& db);
~Engines();
std::optional<EngineEntry> UpsertEngine(
const std::string& engine_name, const std::string& type,
const std::string& api_key, const std::string& url,
const std::string& version, const std::string& variant,
const std::string& status, const std::string& metadata);
std::optional<std::vector<EngineEntry>> GetEngines() const;
std::optional<EngineEntry> GetEngineById(int id) const;
std::optional<EngineEntry> GetEngineByNameAndVariant(
const std::string& engine_name,
const std::optional<std::string> variant = std::nullopt) const;
std::optional<std::string> DeleteEngineById(int id);
};
} // namespace cortex::db