Bot框架-自适应对话框

时间:2020-07-15 15:52:03

标签: c# botframework azure-language-understanding adaptive-dialogs

我正在使用机器人框架自适应对话框。我在通过使用识别器读取luis数据来获取意图和已解析实体时遇到问题。仅通过在子自适应对话框中阅读“ turn.recognized”来获得响应中得分最高的意图。我已将我的luis迁移到v3,并在调用luis时将IncludeAllIntents属性设置为true。我想念在LuisAdaptiveRecognizer中设置任何属性吗?谁能帮我解决这个问题,因为我有一个场景可以检查机器人的第二个最高得分意图。这是自适应对话框的问题吗?

我已经使用Ms docs来构建机器人自适应对话框。

还有另一件事,有没有办法从turn.recognized的结果中提取luis解析实体作为RecognizerResult的一种类型。

根对话框:

var rootDialog = new AdaptiveDialog(nameof(AdaptiveDialog))
{
    Recognizer = new LuisAdaptiveRecognizer()
    {
        ApplicationId = Configuration["LuisAppId"],
        EndpointKey = Configuration["LuisAPIKey"],
        Endpoint = Configuration["LuisAPIHostName"],
        PredictionOptions = new Microsoft.Bot.Builder.AI.LuisV3.LuisPredictionOptions
        {
            IncludeAllIntents = true,
            IncludeInstanceData = true,
            IncludeAPIResults = true,
            PreferExternalEntities = true,
            Slot = "producton"
        }
    },
    Triggers = new List<OnCondition>()
    {
         new OnIntent("Greetings")
        {
            Actions = new List<Dialog>()
            {
                new SendActivity("${HelpRootDialog()}")
            }
        },
    },

子对话框:

public FindLinks(IConfiguration configuration) : base(nameof(FindLinks))
{
    _configuration = configuration;
    this.LinksDialog = new AdaptiveDialog(nameof(FindLinks))
    {
        Triggers = new List<OnCondition>()
        {
            new OnBeginDialog()
            {
                Actions = new List<Dialog>()
                    {
                        new CodeAction(ResolveAndSendAnswer)
                    }
            },
        }
    };

    AddDialog(this._findLinksDialog);
    InitialDialogId = nameof(FindLinks);
}

private async Task<DialogTurnResult> ResolveAndSendAnswer(DialogContext dialogContext, System.Object options)
{
    JObject jObject;
    IList<string> queries = new List<string>();
    dialogContext.State.TryGetValue("turn.recognized", out jObject);

    ....This is how i resolved the luis data from the turn.
}

1 个答案:

答案 0 :(得分:1)

不幸的是,无论您使用哪种识别器,自适应对话框都被设计为仅在turn.recognized中包含一个意图。您可以在源代码here中看到它:

result.Intents.Clear();
result.Intents.Add(topIntent, topScore);

看来,遥测中唯一可以访问其他意图的地方。因此,您有一些选择,尽管我知道它们并不理想。

  1. 显式调用您的LUIS终结点,而不是依靠LuisAdaptiveRecognizer。可以使用HTTP请求作为自适应对话框内部的操作来完成此操作,也可以在对话框外部进行此操作。
  2. 从记录的遥测中加载额外的意图。如果您制作了一个自定义遥测客户端,使数据可以在机器人的本地内存中使用,这可能是最简单的。
  3. 在GitHub上进行功能请求,要求他们在自适应对话框中提供所有意图:https://github.com/microsoft/botbuilder-dotnet/issues/new/choose