导航如何与LUIS子对话框一起使用? [英] How does navigation work with LUIS subdialogs?

查看:54
本文介绍了导航如何与LUIS子对话框一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题.不幸的是,网络上的所有样本都太浅,不能很好地覆盖这个问题:

I have a question... Unfortunately all the samples on the web are too shallow and don't really cover this well:

我有一个扩展LuisDialog的RootDialog.这个RootDialog负责弄清楚用户想要做什么.可能有很多事情,但其中之一将是启动新订单.为此,RootDialog会将调用转发给NewOrderDialog,NewOrderDialog的职责是弄清楚一些基本细节(用户想订购什么,他想使用哪个地址),最后它将确认命令并返回到RootDialog.

I have a RootDialog that extends the LuisDialog. This RootDialog is responsible for figuring out what the user wants to do. It could be multiple things, but one of them would be initiating a new order. For this, the RootDialog would forward the call to the NewOrderDialog, and the responsibility of the NewOrderDialog would be to figure out some basic details (what does the user want to order, which address does he like to use) and finally it will confirm the order and return back to the RootDialog.

RootDialog的代码非常简单:

The code for the RootDialog is very simple:

[Serializable]
public class RootDialog : LuisDialog<object>
{
    public RootDialog() : base(new LuisService(new LuisModelAttribute(ConfigurationManager.AppSettings["LuisAppId"], ConfigurationManager.AppSettings["LuisAPIKey"], domain: "westus.api.cognitive.microsoft.com")))
    {
    }

    [LuisIntent("Order.Place")]
    public async Task PlaceOrderIntent(IDialogContext context, LuisResult result)
    {
        await context.Forward(new NewOrderDialog(), OnPlaceOrderIntentCompleted, context.Activity, CancellationToken.None);

        context.Wait(MessageReceived);
    }

    private async Task OnPlaceOrderIntentCompleted(IDialogContext context, IAwaitable<object> result)
    {
        await context.PostAsync("Your order has been placed. Thank you for shopping with us.");

        context.Wait(MessageReceived);
    }
}

我还为NewOrderDialog设计了一些代码:

I also had some code in mind for the NewOrderDialog:

[Serializable]
public class NewOrderDialog : LuisDialog<object>
{
    private string _product;
    private string _address;

    public NewOrderDialog() : base(new LuisService(new LuisModelAttribute(ConfigurationManager.AppSettings["LuisAppId"], ConfigurationManager.AppSettings["LuisAPIKey"], domain: "westus.api.cognitive.microsoft.com")))
    {
    }

    [LuisIntent("Order.RequestedItem")]
    public async Task RequestItemIntent(IDialogContext context, LuisResult result)
    {
        EntityRecommendation item;
        if (result.TryFindEntity("Item", out item))
        {
            _product = item.Entity;
            await context.PostAsync($"Okay, I understood you want to order: {_product}.");
        }
        else
        {
            await context.PostAsync("I couldn't understand what you would like to buy. Can you try it again?");
        }

        context.Wait(MessageReceived);
    }

    [LuisIntent("Order.AddedAddress")]
    public async Task AddAddressIntent(IDialogContext context, LuisResult result)
    {
        EntityRecommendation item;
        if (result.TryFindEntity("Address", out item))
        {
            _address = item.Entity;
            await context.PostAsync($"Okay, I understood you want to ship the item to: {_address}.");
        }
        else
        {
            await context.PostAsync("I couldn't understand where you would like to ship the item. Can you try it again?");
        }

        context.Wait(MessageReceived);
    }
}

列出的代码不起作用.输入Order.Place意图后,它立即执行成功"回调,然后引发此异常:

The code as listed doesn't work. Upon entering the Order.Place intent, it immediately executes the 'success' callback, and then throws this exception:

异常:IDialog方法执行完成,并通过IDialogStack指定了多个恢复处理程序. ['text/plain'类型的文件]

Exception: IDialog method execution finished with multiple resume handlers specified through IDialogStack. [File of type 'text/plain']

所以我有几个问题:

  1. 如何解决我得到的错误?
  2. 进入NewOrderDialog后,如何检查我们是否已经知道产品和地址,以及是否未提示他们正确的信息?
  3. 即使我未调用诸如context.Done()之类的东西,为什么NewOrderDialog也被关闭?我只希望在收集所有信息并确认订单后将其关闭.

推荐答案

因此,第一个问题是您正在"Order.Place"中执行context.Forwardcontext.Wait,这在定义上是错误的.您需要选择:转发到新对话框或在当前对话框中等待.根据您的帖子,您想转发,因此只需删除等待"呼叫即可.

So the first issue is that you are doing a context.Forward and a context.Wait in "Order.Place", which by definition is wrong. You need to choose: forward to a new dialog or wait in the current. Based on your post, you want to forward, so just remove the Wait call.

除此之外,您还有1个LUIS对话框,并且您正尝试转到新的LUIS对话框.我可以想象这是两个不同的LUIS模型,否则将是错误的.

Besides that, you have 1 LUIS dialog and you are trying to forward to a new LUIS dialog... I have my doubts if that will work on not; I can imagine those are two different LUIS models otherwise it will be just wrong.

根据您的评论,我现在了解您要使用第二个对话框执行的操作.问题(这与您的第二个问题有关)是,以这种方式使用LUIS可能会造成混淆.例如:

Based on your comment, I now understand what you are trying to do with the second dialog. The problem (and this is related to your second question) is that using LUIS in tha way might be confusing. Eg:

  • 用户:我要下订单
  • bot =>转发到新对话框.由于它是向前的,因此activity.Text可能会再次转到LUIS(进入第二个对话框的模型),并且不会检测到任何内容.第二个对话框将处于Wait状态,供用户输入.
  • user: I want to place an order
  • bot => Forward to new dialog. Since it's a forward, the activity.Text will likely go to LUIS again (to the model of the second dialog) and nothing will be detected. The second dialog will be in Wait state, for user input.

现在,用户将如何知道他需要输入地址或产品?您在哪里提示用户输入?看到问题了吗?

Now, how the user will know that he needs to enter an address or a product? Where are you prompting the user for them? See the issue?

我怀疑您的第三个问题是您在#1中遇到的错误的副作用,我已经提供了解决方案.

Your third question I suspect is a side effect of the error you are having in #1, which I already provided the solution for.

如果您再澄清一点,我可能会更有帮助.您试图在第二个对话框中对LUIS进行的操作看起来不太正常,但也许有一个解释可能是有道理的.

If you clarify a bit more I might be even more helpful. What you are trying to do with LUIS in the second dialog it doesn't look ok, but maybe with an explanation might have sense.

通常的情况是:我从LUIS("Order.Place")获得意图,然后启动FormFlow或一组Prompts以获取下订单的信息(地址,产品等)或者,如果您想继续使用LUIS,则可能要检查路易斯动作绑定.您可以在 https://blog.botframework上阅读更多内容. com/2017/04/03/luis-action-binding-bot/.

A usual scenario would be: I get the intent from LUIS ("Order.Place") and then I start a FormFlow or a set of Prompts to get the info to place the order (address, product, etc) or if you want to keep using LUIS you might want to check Luis Action Binding. You can read more on https://blog.botframework.com/2017/04/03/luis-action-binding-bot/.

这篇关于导航如何与LUIS子对话框一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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