BotBuilder Python - Handling multiple dialog and intent

白昼怎懂夜的黑 提交于 2020-07-10 07:37:10

问题


I have the following code to handle multiple intents,

Code

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
        )

Problem

  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?

Any help would be appreciated!


回答1:


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)


来源:https://stackoverflow.com/questions/62006308/botbuilder-python-handling-multiple-dialog-and-intent

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