BotBuilder Python-处理多个对话框和意图 [英] BotBuilder Python - Handling multiple dialog and intent

查看:135
本文介绍了BotBuilder Python-处理多个对话框和意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码可以处理多种意图,

I have the following code to handle multiple intents,

代码

async def on_message_activity(self, turn_context: TurnContext):
    recognizer_result = await self.luis.recognize(self.recognizer, turn_context)
    intent = self.luis.get_top_intent(recognizer_result)
    await self.process_intent(turn_context, recognizer_result, intent)

async def process_intent(self, turn_context: TurnContext, recognizer_result, intent):
    if intent == 'Greeting_Wishes':
        await greeting_wishes(turn_context, user_info)
    elif intent == 'Greeting_Question':
        await greeting_question(turn_context)
    elif intent == 'Movement':
        dialog = Movement(recognizer_result)
        await DialogHelper.run_dialog(
            dialog,
            turn_context,
            self.dialog_state
        )

问题

  1. 打招呼工作正常
  2. 移动意图已正确进入已配置的对话框,但在向用户询问了几次输入后,当用户输入其值时,它要么回到问候意图,要么因为意图是None而无处出行
  1. Greeting intent is working fine
  2. Movement intent is properly taking to the configured dialog but after asking a couple of inputs to the user and when the user enters their value it is either going back to greeting intent or going nowhere since the intent is None

有人可以通过对话框帮助处理多个意图吗?

Can someone help how to handle multiple intents with dialogs?

任何帮助将不胜感激!

推荐答案

我最终有了一个主对话框,并根据另一种意图扩展了其他对话框.查看下面的代码示例,

I ended up having one main dialog and extended the other dialogs depending upon the other intent. Look at the code sample below,

async def on_message_activity(self, turn_context: TurnContext):
    recognizer_result = await self.luis.recognize(self.recognizer, turn_context)
    intent = self.luis.get_top_intent(recognizer_result)
    await self.process_intent(turn_context, recognizer_result, intent)

async def process_intent(self, turn_context: TurnContext, recognizer_result, intent):
    if intent == "Greeting_Wishes" and not entity:
        await greeting_wishes(turn_context, user_info)
        return

    if intent == "Greeting_Question" and not entity:
        await greeting_question(turn_context)
        return

    dialog = MainDialog(self.luis, intent, recognizer_result)
    await DialogHelper.run_dialog(
        dialog,
        turn_context,
        self.conversation_state.create_property("DialogState")
    )

main_dialog.py

在主对话框中,我将检查意图并开始适当的对话框.

Within the main dialog, I'll check for the intent and begin the appropriate dialog.

class MainDialog(ComponentDialog):
    def __init__(self, luis, intent, recognizer_result):
        super(MainDialog, self).__init__(MainDialog.__name__)

        self.luis = luis
        self.intent = intent
        self.recognizer_result = recognizer_result

        self.add_dialog(SampleDialog1())
        self.add_dialog(SampleDialog2())
        self.add_dialog(
            WaterfallDialog(
                "main_dialog_id", [self.main_step]
            )
        )

        self.initial_dialog_id = "main_dialog_id"

    async def main_step(self, step_context: WaterfallStepContext) -> DialogTurnResult:
        dialog_detail = self.luis.get_entities(self.intent, self.recognizer_result)
        if self.intent == "one":
            return await step_context.begin_dialog(SampleDialog1.__name__, dialog_detail)
        elif self.intent == "two":
            return await step_context.begin_dialog(SampleDialog2.__name__, dialog_detail)

这篇关于BotBuilder Python-处理多个对话框和意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