Skip to content

Latest commit

 

History

History
48 lines (36 loc) · 1.13 KB

console-connector.md

File metadata and controls

48 lines (36 loc) · 1.13 KB

@nlpjs/console-connector

Installation

You can install the console connector @nlpjs/console-connector using:

    npm install @nlpjs/console-connector

Example of use inside NLP.js

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.

Example of use of the package

const { ConsoleConnector } = require('@nlpjs/console-connector');

const connector = new ConsoleConnector();
connector.onHear = (self, text) => {
  self.say(`You said "${text}"`);
};
connector.say('Say something!');

Example of use with @nlpjs/basic

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!');
})();