You can install the console connector @nlpjs/console-connector using:
npm install @nlpjs/console-connector
This is a little bit special component.
It allows you to manage scenarios where the main interface is the console. You can find an example of use on examples/02-qna-classic
.
const { ConsoleConnector } = require('@nlpjs/console-connector');
const connector = new ConsoleConnector();
connector.onHear = (self, text) => {
self.say(`You said "${text}"`);
};
connector.say('Say something!');
You must have a file corpus.json in the source code folder:
const { dockStart } = require('@nlpjs/basic');
(async () => {
const dockConfiguration = {
settings: {
nlp: { corpora: ['./corpus.json'] },
},
use: ['Nlp', 'ConsoleConnector']
};
const dock = await dockStart(dockConfiguration);
const nlp = dock.get('nlp');
await nlp.train();
const connector = dock.get('console');
connector.say('Say something!');
})();