nlp.js
nlp.js copied to clipboard
Is there any alternative for onIntent() in pipeline.md?
According to the v4 docs, logic can be added to an intent by using onIntent() in the pipelines.md file. I wanted to know if there is any alternative for that. I have a use case where this might not be feasible.
Use Case:
I want to do some database querying based on the intent that has been identified. For this I will have to import additional packages and do a good amount of processing. Can I do all this in pipelines.md file under the onIntent() method? What is the alternative?
Hello,
In this same example try this index.js:
const { dockStart } = require('@nlpjs/basic');
function onIntent(nlp, input) {
if (input.intent === 'joke.chucknorris') {
const output = input;
output.answer = 'this has been modified';
}
return input;
}
(async () => {
const dock = await dockStart();
const nlp = dock.get('nlp');
nlp.onIntent = onIntent;
let result = await nlp.process('Who are you?');
console.log(result.answer);
result = await nlp.process('Tell me a chuck norris joke');
console.log(result.answer);
})();
Unfortunatelly, having a programatically onIntent function, overrides the pipelines.md, I mean, if you want to have some intents processed in your javascript files and other ones in the pipelines.md, this is not possible, as soon as you override this onIntent event, it does not trigger the code in the pipelines.md.
Hi @jesus-seijas-sp
How can I implement the same example using
` const { containerBootstrap } = require('../packages/core-loader/src');
function onIntent(nlp, input) { console.log(nlp, input) if (input.intent === 'joke.chucknorris') { const output = input; output.answer = 'this has been modified'; } return input; }
(async () => {
await containerBootstrap().start();
})(); `
I've tried with nlp = containerBootstrap().get('nlp');
but it can't attach this nlp.onIntent or maybe I'm doing something wrong.
Edit:
Found the solution
`const { containerBootstrap} = require('../packages/core-loader/src');
const onCustomIntent = (nlp, input) => { console.log(123, nlp, input) if (input.intent === 'joke.chucknorris') { const output = input; output.answer = 'this has been modified'; } return input; }
(async () => {
const container = containerBootstrap(); await container.start();
container.get('nlp').onIntent = onCustomIntent; })(); `
There are also actions thgat are intent specific methjod athat also can be used ...
Closing due to inactivity. Please, re-open if you think the topic is still alive.