Simplified file reading, fixed an oversight
This commit is contained in:
parent
96b6806e1c
commit
872d004b64
2 changed files with 11 additions and 19 deletions
|
@ -115,25 +115,17 @@ void process_escapes(std::string& input) {
|
|||
input.resize(output_idx);
|
||||
}
|
||||
|
||||
nlohmann::json get_json(std::string file_name) {
|
||||
nlohmann::json config;
|
||||
std::fstream jstream(file_name);
|
||||
if (jstream.is_open()) {
|
||||
nlohmann::json get_json(std::string& file_name) noexcept {
|
||||
try {
|
||||
config = nlohmann::json::parse(jstream);
|
||||
jstream.close();
|
||||
printf("Opened a json file %s\n", file_name.c_str());
|
||||
printf("Opening a json file %s\n", file_name.c_str());
|
||||
std::ifstream jstream(file_name);
|
||||
return nlohmann::json::parse(jstream);
|
||||
}
|
||||
catch (nlohmann::json::parse_error& ex) {
|
||||
jstream.close();
|
||||
catch (const std::exception& ex) {
|
||||
fprintf(stderr, "%s\n", ex.what());
|
||||
return config;
|
||||
}
|
||||
} else {
|
||||
printf("%s not found!\n", file_name.c_str());
|
||||
}
|
||||
|
||||
return config;
|
||||
return {};
|
||||
}
|
||||
|
||||
bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
|
||||
|
@ -145,7 +137,7 @@ bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
|
|||
if (argc > 1) {
|
||||
// console arguments should override json values, so json processing goes first
|
||||
std::string json_name = argv[1];
|
||||
nlohmann::json file_config = get_json(argv[1]);
|
||||
nlohmann::json file_config = get_json(json_name);
|
||||
pos = 2; // avoid putting file name into arguments
|
||||
if (!file_config.empty()) {
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@ struct gpt_params {
|
|||
std::string image = ""; // path to an image file
|
||||
};
|
||||
|
||||
nlohmann::json get_json(std::string file_name);
|
||||
nlohmann::json get_json(std::string& file_name) noexcept;
|
||||
|
||||
bool gpt_params_parse_ex(int argc, char ** argv, gpt_params & params);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue