且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Azure BOT框架,将QnA Maker与LUIS集成

更新时间:2023-02-08 12:15:15

有几种通用的方法来实现它,但是最终由Bot开发人员来决定如何构造它.

There are several general ways to do it, but it's ultimately up to you as the Bot developer to decide how to structure it.

docs

A general overview is provided in the docs here, but if you want a more code oriented sample, this blog post should help you -

使用QnA,Luis和可得分

在示例中, LuisDialog 充当一种消息控制器,它根据意图将用户引导到某种类型的对话框.这也可以用于将用户定向到QnA对话框->

In the sample, the LuisDialog acts as a kind of message controller, which guides the user to a certain kind of dialog based on intent. This also can be used to direct a user to a QnA dialog ->

[Serializable]
[LuisModel("YourLuisAppID", "YourLuisSubscriptionKey")]
public class LuisDialog : LuisDialog<object>
{
    // methods to handle LUIS intents

    [LuisIntent("")]
    [LuisIntent("None")]
    public async Task None(IDialogContext context, LuisResult result)
    {
       // You can forward to QnA Dialog, and let Qna Maker handle the user's 
        query if no intent is found
        await context.Forward(new QnaDialog(), ResumeAfterQnaDialog, 
                               context.Activity, CancellationToken.None);
    }

    [LuisIntent("Some-Intent-Like-Get-Weather")]
     public async Task GetWeather(IDialogContext context, LuisResult result)
     {
         .... 
         // some tasks, forward to other dialog, etc 
     }

}

这是一种实现方法,也是一种流行的方法.在此设置中,如果LUIS无法检测到意图,它将把用户的查询路由到Qna服务(您训练的)要回答的QnA对话框.

This is one way to do it, and a popular one. In this setup, if there is no intent that LUIS can detect, it'll route the user's query to a QnA dialog for the Qna Service (which you train) to answer.

或者,如果用户的意图是提出问题,则可以专门创建一个问题意图",然后尝试将其转发给QnA.但是,这比较棘手,因为此方法要求您手动创建自定义代码来管理响应的分数".

Alternatively, you can create specifically a "Question intent" and try to forward it to QnA that way, if the user's intent was to ask a question. This is trickier however, as this method requires you to manually create custom code to manage the 'scores' of the responses.

希望这足以帮助您获得所需的东西!

Hope this was enough to help you get to what you need!

编辑-抱歉,修复了第一个链接.

EDIT - Apologies, fixed the first link.

此外,我将粘贴文档中列出的3种常见方案,作为您使用LUIS + QnA的方式:

In addition, I'll just paste 3 common scenarios listed from the docs as ways you can use LUIS + QnA:

1)同时调用QnA Maker和LUIS,并使用第一个返回特定阈值分数的信息来响应用户.

1) Call both QnA Maker and LUIS at the same time, and respond to the user by using information from the first one that returns a score of a specific threshold.

2)首先呼叫LUIS,如果没有意图满足特定阈值分数,即触发无"意图,则呼叫QnA Maker.或者,为QnA Maker创建LUIS意向,为LUIS模型提供映射到"QnAIntent"的示例QnA问题.

2) Call LUIS first, and if no intent meets a specific threshold score, i.e., "None" intent is triggered, then call QnA Maker. Alternatively, create a LUIS intent for QnA Maker, feeding your LUIS model with example QnA questions that map to "QnAIntent."

3)首先致电QnA Maker,如果没有答案符合特定阈值分数,则致电LUIS.

3)Call QnA Maker first, and if no answer meets a specific threshold score, then call LUIS.