使用Azure Bot Framework和LUIS.ai识别用户意图。对文本执行对端点的get请求将返回我期望的json对象,但是使用内置的Luis Recognizer我收到以下错误:'无法读取未定义的属性'get'。从此处的文档中:https://docs.microsoft.com/en-us/azure/cognitive-services/luis/luis-nodejs-tutorial-bf-v4这似乎是正确的配置,所以我不确定发生了什么。有任何想法吗?


const { ComponentDialog, DialogSet, DialogTurnStatus, WaterfallDialog, ChoicePrompt, TextPrompt } = require('botbuilder-dialogs');
const { TopLevelDialog, TOP_LEVEL_DIALOG } = require('./topLevelDialog');

const { LuisRecognizer, QnAMaker } = require('botbuilder-ai');
const axios = require('axios');

const MAIN_DIALOG = 'MAIN_DIALOG';
const WATERFALL_DIALOG = 'WATERFALL_DIALOG';
const USER_PROFILE_PROPERTY = 'USER_PROFILE_PROPERTY';
const CHOICE_PROMPT = 'CHOICE_PROMPT';
const TEXT_PROMPT = 'TEXT_PROMPT';


class MainDialog extends ComponentDialog {
    constructor(userState) {
        super(MAIN_DIALOG);
        this.userState = userState;
        this.userProfileAccessor = userState.createProperty(USER_PROFILE_PROPERTY);

        this.addDialog(new TextPrompt(TEXT_PROMPT));
        this.addDialog(new TopLevelDialog());
        this.addDialog(new WaterfallDialog(WATERFALL_DIALOG, [
            this.initialStep.bind(this),
            this.askIfFinishedStep.bind(this),
            this.finalStep.bind(this)
        ]));

        this.initialDialogId = WATERFALL_DIALOG;

        let luisConfig = {
            applicationId: '',
            endpointKey: '',
            endpoint: '',
        };

        this.Luis = new LuisRecognizer(
            luisConfig,
            {
                includeAllIntents: true,
                log: true,
                staging: false
            },
            true
            );

    }

    async run(turnContext, accessor) {
        const dialogSet = new DialogSet(accessor);
        dialogSet.add(this);

        const dialogContext = await dialogSet.createContext(turnContext);
        const results = await dialogContext.continueDialog();
        if (results.status === DialogTurnStatus.empty) {
            await dialogContext.beginDialog(this.id);
        }
    }

    async initialStep(stepContext) {

        let luisAnalysis = await this.Luis.recognize(stepContext);

        let queryString = encodeURIComponent(stepContext.context._activity.text);

        /*
         Ignore this if statement - only in use with the get request
        */
        if(luisResponse.data.topScoringIntent.intent === 'TrainingExpiry' && luisResponse.data.topScoringIntent.score > .75)
        {
            return await stepContext.beginDialog(TOP_LEVEL_DIALOG);
        }
        else
        {
            await stepContext.context.sendActivity("I'm sorry, that is not supported at this time or a high enough intent was not acknowledged.");
            await stepContext.context.sendActivity("Top intent: " + luisResponse.data.topScoringIntent.intent + " Score: " + luisResponse.data.topScoringIntent.score);

            return await stepContext.next();
        }
    }

    async askIfFinishedStep(stepContext) {
        const promptOptions = { prompt: 'Is there anything else I can assist you with?' };

        return await stepContext.prompt(TEXT_PROMPT, promptOptions);
    }

    async finalStep(stepContext) {

        if(stepContext.context._activity.text.toLowerCase() === 'no')
        {
            await stepContext.context.sendActivity("Good bye");

            return await stepContext.endDialog();
        }
        else
        {
            return await stepContext.beginDialog(MAIN_DIALOG);
        }
    }
}

module.exports.MainDialog = MainDialog;
module.exports.MAIN_DIALOG = MAIN_DIALOG;



注意:问题出在我的参数传递给识别器上,正如@billoverton指出的那样。解决方案是传递stepContext.context。

最佳答案

从botbuilder-ai模块查看luisRecognizer.js,该错误是因为识别器期望使用turnContext(具有turnState属性),并且您正在发送stepContext。 turnState在stepContext上不存在,因此get属性失败并导致您的错误。如果您改为发送stepContext.context,则可以解决此问题,即let luisAnalysis = await this.Luis.recognize(stepContext.context);

关于node.js - Azure Bot Framework V4(NodeJS)-LUIS识别器返回错误?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60436192/

10-11 21:19