SimpCfg: Allow for direct initialization lists based init
This should pave way for having a default chat templates dataset in the code, without needing to load it from a config file, if one doesnt want to. TODO: allow for loading config from json into simpcfg, so that a program which uses llama.cpp can decide, whether it is ok with what is already there in the internal dataset, or allow for loading template info at runtime using the simpcfg's simple text file or additionally include the json code to load template info at runtime from json file.
This commit is contained in:
parent
fe27902964
commit
c0506f94bf
1 changed files with 39 additions and 9 deletions
|
@ -279,16 +279,19 @@ std::string str(std::vector<TypeWithStrSupp> values) {
|
||||||
|
|
||||||
typedef std::variant<std::string, bool, int64_t, double> SimpCfgData;
|
typedef std::variant<std::string, bool, int64_t, double> SimpCfgData;
|
||||||
typedef std::vector<std::string> MultiPart;
|
typedef std::vector<std::string> MultiPart;
|
||||||
|
typedef std::map<std::string, std::map<std::string, SimpCfgData>> SimpCfgMapMapVariant;
|
||||||
|
|
||||||
class SimpCfg {
|
class SimpCfg {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<std::string, std::map<std::string, SimpCfgData>> mapV = {};
|
SimpCfgMapMapVariant mapV = {};
|
||||||
std::regex rInt {R"(^[-+]?\d+$)"};
|
std::regex rInt {R"(^[-+]?\d+$)"};
|
||||||
std::regex rFloat {R"(^[-+]?\d+(?:\.\d+)?(?:[eE][-+]?\d+)?$)"};
|
std::regex rFloat {R"(^[-+]?\d+(?:\.\d+)?(?:[eE][-+]?\d+)?$)"};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
SimpCfg(SimpCfgMapMapVariant defaultMap) : mapV(defaultMap) {}
|
||||||
|
|
||||||
static std::string joiner(const MultiPart& parts) {
|
static std::string joiner(const MultiPart& parts) {
|
||||||
std::stringstream joined;
|
std::stringstream joined;
|
||||||
int iCnt = 0;
|
int iCnt = 0;
|
||||||
|
@ -354,6 +357,8 @@ public:
|
||||||
set_double(group, keyParts, dvalue);
|
set_double(group, keyParts, dvalue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Dump info about the specified group.
|
||||||
|
// If group is empty, then dump info about all groups maintained in this instance.
|
||||||
void dump(const std::string &group) {
|
void dump(const std::string &group) {
|
||||||
for (auto gm: mapV) {
|
for (auto gm: mapV) {
|
||||||
if (!group.empty() && (gm.first != group)) {
|
if (!group.empty() && (gm.first != group)) {
|
||||||
|
@ -604,16 +609,28 @@ void check_strings() {
|
||||||
SimpCfg::locale_restore(sSavedLocale);
|
SimpCfg::locale_restore(sSavedLocale);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
void sc_inited() {
|
||||||
if (argc != 2) {
|
SimpCfg sc = {{
|
||||||
LERRR_LN("USAGE:%s simp.cfg", argv[0]);
|
{"Group1",{
|
||||||
exit(1);
|
{"testkey11", 11},
|
||||||
}
|
{"testkey12", true}
|
||||||
|
}},
|
||||||
|
{"Group2", {
|
||||||
|
{"key21", "val21"},
|
||||||
|
{"key22", 22},
|
||||||
|
{"key23", 2.3}
|
||||||
|
}}
|
||||||
|
}};
|
||||||
|
|
||||||
check_strings();
|
std::cout << "**** sc inited **** " << std::endl;
|
||||||
|
sc.dump("");
|
||||||
|
|
||||||
std::string fname {argv[1]};
|
}
|
||||||
SimpCfg sc;
|
|
||||||
|
void sc_set(const std::string &fname) {
|
||||||
|
|
||||||
|
std::cout << "**** sc set **** " << std::endl;
|
||||||
|
SimpCfg sc = {{}};
|
||||||
sc.load(fname);
|
sc.load(fname);
|
||||||
sc.dump("");
|
sc.dump("");
|
||||||
|
|
||||||
|
@ -646,6 +663,19 @@ int main(int argc, char **argv) {
|
||||||
sc.set_string("testme", {"keyA301", "2"}, "AkashaGanga");
|
sc.set_string("testme", {"keyA301", "2"}, "AkashaGanga");
|
||||||
sc.get_vector<int64_t>("testme", {"keyA300"}, {1, 2, 3});
|
sc.get_vector<int64_t>("testme", {"keyA300"}, {1, 2, 3});
|
||||||
sc.get_vector<std::string>("testme", {"keyA301"}, { "yes 1", "No 2", "very well 3" });
|
sc.get_vector<std::string>("testme", {"keyA301"}, { "yes 1", "No 2", "very well 3" });
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
if (argc != 2) {
|
||||||
|
LERRR_LN("USAGE:%s simp.cfg", argv[0]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
check_strings();
|
||||||
|
sc_inited();
|
||||||
|
std::string fname {argv[1]};
|
||||||
|
sc_set(fname);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue