首页 > 解决方案 > 从另一个文件(Node.js)中的子对话框获取 Luis“topIntent”

问题描述

我让 Luis 在我的主要 bot.js 文件中工作以获取顶级意图。但我想从他们自己的文件中的其他对话框访问 Luis,由 bot.js 调用:

bot.js:

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

然后在机器人的类中:

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

最后,如果检测到“开始意图”,我们将启动对话框:

await dc.beginDialog(InitialDialog);

在 dialogs/initial/index.js 中:

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

这就是问题所在:当我尝试打电话给 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;

我收到一个错误:

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

知道我在这里做错了什么吗?

标签: node.jsbotframework

解决方案


需要创建luisRecognizer :

    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);

可以在此处找到使用 LUIS 的示例: https ://github.com/Microsoft/BotBuilder-Samples/blob/master/samples/javascript_nodejs/12.nlp-with-luis


推荐阅读