technician1 commited on
Commit
54ffa12
·
1 Parent(s): b2577ea

Upload 2 files

Browse files
Files changed (1) hide show
  1. ChatIPC.cpp +67 -8
ChatIPC.cpp CHANGED
@@ -1514,17 +1514,75 @@ static void load_kb_binary(KnowledgeBase &kb, const std::string &fname, int cli_
1514
  }
1515
  }
1516
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1517
  static void print_commands(const char *p){
1518
- std::cout << "CLI options: [--response-max-length N] [--save FILE] [--load-kb FILE] [--dictionary-depth D] [--learn f1 f2 ...] [--repeat-penalty P] [--activate-agi] [--help]\n";
1519
- std::cout << " --response-max-length N Maximum number of tokens in a response.\n";
1520
  std::cout << " --save-kb FILE Save the knowledge-base to a binary file.\n";
1521
  std::cout << " --load-kb FILE Load a previously saved knowledge-base from a binary file.\n";
1522
- std::cout << " --dictionary-depth D Depth of dictionary-definition expansion used during learning.\n";
1523
- std::cout << " --n-gram N Size of the n-gram where N is the size.\n";
 
1524
  std::cout << " --learn f1 f2 ... Learn from one or more text files to update the knowledge-base.\n";
1525
- std::cout << " --repeat-penalty P Penalize repeated tokens when constructing response (higher values reduce repetition).\n";
1526
  std::cout << " --activate-agi Activate the Artificial General Intelligence (AGI) features.\n";
1527
- std::cout << " --help Show all the Command-Line Interface (CLI) options for using " << p << "\n";
1528
  }
1529
 
