Getting the Luis “topIntent” from a child dialog inside another file (Node.js)

主宰稳场 提交于 2020-01-06 11:17:04

问题


I have Luis working in my main bot.js file for top level intents. But i'd like to access Luis from other dialogs that are in their own files, called by bot.js:

bot.js:

const { InitialDialog } = require('./dialogs/initial');    
const INITIAL_DIALOG = 'initialDialog';
const START_INTENT = 'Start';

then in the bot's class:

this.dialogs.add(
    new InitialDialog(
        INITIAL_DIALOG,
        this.userProfileAccessor,
        botConfig
    )
);

and finally, if the "Start intent" is detected we start the dialog:

await dc.beginDialog(InitialDialog);

In dialogs/initial/index.js:

class Initial extends ComponentDialog {
    constructor(dialogId, userProfileAccessor, botConfig) {
 super(dialogId);
}

Here's where it gets problematic: when I try and call Luis:

// Perform a call to LUIS to retrieve results for the user's message.

const results: RecognizerResult = await this.luisRecognizer.recognize(turnContext);

// Since the LuisRecognizer was configured to include the raw results, get the `topScoringIntent` as specified by LUIS.
const topIntent = results.luisResult.topScoringIntent;

I'm getting an error:

[onTurnError]: TypeError: Cannot read property 'recognize' of undefined

Any idea what I'm doing wrong here?


回答1:


The luisRecognizer needs to be created:

    const luisApplication = {
        applicationId: luisConfig.appId,
        endpointKey: luisConfig.subscriptionKey || luisConfig.authoringKey,
        endpoint: luisConfig.getEndpoint()
    };

    // Create configuration for LuisRecognizer's runtime behavior.
    const luisPredictionOptions = {
        includeAllIntents: true,
        log: true,
        staging: false
    };

this.luisRecognizer = new LuisRecognizer(luisApplication, luisPredictionOptions , true);

A sample using LUIS can be found here: https://github.com/Microsoft/BotBuilder-Samples/blob/master/samples/javascript_nodejs/12.nlp-with-luis



来源:https://stackoverflow.com/questions/53232536/getting-the-luis-topintent-from-a-child-dialog-inside-another-file-node-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!