【问题标题】:Avoiding interruptions from Luis during waterfall dialog (BotFramework v4)在瀑布对话期间避免 Luis 打断 (BotFramework v4)
【发布时间】:2018-10-12 23:26:18
【问题描述】:

如何防止 Luis 在 Bot Framework v4 中触发意图?例如,当向用户询问“你叫什么名字”之类的问题/使用提示时或“你的邮政编码是多少?”

在 v3 中,可以这样做:

var recognizer = new builder.LuisRecognizer(url) 
    .onEnabled(function (context, callback) {
        // LUIS is only ON when there are no tasks pending(e.g. Prompt text) 
        var enabled = context.dialogStack().length === 0; 
        callback(null, enabled); 
    });

(link)

在 v4 中,这是我的识别器:

this.luisRecognizer = new LuisRecognizer({
            applicationId: luisConfig.appId,
            endpoint: luisConfig.getEndpoint(),
            endpointKey: luisConfig.authoringKey
        });

我想我需要将其创建为中间件,检查对话状态是否存在,然后禁用/重新启用 Luis...?

【问题讨论】:

  • 现在,我只是确保将触发不需要的 Luis 意图的话语分配给“无”意图。

标签: node.js botframework azure-language-understanding


【解决方案1】:

在您的主对话框(用于识别 LUIS 意图的那个)中检查您的上下文以查看是否有任何活动对话框:

async onTurn(context) {
    // Create dialog context.
    const dc = await this.dialogs.createContext(context);
    // By checking the incoming Activity type, the bot only calls LUIS in appropriate cases.
    if (context.activity.type === ActivityTypes.Message) {
        // Normalizes all user's text inputs
        const utterance = context.activity.text.trim().toLowerCase();

        // handle conversation interrupts first
        const interrupted = await this.isTurnInterrupted(dc, utterance);
        if (!interrupted) {
            // Continue the current dialog
            const dialogResult = await dc.continueDialog();

            // If no one has responded,
            if (!dc.context.responded) {
                // Examine results from active dialog
                switch (dialogResult.status) {
                    case DialogTurnStatus.empty:
                        // Call to LUIS recognizer to get intent + entities
                        const results = await this.luisRecognizer.recognize(dc.context);
                        // Since the LuisRecognizer was configured to include the raw results, get the `topScoringIntent` as specified by LUIS.
                        const topIntent = results.luisResult.topScoringIntent;

                        switch (topIntent.intent) {
                            case SMALLTALK_INTENT:
                                return await dc.beginDialog(SmallTalkDialog.Name);
                            ...
                        }
                    case DialogTurnStatus.waiting:
                        // The active dialog is waiting for a response from the user, so do nothing
                        break;
                    case DialogTurnStatus.complete:
                        await dc.endDialog();
                        break;
                    default:
                        await dc.cancelAllDialogs();
                        break;
                }
            }
        }
    } else if (context.activity.type === ActivityTypes.ConversationUpdate &&
        context.activity.recipient.id !== context.activity.membersAdded[0].id) {
        // If the Activity is a ConversationUpdate, send a greeting message to the user.
        await context.sendActivity('¡Hola! ¿En qué puedo ayudarte? ?');
    } else if (context.activity.type !== ActivityTypes.ConversationUpdate) {
        // Respond to all other Activity types.
        //await context.sendActivity(`[${ context.activity.type }]-type activity detected.`);
        //await this.authDialog.onTurn(context);
    }
    // Save state changes
    await this.conversationState.saveChanges(context);
  }

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-18
    • 2020-02-21
    • 1970-01-01
    • 2019-11-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多