Created
January 28, 2023 16:08
-
-
Save roberto-butti/c0f7da85a5617195a3e992f71dce0aab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { dockStart } = require('@nlpjs/basic'); | |
const fs = require('fs'); | |
(async () => { | |
const dock = await dockStart({ use: ['Basic', 'Qna'], nlu: { useNoneFeature: false } }); | |
const nlp = dock.get('nlp'); | |
await nlp.addCorpus({ filename: './qna.tsv', importer: 'qna', locale: 'en' }); | |
await nlp.train(); | |
console.log("TRAIN DONE"); | |
console.log(""); | |
const readline = require('readline').createInterface({ | |
input: process.stdin, | |
output: process.stdout, | |
}); | |
console.clear() | |
readline.question(`β What is your question? `, async (question) => { | |
console.log("π§ Let me try to answer to your question."); | |
console.log("π Your question is: " + question); | |
const response = await nlp.process('en', question); | |
console.log(response.answer); | |
try { | |
const data = fs.readFileSync('./content/' + response.answer, 'utf8'); | |
console.log('π«π«π«π«π«π«π«π«π«π«π«π«π«') | |
console.log(data); | |
console.log('π«π«π«π«π«π«π«π«π«π«π«π«π«') | |
} catch (err) { | |
console.error(err); | |
} | |
readline.close(); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment