Commit 路
927ceb6
1
Parent(s): b56e279
Upload ChatIPC.cpp
Browse files- ChatIPC.cpp +12 -11
ChatIPC.cpp
CHANGED
|
@@ -1358,7 +1358,8 @@ static std::vector<std::string> construct_response(KnowledgeBase &kb,
|
|
| 1358 |
const std::vector<std::string> &prompt_toks,
|
| 1359 |
size_t response_maxlen,
|
| 1360 |
double repeat_penalty,
|
| 1361 |
-
int n_gram_size
|
|
|
|
| 1362 |
{
|
| 1363 |
std::vector<std::string> resp;
|
| 1364 |
if (prompt_toks.empty() || response_maxlen == 0) return resp;
|
|
@@ -1414,7 +1415,7 @@ static std::vector<std::string> construct_response(KnowledgeBase &kb,
|
|
| 1414 |
if (candidates.size() == 1){
|
| 1415 |
std::string only = *candidates[0];
|
| 1416 |
std::string only_key = normalize_dictionary_key(only);
|
| 1417 |
-
if (recent_counts[only_key.empty() ? only : only_key] > 0) break;
|
| 1418 |
|
| 1419 |
resp.push_back(only);
|
| 1420 |
StrPtr ptr = kb.interner.intern(only);
|
|
@@ -1772,15 +1773,16 @@ static void print_kb_info(const std::string &fname) {
|
|
| 1772 |
|
| 1773 |
static void print_commands(const char *p){
|
| 1774 |
std::cout << p << " command-line interface options:\n";
|
| 1775 |
-
std::cout << " --response-max-length N Set maximum number of token(s) in a response.\n";
|
| 1776 |
std::cout << " --save-kb FILE Save the knowledge-base graph to a binary file.\n";
|
| 1777 |
std::cout << " --load-kb FILE Load a previously saved knowledge-base graph from a binary file.\n";
|
| 1778 |
std::cout << " --info-kb FILE Show the dictionary-depth and n-gram max size of a knowledge-base file.\n";
|
| 1779 |
std::cout << " --static-kb Disable learning prompt(s) and response(s) during interactive session.\n";
|
| 1780 |
-
std::cout << " --dictionary-depth D Set depth of dictionary-definition expansion used during learning.\n";
|
| 1781 |
-
std::cout << " --n-gram-max-size N Set maximum size of the n-gram where N is the size.\n";
|
| 1782 |
std::cout << " --learn f1 f2 ... Learn from text file(s) to update the knowledge-base graph.\n";
|
| 1783 |
-
std::cout << " --repeat-penalty P Set penalty for repeated tokens
|
|
|
|
| 1784 |
std::cout << " --activate-agi Activate the Artificial General Intelligence (AGI) features.\n";
|
| 1785 |
std::cout << " --help Show " << p << " command-line interface options.\n";
|
| 1786 |
}
|
|
@@ -1795,6 +1797,7 @@ int main(int argc, char **argv){
|
|
| 1795 |
double repeat_penalty = 0.7; // default 位
|
| 1796 |
std::vector<std::string> learn_files;
|
| 1797 |
bool learn_chat = true;
|
|
|
|
| 1798 |
|
| 1799 |
for (int i=1;i<argc;++i){
|
| 1800 |
std::string a = argv[i];
|
|
@@ -1806,15 +1809,13 @@ int main(int argc, char **argv){
|
|
| 1806 |
if (a=="--static-kb"){ learn_chat = false; continue; }
|
| 1807 |
if (a=="--dictionary-depth" && i+1<argc){ def_depth = std::stoi(argv[++i]); continue; }
|
| 1808 |
if (a=="--n-gram-max-size" && i+1<argc){ n_gram_size = std::max(1, std::stoi(argv[++i])); continue; }
|
|
|
|
| 1809 |
if (a=="--repeat-penalty" && i+1<argc){ repeat_penalty = std::stod(argv[++i]); continue; }
|
|
|
|
| 1810 |
if (a=="--activate-agi"){
|
| 1811 |
std::cerr << "AGI subscription fee is $1,000 CAD per month. To pay the fee, contact Caleb Nwokocha via email cnwokocha@proton.me\n";
|
| 1812 |
return 0;
|
| 1813 |
}
|
| 1814 |
-
if (a=="--learn"){
|
| 1815 |
-
while(i+1<argc && argv[i+1][0] != '-') learn_files.push_back(argv[++i]);
|
| 1816 |
-
continue;
|
| 1817 |
-
}
|
| 1818 |
|
| 1819 |
std::cerr << "Error: Unknown or incomplete command-line option '" << a << "'\n";
|
| 1820 |
print_commands(argv[0]);
|
|
@@ -1844,7 +1845,7 @@ int main(int argc, char **argv){
|
|
| 1844 |
if (line.empty()){ std::cout << "\n"; continue; }
|
| 1845 |
auto prompt_toks = tokenize_whitespace(line);
|
| 1846 |
if (learn_chat) {learn_tokens_ngram(kb, prompt_toks, n_gram_size);}
|
| 1847 |
-
auto resp = construct_response(kb, prompt_toks, response_maxlen, repeat_penalty, n_gram_size);
|
| 1848 |
std::cout << "\n";
|
| 1849 |
if (!resp.empty() && learn_chat){learn_tokens_ngram(kb, resp, n_gram_size);}
|
| 1850 |
if (!savefile.empty()){
|
|
|
|
| 1358 |
const std::vector<std::string> &prompt_toks,
|
| 1359 |
size_t response_maxlen,
|
| 1360 |
double repeat_penalty,
|
| 1361 |
+
int n_gram_size,
|
| 1362 |
+
bool allow_path_loops)
|
| 1363 |
{
|
| 1364 |
std::vector<std::string> resp;
|
| 1365 |
if (prompt_toks.empty() || response_maxlen == 0) return resp;
|
|
|
|
| 1415 |
if (candidates.size() == 1){
|
| 1416 |
std::string only = *candidates[0];
|
| 1417 |
std::string only_key = normalize_dictionary_key(only);
|
| 1418 |
+
if (!allow_path_loops && recent_counts[only_key.empty() ? only : only_key] > 0) break;
|
| 1419 |
|
| 1420 |
resp.push_back(only);
|
| 1421 |
StrPtr ptr = kb.interner.intern(only);
|
|
|
|
| 1773 |
|
| 1774 |
static void print_commands(const char *p){
|
| 1775 |
std::cout << p << " command-line interface options:\n";
|
| 1776 |
+
std::cout << " --response-max-length N Set maximum number of token(s) in a response. Default number is 500.\n";
|
| 1777 |
std::cout << " --save-kb FILE Save the knowledge-base graph to a binary file.\n";
|
| 1778 |
std::cout << " --load-kb FILE Load a previously saved knowledge-base graph from a binary file.\n";
|
| 1779 |
std::cout << " --info-kb FILE Show the dictionary-depth and n-gram max size of a knowledge-base file.\n";
|
| 1780 |
std::cout << " --static-kb Disable learning prompt(s) and response(s) during interactive session.\n";
|
| 1781 |
+
std::cout << " --dictionary-depth D Set depth of dictionary-definition expansion used during learning. Default depth is 3.\n";
|
| 1782 |
+
std::cout << " --n-gram-max-size N Set maximum size of the n-gram where N is the size. Default size is 3.\n";
|
| 1783 |
std::cout << " --learn f1 f2 ... Learn from text file(s) to update the knowledge-base graph.\n";
|
| 1784 |
+
std::cout << " --repeat-penalty P Set penalty for repeated tokens in response. Default penalty is 0.7 (higher values reduce repetition).\n";
|
| 1785 |
+
std::cout << " --allow-path-loops Allow infinite loops if the knowledge-base graph has a circular single-path reference.\n";
|
| 1786 |
std::cout << " --activate-agi Activate the Artificial General Intelligence (AGI) features.\n";
|
| 1787 |
std::cout << " --help Show " << p << " command-line interface options.\n";
|
| 1788 |
}
|
|
|
|
| 1797 |
double repeat_penalty = 0.7; // default 位
|
| 1798 |
std::vector<std::string> learn_files;
|
| 1799 |
bool learn_chat = true;
|
| 1800 |
+
bool allow_path_loops = false;
|
| 1801 |
|
| 1802 |
for (int i=1;i<argc;++i){
|
| 1803 |
std::string a = argv[i];
|
|
|
|
| 1809 |
if (a=="--static-kb"){ learn_chat = false; continue; }
|
| 1810 |
if (a=="--dictionary-depth" && i+1<argc){ def_depth = std::stoi(argv[++i]); continue; }
|
| 1811 |
if (a=="--n-gram-max-size" && i+1<argc){ n_gram_size = std::max(1, std::stoi(argv[++i])); continue; }
|
| 1812 |
+
if (a=="--learn"){ while(i+1<argc && argv[i+1][0] != '-') learn_files.push_back(argv[++i]); continue; }
|
| 1813 |
if (a=="--repeat-penalty" && i+1<argc){ repeat_penalty = std::stod(argv[++i]); continue; }
|
| 1814 |
+
if (a=="--allow-path-loops") { allow_path_loops = true; continue; }
|
| 1815 |
if (a=="--activate-agi"){
|
| 1816 |
std::cerr << "AGI subscription fee is $1,000 CAD per month. To pay the fee, contact Caleb Nwokocha via email cnwokocha@proton.me\n";
|
| 1817 |
return 0;
|
| 1818 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1819 |
|
| 1820 |
std::cerr << "Error: Unknown or incomplete command-line option '" << a << "'\n";
|
| 1821 |
print_commands(argv[0]);
|
|
|
|
| 1845 |
if (line.empty()){ std::cout << "\n"; continue; }
|
| 1846 |
auto prompt_toks = tokenize_whitespace(line);
|
| 1847 |
if (learn_chat) {learn_tokens_ngram(kb, prompt_toks, n_gram_size);}
|
| 1848 |
+
auto resp = construct_response(kb, prompt_toks, response_maxlen, repeat_penalty, n_gram_size, allow_path_loops);
|
| 1849 |
std::cout << "\n";
|
| 1850 |
if (!resp.empty() && learn_chat){learn_tokens_ngram(kb, resp, n_gram_size);}
|
| 1851 |
if (!savefile.empty()){
|