-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
executable file
·65 lines (52 loc) · 1.78 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#! /usr/bin/env node
import { hideBin } from 'yargs/helpers';
import yargs from 'yargs/yargs';
import ChatBot from './src/ChatBot.js';
import promptSync from 'prompt-sync';
import Markdown from 'markdown-it';
const prompt = promptSync({
autocomplete: getAutoComplete(['!exit', '!reset']),
});
function getAutoComplete(commands) {
return function (partial) {
return commands.filter((c) => c.startsWith(partial));
};
}
const markdown = new Markdown();
(async function () {
console.log(`
Bard - A command-line interface to Google's Bard (https://bard.google.com/)
Repo: github.com/acheong08/Bard
Enter Ctrl+C or type "!exit" to quit.
`);
const argv = yargs(hideBin(process.argv))
.option('session', {
describe: '__Secure-1PSID cookie.',
type: 'string',
demandOption: true,
})
.argv;
const { session } = argv;
const chatbot = new ChatBot(session);
try {
while (true) {
// console.log('You:');
const userPrompt = prompt('You: > ');
if (userPrompt === '!exit' || userPrompt === null || userPrompt === undefined || userPrompt === '') {
console.log('Exiting...');
break;
} else if (userPrompt === '!reset') {
chatbot.conversationId = '';
chatbot.responseId = '';
chatbot.choiceId = '';
continue;
}
// console.log('Google Bard:');
const response = await chatbot.ask(userPrompt);
console.log('Google Bard:',ChatBot.htmlToCommandLine(markdown.render(response.content)) + '\n\n');
}
} catch (error) {
console.error(error.message);
console.log('Exiting...');
}
})();