Commit 路
b1a57ee
1
Parent(s): afcc6b5
Upload ChatIPC.cpp
Browse files- ChatIPC.cpp +14 -8
ChatIPC.cpp
CHANGED
|
@@ -1772,13 +1772,14 @@ 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
|
| 1776 |
-
std::cout << " --save-kb FILE Save the knowledge-base to a binary file.\n";
|
| 1777 |
-
std::cout << " --load-kb FILE Load a previously saved knowledge-base from a binary file.\n";
|
| 1778 |
-
std::cout << " --info-kb FILE Show the dictionary-depth and n-gram max size of a
|
|
|
|
| 1779 |
std::cout << " --dictionary-depth D Set depth of dictionary-definition expansion used during learning.\n";
|
| 1780 |
std::cout << " --n-gram-max-size N Set maximum size of the n-gram where N is the size.\n";
|
| 1781 |
-
std::cout << " --learn f1 f2 ... Learn from
|
| 1782 |
std::cout << " --repeat-penalty P Set penalty for repeated tokens when constructing response (higher values reduce repetition).\n";
|
| 1783 |
std::cout << " --activate-agi Activate the Artificial General Intelligence (AGI) features.\n";
|
| 1784 |
std::cout << " --help Show " << p << " command-line interface options.\n";
|
|
@@ -1793,6 +1794,7 @@ int main(int argc, char **argv){
|
|
| 1793 |
int n_gram_size = 3;
|
| 1794 |
double repeat_penalty = 0.7; // default 位
|
| 1795 |
std::vector<std::string> learn_files;
|
|
|
|
| 1796 |
|
| 1797 |
for (int i=1;i<argc;++i){
|
| 1798 |
std::string a = argv[i];
|
|
@@ -1801,6 +1803,7 @@ int main(int argc, char **argv){
|
|
| 1801 |
if (a=="--save-kb" && i+1<argc){ savefile = argv[++i]; continue; }
|
| 1802 |
if (a=="--load-kb" && i+1<argc){ load_kb = argv[++i]; continue; }
|
| 1803 |
if (a=="--info-kb" && i+1<argc){ print_kb_info(argv[++i]); return 0; }
|
|
|
|
| 1804 |
if (a=="--dictionary-depth" && i+1<argc){ def_depth = std::stoi(argv[++i]); continue; }
|
| 1805 |
if (a=="--n-gram-max-size" && i+1<argc){ n_gram_size = std::max(1, std::stoi(argv[++i])); continue; }
|
| 1806 |
if (a=="--repeat-penalty" && i+1<argc){ repeat_penalty = std::stod(argv[++i]); continue; }
|
|
@@ -1812,7 +1815,10 @@ int main(int argc, char **argv){
|
|
| 1812 |
while(i+1<argc && argv[i+1][0] != '-') learn_files.push_back(argv[++i]);
|
| 1813 |
continue;
|
| 1814 |
}
|
| 1815 |
-
|
|
|
|
|
|
|
|
|
|
| 1816 |
}
|
| 1817 |
|
| 1818 |
KnowledgeBase kb;
|
|
@@ -1837,10 +1843,10 @@ int main(int argc, char **argv){
|
|
| 1837 |
while (std::cout << "> " , std::getline(std::cin, line)){
|
| 1838 |
if (line.empty()){ std::cout << "\n"; continue; }
|
| 1839 |
auto prompt_toks = tokenize_whitespace(line);
|
| 1840 |
-
learn_tokens_ngram(kb, prompt_toks, n_gram_size);
|
| 1841 |
auto resp = construct_response(kb, prompt_toks, response_maxlen, repeat_penalty, n_gram_size);
|
| 1842 |
std::cout << "\n";
|
| 1843 |
-
if (!resp.empty()){learn_tokens_ngram(kb, resp, n_gram_size);}
|
| 1844 |
if (!savefile.empty()){
|
| 1845 |
try { std::cerr << "Saving knowledge base: " << savefile << "\n";
|
| 1846 |
save_kb_binary(kb, savefile); std::cerr << "Saved knowledge base: " << savefile << "\n"; }
|
|
|
|
| 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 when constructing response (higher values reduce repetition).\n";
|
| 1784 |
std::cout << " --activate-agi Activate the Artificial General Intelligence (AGI) features.\n";
|
| 1785 |
std::cout << " --help Show " << p << " command-line interface options.\n";
|
|
|
|
| 1794 |
int n_gram_size = 3;
|
| 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];
|
|
|
|
| 1803 |
if (a=="--save-kb" && i+1<argc){ savefile = argv[++i]; continue; }
|
| 1804 |
if (a=="--load-kb" && i+1<argc){ load_kb = argv[++i]; continue; }
|
| 1805 |
if (a=="--info-kb" && i+1<argc){ print_kb_info(argv[++i]); return 0; }
|
| 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; }
|
|
|
|
| 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]);
|
| 1821 |
+
return 1;
|
| 1822 |
}
|
| 1823 |
|
| 1824 |
KnowledgeBase kb;
|
|
|
|
| 1843 |
while (std::cout << "> " , std::getline(std::cin, line)){
|
| 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()){
|
| 1851 |
try { std::cerr << "Saving knowledge base: " << savefile << "\n";
|
| 1852 |
save_kb_binary(kb, savefile); std::cerr << "Saved knowledge base: " << savefile << "\n"; }
|