Design and style fixes, better to not decide for users
This commit is contained in:
parent
8701b58276
commit
96b6806e1c
1 changed files with 16 additions and 14 deletions
|
@ -116,8 +116,6 @@ void process_escapes(std::string& input) {
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json get_json(std::string file_name) {
|
nlohmann::json get_json(std::string file_name) {
|
||||||
// safeguard since we expose this fucntion in header
|
|
||||||
if (file_name.find(".json") == file_name.npos) file_name += ".json";
|
|
||||||
nlohmann::json config;
|
nlohmann::json config;
|
||||||
std::fstream jstream(file_name);
|
std::fstream jstream(file_name);
|
||||||
if (jstream.is_open()) {
|
if (jstream.is_open()) {
|
||||||
|
@ -143,15 +141,14 @@ bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
|
||||||
std::vector<char*> arguments_w_json;
|
std::vector<char*> arguments_w_json;
|
||||||
arguments_w_json.push_back(argv[0]);
|
arguments_w_json.push_back(argv[0]);
|
||||||
int pos = 1;
|
int pos = 1;
|
||||||
|
// only the second argument to reduce reading attempts (plus drag'n'drop)
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
std::string json_name = argv[1];
|
|
||||||
// console arguments should override json values, so json processing goes first
|
// console arguments should override json values, so json processing goes first
|
||||||
// to avoid exta work, let's expect at least an extention
|
std::string json_name = argv[1];
|
||||||
if (json_name.rfind(".json") != json_name.npos) {
|
nlohmann::json file_config = get_json(argv[1]);
|
||||||
nlohmann::json file_config = get_json(argv[1]);
|
pos = 2; // avoid putting file name into arguments
|
||||||
// avoid putting file name in arguments
|
if (!file_config.empty()) {
|
||||||
pos = 2;
|
|
||||||
for (auto& p : file_config.items()) {
|
for (auto& p : file_config.items()) {
|
||||||
// only use strings, numbers and booleans for switches
|
// only use strings, numbers and booleans for switches
|
||||||
if (p.value().is_string() || p.value().is_number() || p.value().is_boolean()) {
|
if (p.value().is_string() || p.value().is_number() || p.value().is_boolean()) {
|
||||||
|
@ -159,10 +156,14 @@ bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
|
||||||
strcpy(key, p.key().c_str());
|
strcpy(key, p.key().c_str());
|
||||||
arguments_w_json.push_back(key);
|
arguments_w_json.push_back(key);
|
||||||
std::string param_value;
|
std::string param_value;
|
||||||
if (!p.value().is_boolean()){
|
|
||||||
if (p.value().is_string()) param_value = p.value().get<std::string>();
|
if (!p.value().is_boolean()) {
|
||||||
else if (p.value().is_number()) param_value = std::to_string(p.value().get<float>());
|
if (p.value().is_string()) {
|
||||||
|
param_value = p.value().get<std::string>();
|
||||||
|
} else if (p.value().is_number()) {
|
||||||
|
param_value = std::to_string(p.value().get<float>()); // nlohmann::json can't just get numbers as strings, float works fine for int values
|
||||||
|
}
|
||||||
|
|
||||||
char* val = new char[param_value.length() + 1];
|
char* val = new char[param_value.length() + 1];
|
||||||
strcpy(val, param_value.c_str());
|
strcpy(val, param_value.c_str());
|
||||||
arguments_w_json.push_back(val);
|
arguments_w_json.push_back(val);
|
||||||
|
@ -170,12 +171,13 @@ bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = pos; i < argc; i++) {
|
for (int i = pos; i < argc; i++) {
|
||||||
arguments_w_json.push_back(argv[i]);
|
arguments_w_json.push_back(argv[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int argc_json = arguments_w_json.size();
|
int argc_json = arguments_w_json.size();
|
||||||
char** argv_json = &arguments_w_json[0];
|
char** argv_json = &arguments_w_json[0];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue