technician1 commited on
Commit
a18eebf
1 Parent(s): 914ba40

Upload ChatIPC.cpp

Browse files
Files changed (1) hide show
  1. ChatIPC.cpp +9 -9
ChatIPC.cpp CHANGED
@@ -1138,7 +1138,7 @@ static void save_kb_binary(const KnowledgeBase &kb, const std::string &fname){
1138
  }
1139
  }
1140
 
1141
- static void load_kb_binary(KnowledgeBase &kb, const std::string &fname, int cli_dict_depth){
1142
  std::ifstream ifs(fname, std::ios::binary);
1143
  if (!ifs) throw std::runtime_error("cannot open load file");
1144
 
@@ -1242,8 +1242,8 @@ static void load_kb_binary(KnowledgeBase &kb, const std::string &fname, int cli_
1242
  }
1243
  }
1244
 
1245
- if (cli_dict_depth != static_cast<int>(file_def_depth)){
1246
- kb.set_def_depth(cli_dict_depth);
1247
 
1248
  std::vector<StrPtr> targets;
1249
  targets.reserve(ptrs.size() + kb.next.size() * 2);
@@ -1279,7 +1279,7 @@ static void load_kb_binary(KnowledgeBase &kb, const std::string &fname, int cli_
1279
  }
1280
  }
1281
 
1282
- static void print_usage(const char *p){
1283
  std::cout << "CLI options: [--response-max-length N] [--save FILE] [--load-kb FILE] [--dictionary-depth D] [--learn f1 f2 ...] [--repeat-penalty P] [--help]\n";
1284
  std::cout << " --response-max-length N Maximum number of tokens in a response.\n";
1285
  std::cout << " --save-kb FILE Save the knowledge-base to a binary file.\n";
@@ -1296,18 +1296,18 @@ int main(int argc, char **argv){
1296
  std::string savefile;
1297
  std::string load_txt;
1298
  std::string load_kb;
1299
- int dict_depth = 3;
1300
  int n_gram_size = 3;
1301
  double repeat_penalty = 0.7; // default 位
1302
  std::vector<std::string> learn_files;
1303
 
1304
  for (int i=1;i<argc;++i){
1305
  std::string a = argv[i];
1306
- if (a=="--help"){ print_usage(argv[0]); return 0; }
1307
  if (a=="--response-max-length" && i+1<argc){ response_maxlen = std::stoul(argv[++i]); continue; }
1308
  if (a=="--save-kb" && i+1<argc){ savefile = argv[++i]; continue; }
1309
  if (a=="--load-kb" && i+1<argc){ load_kb = argv[++i]; continue; }
1310
- if (a=="--dictionary-depth" && i+1<argc){ dict_depth = std::stoi(argv[++i]); continue; }
1311
  if (a=="--n-gram" && i+1<argc){ n_gram_size = std::max(1, std::stoi(argv[++i])); continue; }
1312
  if (a=="--repeat-penalty" && i+1<argc){ repeat_penalty = std::stod(argv[++i]); continue; }
1313
  if (a=="--learn"){
@@ -1321,11 +1321,11 @@ int main(int argc, char **argv){
1321
 
1322
  global_dictionary_entries = parse_dictionary_json();
1323
  build_def_tokens_cache();
1324
- kb.set_def_depth(dict_depth);
1325
 
1326
  if (!load_kb.empty()){
1327
  try { std::cerr << "Loading knowledge base: " << load_kb << "\n";
1328
- load_kb_binary(kb, load_kb, dict_depth); std::cerr << "Loaded knowledge base: " << load_kb << "\n"; }
1329
  catch (const std::exception &e){ std::cerr << "Error: " << e.what() << "\n"; }
1330
  }
1331
 
 
1138
  }
1139
  }
1140
 
1141
+ static void load_kb_binary(KnowledgeBase &kb, const std::string &fname, int cli_def_depth){
1142
  std::ifstream ifs(fname, std::ios::binary);
1143
  if (!ifs) throw std::runtime_error("cannot open load file");
1144
 
 
1242
  }
1243
  }
1244
 
1245
+ if (cli_def_depth != static_cast<int>(file_def_depth)){
1246
+ kb.set_def_depth(cli_def_depth);
1247
 
1248
  std::vector<StrPtr> targets;
1249
  targets.reserve(ptrs.size() + kb.next.size() * 2);
 
1279
  }
1280
  }
1281
 
1282
+ static void print_commands(const char *p){
1283
  std::cout << "CLI options: [--response-max-length N] [--save FILE] [--load-kb FILE] [--dictionary-depth D] [--learn f1 f2 ...] [--repeat-penalty P] [--help]\n";
1284
  std::cout << " --response-max-length N Maximum number of tokens in a response.\n";
1285
  std::cout << " --save-kb FILE Save the knowledge-base to a binary file.\n";
 
1296
  std::string savefile;
1297
  std::string load_txt;
1298
  std::string load_kb;
1299
+ int def_depth = 3;
1300
  int n_gram_size = 3;
1301
  double repeat_penalty = 0.7; // default 位
1302
  std::vector<std::string> learn_files;
1303
 
1304
  for (int i=1;i<argc;++i){
1305
  std::string a = argv[i];
1306
+ if (a=="--help"){ print_commands(argv[0]); return 0; }
1307
  if (a=="--response-max-length" && i+1<argc){ response_maxlen = std::stoul(argv[++i]); continue; }
1308
  if (a=="--save-kb" && i+1<argc){ savefile = argv[++i]; continue; }
1309
  if (a=="--load-kb" && i+1<argc){ load_kb = argv[++i]; continue; }
1310
+ if (a=="--dictionary-depth" && i+1<argc){ def_depth = std::stoi(argv[++i]); continue; }
1311
  if (a=="--n-gram" && i+1<argc){ n_gram_size = std::max(1, std::stoi(argv[++i])); continue; }
1312
  if (a=="--repeat-penalty" && i+1<argc){ repeat_penalty = std::stod(argv[++i]); continue; }
1313
  if (a=="--learn"){
 
1321
 
1322
  global_dictionary_entries = parse_dictionary_json();
1323
  build_def_tokens_cache();
1324
+ kb.set_def_depth(def_depth);
1325
 
1326
  if (!load_kb.empty()){
1327
  try { std::cerr << "Loading knowledge base: " << load_kb << "\n";
1328
+ load_kb_binary(kb, load_kb, def_depth); std::cerr << "Loaded knowledge base: " << load_kb << "\n"; }
1329
  catch (const std::exception &e){ std::cerr << "Error: " << e.what() << "\n"; }
1330
  }
1331