Botmaker解决了Qnamaker后续问题 [英] Botmaker resolve Qnamaker Followup Questions

查看:118
本文介绍了Botmaker解决了Qnamaker后续问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我当前的项目,我尝试使用仅上下文跟踪提示.

for my current project i try to use context-only follow-up prompts.

我的问题是,后续提示中的某些问题是相同的.

My problem is now, that some of the questions from the follow-up prompts are the same.

在qna ui中,上下文的分离效果很好,但是当用户从我在应用程序中实现的聊天中回答问题时,qna返回错误的答案.

In the qna ui the separations of the context works fine, but when the user answers the question from the chat i implementen in my application, qna returns the wrong answer.

代码: Botbuilder版本:4.5.3 NodeJS:12.10.0

Code: Botbuilder version: 4.5.3 NodeJS: 12.10.0

onMessage(){.....

let results = qna.getAnswer(context);
if(results[0].context.prompts.length){ //  Answer with Follow-up
      return context.sendActivity(CardHelper.GetHeroCard(results[0].answer, results[0].context.prompts))
   }else{ // normal answer
      return context.sendActivity(results[0].answer)
   }
}

Sample Questions:

Expected Answer:
I want to learn programming => java => here is our guide
Real Answer:
I want to learn programming => java => that is the java test

Expected Answer:
I want to do a test => java => that is the java test
Real Answer:
I want to do a test => java => that is the java test

如何在代码中实现这些后续提示而又不丢失后续上下文?

How is it possible to implement these follow-up prompts in the code and don't lose the follow-up context?

推荐答案

首先要了解的是多轮对话和后续提示处于预览状态.通常,这意味着人们应该期待错误和功能缺失.在这种情况下,这意味着该功能不仅在SDK中缺失,甚至在API参考中甚至消失.您可以在生成答案参考中看到,对generateAnswer端点的调用在其主体中包含context属性,但是该对象的类型未记录.它链接到在响应中返回的Context对象类型,而不是您应该在请求中输入的对象类型.

The first thing to understand is that multi-turn conversations and follow-up prompts are in preview. This generally means one should expect bugs and missing functionality. In this case it means the feature is not only missing from the SDK, it's even missing from the API reference. You can see in the Generate Answer reference that a call to the generateAnswer endpoint includes a context property in its body, but the type of that object is undocumented. It links to the Context object type that gets returned in the response rather than what you're supposed to put in the request.

由于您的问题提到了CardHelper.GetHeroCard,所以我想您已经熟悉

Since your question mentions CardHelper.GetHeroCard, I presume you're already familiar with the QnA Maker prompting sample. If you are by some chance not familiar with that sample, it is the ultimate source of truth when it comes to multi-turn conversations in QnA Maker. That sample contains the entire answer to your question so I'm unsure why you're not using it. However, you should have also seen what you need to do in the documentation you should be following:

返回非初始答案和后续提示的JSON请求

填充context对象以包含先前的上下文.

A JSON request to return a non-initial answer and follow-up prompts

Fill the context object to include the previous context.

在以下JSON请求中,当前问题是使用Windows Hello登录,而上一个问题是帐户和登录.

In the following JSON request, the current question is Use Windows Hello to sign in and the previous question was accounts and signing in.

{
  "question": "Use Windows Hello to sign in",
  "top": 10,
  "userId": "Default",
  "isTest": false,
  "qnaId": 17,
  "context": {
    "previousQnAId": 15,
    "previousUserQuery": "accounts and signing in"
  }
}

QnA Maker不会自行保存任何状态,因此它取决于您的机器人为其提供上一回合的上下文.您的机器人没有这样做,这就是为什么它无法正常工作.这是示例代码的简化版本,可帮助您了解需要执行的操作:

QnA Maker doesn't save any state on its own, so it depends on your bot to give it the context from the previous turn. Your bot isn't doing that, and that's why it's not working. Here's a simplified version of the code from the sample to help you understand what you need to do:

async testQnAMaker(turnContext) {
    var qna = new QnAMaker({
        knowledgeBaseId: '<GUID>',
        endpointKey: '<GUID>',
        host: 'https://<APPNAME>.azurewebsites.net/qnamaker'
    });

    var context = await this.qnaState.get(turnContext) || {
        PreviousQnaId: 0,
        PreviousUserQuery: null
    };

    // We're passing a context property into the QnAMakerOptions
    // even though it's not part of the interface yet
    var results = await qna.getAnswers(turnContext, { context });
    var firstResult = results[0];

    if (firstResult) {
        var answer = firstResult.answer;
        var resultContext = firstResult.context;
        var prompts = resultContext && resultContext.prompts;

        if (prompts && prompts.length) {
            await this.qnaState.set(turnContext, {
                PreviousQnaId: firstResult.id,
                PreviousUserQuery: turnContext.activity.text
            });

            answer = ChoiceFactory.forChannel(
                turnContext,
                prompts.map(prompt => prompt.displayText),
                answer);
        }

        await turnContext.sendActivity(answer);
    } else {
        await turnContext.sendActivity("I can't answer that");
    }
}

由于您使用的是当前正在预览的功能,因此在弄清如何使用它时将需要使用自己的独创性.我只是使用状态属性访问器在每个回合中保存上一个问题的上下文,但是您很可能希望将其构建到对话框中,并将每个用户查询保存在对话框状态中.关键是要使后续提示正常工作,您必须保存QnA Maker状态.

Because you're using a feature that's currently in preview, you will need to use your own ingenuity when it comes to figuring out how to use it. I'm just using a state property accessor to save the context of the previous question on each turn, but it's likely that you'll want to build this into a dialog and save each user query in the dialog state. The point is that you'll have to save the QnA Maker state if you want the follow-up prompts to work.

编辑:事实证明,如果您将上下文放在操作本身中,则可以使用后续提示而不使用漫游器状态,但这仅在用户单击按钮的情况下有效输入内容:显示QnAMaker后续提示的文本

It turns out there is a way to use follow-up prompts without bot state if you put the context in the actions themselves, but that will only work if the user clicks the buttons instead of typing something: Display Text for QnAMaker follow-on prompts

这篇关于Botmaker解决了Qnamaker后续问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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