technician1 commited on
Commit
a884f55
·
1 Parent(s): 6fab79c

Upload ChatIPC.cpp

Browse files
Files changed (1) hide show
  1. ChatIPC.cpp +14 -14
ChatIPC.cpp CHANGED
@@ -828,11 +828,11 @@ static std::string best_candidate_by_similarity(
828
 
829
  static std::vector<std::string> construct_response(KnowledgeBase &kb,
830
  const std::vector<std::string> &prompt_toks,
831
- size_t maxlen,
832
  double repeat_penalty)
833
  {
834
  std::vector<std::string> resp;
835
- if (prompt_toks.empty() || maxlen == 0) return resp;
836
 
837
  auto prompt_ptrs = intern_tokens(kb, prompt_toks);
838
  std::vector<StrPtr> resp_ptrs;
@@ -846,7 +846,7 @@ static std::vector<std::string> construct_response(KnowledgeBase &kb,
846
 
847
  std::string last_printed;
848
 
849
- for (size_t step = 0; step < maxlen; ++step){
850
  NextSet candidates;
851
  bool found = false;
852
  std::string context_tok;
@@ -1156,18 +1156,18 @@ static void load_kb_binary(KnowledgeBase &kb, const std::string &fname, int cli_
1156
  }
1157
 
1158
  static void print_usage(const char *p){
1159
- std::cout << "Usage: " << p << " [--maxlen N] [--save FILE] [--load-kb FILE] [--dictionary-depth D] [--learn f1 f2 ...] [--repeat-penalty P] [--help]\n";
1160
- std::cout << " --maxlen N Maximum number of tokens constructed in a response.\n";
1161
- std::cout << " --save FILE Save the knowledge-base and dictionary expansions to a binary file.\n";
1162
- std::cout << " --load-kb FILE Load a previously saved knowledge-base (and dictionary expansions) from a binary file.\n";
1163
- std::cout << " --dictionary-depth D Depth of dictionary-definition expansion used during learning.\n";
1164
- std::cout << " --learn f1 f2 ... Learn from one or more text files to update the knowledge base.\n";
1165
- std::cout << " --repeat-penalty P Penalize repeated tokens during response generation (higher values discourage repetition).\n";
1166
- std::cout << " --help Show command-line interface options for ChatIPC usage.\n";
1167
  }
1168
 
1169
  int main(int argc, char **argv){
1170
- size_t maxlen = 100;
1171
  std::string savefile;
1172
  std::string load_txt;
1173
  std::string load_kb;
@@ -1178,7 +1178,7 @@ int main(int argc, char **argv){
1178
  for (int i=1;i<argc;++i){
1179
  std::string a = argv[i];
1180
  if (a=="--help"){ print_usage(argv[0]); return 0; }
1181
- if (a=="--maxlen" && i+1<argc){ maxlen = std::stoul(argv[++i]); continue; }
1182
  if (a=="--save" && i+1<argc){ savefile = argv[++i]; continue; }
1183
  if (a=="--load-kb" && i+1<argc){ load_kb = argv[++i]; continue; }
1184
  if (a=="--dictionary-depth" && i+1<argc){ dict_depth = std::stoi(argv[++i]); continue; }
@@ -1219,7 +1219,7 @@ int main(int argc, char **argv){
1219
  if (line.empty()){ std::cout << "\n"; continue; }
1220
  auto prompt_toks = tokenize_whitespace(line);
1221
  for (size_t i=1;i<prompt_toks.size();++i) kb.add_pair(prompt_toks[i-1], prompt_toks[i]);
1222
- auto resp = construct_response(kb, prompt_toks, maxlen, repeat_penalty);
1223
  std::cout << "\n";
1224
  if (!resp.empty()){for (size_t i=1;i<resp.size();++i) kb.add_pair(resp[i-1], resp[i]);}
1225
  if (!savefile.empty()){
 
828
 
829
  static std::vector<std::string> construct_response(KnowledgeBase &kb,
830
  const std::vector<std::string> &prompt_toks,
831
+ size_t response_maxlen,
832
  double repeat_penalty)
833
  {
834
  std::vector<std::string> resp;
835
+ if (prompt_toks.empty() || response_maxlen == 0) return resp;
836
 
837
  auto prompt_ptrs = intern_tokens(kb, prompt_toks);
838
  std::vector<StrPtr> resp_ptrs;
 
846
 
847
  std::string last_printed;
848
 
849
+ for (size_t step = 0; step < response_maxlen; ++step){
850
  NextSet candidates;
851
  bool found = false;
852
  std::string context_tok;
 
1156
  }
1157
 
1158
  static void print_usage(const char *p){
1159
+ std::cout << "Usage: " << p << " [--response-max-length N] [--save FILE] [--load-kb FILE] [--dictionary-depth D] [--learn f1 f2 ...] [--repeat-penalty P] [--help]\n";
1160
+ std::cout << " --response-max-length N Maximum number of tokens constructed in a response.\n";
1161
+ std::cout << " --save FILE Save the knowledge-base and dictionary expansions to a binary file.\n";
1162
+ std::cout << " --load-kb FILE Load a previously saved knowledge-base (and dictionary expansions) from a binary file.\n";
1163
+ std::cout << " --dictionary-depth D Depth of dictionary-definition expansion used during learning.\n";
1164
+ std::cout << " --learn f1 f2 ... Learn from one or more text files to update the knowledge base.\n";
1165
+ std::cout << " --repeat-penalty P Penalize repeated tokens during response generation (higher values discourage repetition).\n";
1166
+ std::cout << " --help Show command-line interface options for ChatIPC usage.\n";
1167
  }
1168
 
1169
  int main(int argc, char **argv){
1170
+ size_t response_maxlen = 100;
1171
  std::string savefile;
1172
  std::string load_txt;
1173
  std::string load_kb;
 
1178
  for (int i=1;i<argc;++i){
1179
  std::string a = argv[i];
1180
  if (a=="--help"){ print_usage(argv[0]); return 0; }
1181
+ if (a=="--response-max-length" && i+1<argc){ response_maxlen = std::stoul(argv[++i]); continue; }
1182
  if (a=="--save" && i+1<argc){ savefile = argv[++i]; continue; }
1183
  if (a=="--load-kb" && i+1<argc){ load_kb = argv[++i]; continue; }
1184
  if (a=="--dictionary-depth" && i+1<argc){ dict_depth = std::stoi(argv[++i]); continue; }
 
1219
  if (line.empty()){ std::cout << "\n"; continue; }
1220
  auto prompt_toks = tokenize_whitespace(line);
1221
  for (size_t i=1;i<prompt_toks.size();++i) kb.add_pair(prompt_toks[i-1], prompt_toks[i]);
1222
+ auto resp = construct_response(kb, prompt_toks, response_maxlen, repeat_penalty);
1223
  std::cout << "\n";
1224
  if (!resp.empty()){for (size_t i=1;i<resp.size();++i) kb.add_pair(resp[i-1], resp[i]);}
1225
  if (!savefile.empty()){