1530
  int main(int argc, char **argv){
@@ -1543,12 +1601,13 @@ int main(int argc, char **argv){
1543
  if (a=="--response-max-length" && i+1<argc){ response_maxlen = std::stoul(argv[++i]); continue; }
1544
  if (a=="--save-kb" && i+1<argc){ savefile = argv[++i]; continue; }
1545
  if (a=="--load-kb" && i+1<argc){ load_kb = argv[++i]; continue; }
 
1546
  if (a=="--dictionary-depth" && i+1<argc){ def_depth = std::stoi(argv[++i]); continue; }
1547
- if (a=="--n-gram" && i+1<argc){ n_gram_size = std::max(1, std::stoi(argv[++i])); continue; }
1548
  if (a=="--repeat-penalty" && i+1<argc){ repeat_penalty = std::stod(argv[++i]); continue; }
1549
  if (a=="--activate-agi"){
1550
  std::cerr << "AGI subscription fee is $1,000 CAD per month. To pay the fee, contact Caleb Nwokocha via email cnwokocha@proton.me\n";
1551
- continue;
1552
  }
1553
  if (a=="--learn"){
1554
  while(i+1<argc && argv[i+1][0] != '-') learn_files.push_back(argv[++i]);
 
1514
  }
1515
  }
1516
 
1517
+ static void print_kb_info(const std::string &fname) {
1518
+ std::ifstream ifs(fname, std::ios::binary);
1519
+ if (!ifs) {
1520
+ std::cerr << "Error: cannot open knowledge-base file " << fname << "\n";
1521
+ return;
1522
+ }
1523
+
1524
+ std::cout << "Reckoning knowledge-base "<< fname << " info.\n";
1525
+
1526
+ try {
1527
+ const std::uint64_t magic = read_u64(ifs);
1528
+ if (magic != KB_MAGIC) throw std::runtime_error("bad save file magic");
1529
+
1530
+ const std::uint64_t version = read_u64(ifs);
1531
+ if (version != KB_VERSION) throw std::runtime_error("unsupported save file version");
1532
+
1533
+ const std::uint64_t file_def_depth = read_u64(ifs);
1534
+
1535
+ const std::uint64_t N = read_u64(ifs);
1536
+ if (N > (1ULL << 26)) throw std::runtime_error("save file is corrupted: pool too large");
1537
+
1538
+ // Fast-skip string pool to reach the n-gram graph data
1539
+ for (std::uint64_t i = 0; i < N; ++i){
1540
+ std::uint64_t len = read_u64(ifs);
1541
+ if (len > (1ULL << 30)) throw std::runtime_error("save file is corrupted: string too large");
1542
+ if (len > 0) ifs.seekg(static_cast<std::streamoff>(len), std::ios_base::cur);
1543
+ }
1544
+
1545
+ const std::uint64_t E = read_u64(ifs);
1546
+ if (E > (1ULL << 26)) throw std::runtime_error("save file is corrupted: graph too large");
1547
+
1548
+ std::uint64_t max_ngram = 0;
1549
+ for (std::uint64_t i = 0; i < E; ++i){
1550
+ const std::uint64_t ctx_size = read_u64(ifs);
1551
+ if (ctx_size > (1ULL << 16)) throw std::runtime_error("save file is corrupted: n-gram context too large");
1552
+
1553
+ // The maximum context size stored represents the n-gram size
1554
+ if (ctx_size > max_ngram) max_ngram = ctx_size;
1555
+
1556
+ // Skip the context keys
1557
+ ifs.seekg(static_cast<std::streamoff>(ctx_size * sizeof(std::uint64_t)), std::ios_base::cur);
1558
+
1559
+ const std::uint64_t M = read_u64(ifs);
1560
+ if (M > (1ULL << 26)) throw std::runtime_error("save file is corrupted: graph degree too large");
1561
+
1562
+ // Skip the next-nodes values
1563
+ ifs.seekg(static_cast<std::streamoff>(M * sizeof(std::uint64_t)), std::ios_base::cur);
1564
+ }
1565
+
1566
+ std::cout << fname << " dictionary depth: " << file_def_depth << "\n";
1567
+ std::cout << fname << " n-gram max size: " << max_ngram << "\n";
1568
+
1569
+ } catch (const std::exception &e) {
1570
+ std::cerr << "Error reading knowledge-base info: " << e.what() << "\n";
1571
+ }
1572
+ }
1573
+
1574
  static void print_commands(const char *p){
1575
+ std::cout << p << " command-line interface options:\n";
1576
+ std::cout << " --response-max-length N Set maximum number of tokens in a response.\n";
1577
  std::cout << " --save-kb FILE Save the knowledge-base to a binary file.\n";
1578
  std::cout << " --load-kb FILE Load a previously saved knowledge-base from a binary file.\n";
1579
+ std::cout << " --info-kb FILE Show the dictionary-depth and n-gram max size of a saved knowledge-base.\n";
1580
+ std::cout << " --dictionary-depth D Set depth of dictionary-definition expansion used during learning.\n";
1581
+ std::cout << " --n-gram-max-size N Set maximum size of the n-gram where N is the size.\n";
1582
  std::cout << " --learn f1 f2 ... Learn from one or more text files to update the knowledge-base.\n";
1583
+ std::cout << " --repeat-penalty P Set penalty for repeated tokens when constructing response (higher values reduce repetition).\n";
1584
  std::cout << " --activate-agi Activate the Artificial General Intelligence (AGI) features.\n";
1585
+ std::cout << " --help Show " << p << " command-line interface options.\n";
1586
  }
1587
 
1588
  int main(int argc, char **argv){
 
1601
  if (a=="--response-max-length" && i+1<argc){ response_maxlen = std::stoul(argv[++i]); continue; }
1602
  if (a=="--save-kb" && i+1<argc){ savefile = argv[++i]; continue; }
1603
  if (a=="--load-kb" && i+1<argc){ load_kb = argv[++i]; continue; }
1604
+ if (a=="--info-kb" && i+1<argc){ print_kb_info(argv[++i]); return 0; }
1605
  if (a=="--dictionary-depth" && i+1<argc){ def_depth = std::stoi(argv[++i]); continue; }
1606
+ if (a=="--n-gram-max-size" && i+1<argc){ n_gram_size = std::max(1, std::stoi(argv[++i])); continue; }
1607
  if (a=="--repeat-penalty" && i+1<argc){ repeat_penalty = std::stod(argv[++i]); continue; }
1608
  if (a=="--activate-agi"){
1609
  std::cerr << "AGI subscription fee is $1,000 CAD per month. To pay the fee, contact Caleb Nwokocha via email cnwokocha@proton.me\n";
1610
+ return 0;
1611
  }
1612
  if (a=="--learn"){
1613
  while(i+1<argc && argv[i+1][0] != '-') learn_files.push_back(argv[++i]);