- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
QnA 创客机器人易于实现并提供巨大值(value)。在某些情况下,我需要向 QnaMaker 机器人添加对话框。我正在努力寻找最好的方法来做到这一点。我尝试的示例均以非 QnAmaker 主对话框开始。
我的目标是在 QnA 服务 (#contact) 给出特定答案后开始对话(以获取联系方式)。感谢一些指导。
我创建了一个对话框组件来检索用户配置文件。我使用多提示示例作为指导。该对话框确实是在 QnAMaker 查询得到特定结果后启动的。
// user requests to be contacted
case '#Contact': {
await this.dialog.run(turnContext, this.dialogState);
break;
对话集的第一步开始。输入响应后,该过程失败。答案将再次发送到 QnA 服务,并且不会用作对话框组件中下一步的输入(结果)。
我预计原因是所有结果都由 onTurn 处理程序发送到 QnA 服务。
我的问题:
这还能做到吗?我是否能够(无需太多重构)从 QnA 机器人启动一个简单的对话框。
有没有办法检查是否有事件对话框。如果是这样,我也许可以用它来解决它。
我正在考虑这样的事情:
this.onMessage(async (context, next) => {
console.log('Any active Dialog we need to finish?');
AciveDialog ? ResumeDialog : const qnaResults = await this.qnaMaker.getAnswers(context);
文档和示例不是很有帮助,因此非常感谢任何帮助。
到目前为止我的机器人代码。我没有链接对话框组件,因为我希望这不会成为问题的一部分。
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Microsoft Bot Framework components
const { AttachmentLayoutTypes, ActivityTypes, ActivityHandler, CardFactory } = require('botbuilder');
const { QnAMaker } = require('botbuilder-ai');
// Making sure the time is mentioned correctly
const moment = require('moment-timezone');
require('moment/locale/nl');
// Helper funtions (forecast, welcome-message, cards, storage)
const helper = require('./helper');
// Introcard for welcome message
const IntroCard = require('./resources/IntroCard.json');
class QnAMakerBot extends ActivityHandler {
constructor(endpoint, qnaOptions, conversationState, userState, dialog) {
super();
this.qnaMaker = new QnAMaker(endpoint, qnaOptions);
this.conversationState = conversationState;
this.userState = userState;
this.dialog = dialog;
this.dialogState = this.conversationState.createProperty('DialogState');
}
async onTurn(turnContext) {
// First check if a new user joined the webchat, if so, send a greeting message to the user.
if (turnContext.activity.name === 'webchat/join') {
await turnContext.sendActivity({ type: 'typing' });
await turnContext.sendActivity({
attachments: [CardFactory.adaptiveCard(IntroCard)]
});
};
// if a user sent a message, show some response (1) and construct an answer (2).
if (turnContext.activity.type === ActivityTypes.Message) {
// (1)typing indicator with a short delay to improve user experience
await turnContext.sendActivity({ type: 'typing' });
// (2) Perform a call to the QnA Maker service to retrieve matching Question and Answer pairs.
const qnaResults = await this.qnaMaker.getAnswers(turnContext);
// for learning purposes store all questions with qnaMaker score.
if (turnContext.activity.name !== 'webchat/join') {
let score = (qnaResults[0] != null) ? qnaResults[0].score : 'No answer found';
helper.storeQuestions(turnContext, score);
};
// If QnAMaker found an answer that might be correct, first check for responses that need additional work
// If so, do the additional work, otherwise (default) send the QnA answer to the user
if (qnaResults[0] && qnaResults[0].score > 0.5) {
switch (qnaResults[0].answer) {
// user requests a weatherforecast
case '#Weather': {
var weatherForecast = await helper.getWeatherForecast(turnContext);
await turnContext.sendActivity({
attachments: [CardFactory.adaptiveCard(weatherForecast)]
});
break;
}
// user requests current date and/or time
case '#DateTime': {
await turnContext.sendActivity(moment().tz('Europe/Amsterdam').format('[Today is ]LL[ and the time is ] LT'));
break;
}
// user requests help or a startmenu
case '#Help': {
await turnContext.sendActivity({
attachments: [CardFactory.adaptiveCard(IntroCard)]
});
break;
}
// user requests an overview of current bots
case '#Bots': {
await turnContext.sendActivity({
attachments: helper.createBotsGallery(turnContext),
attachmentLayout: AttachmentLayoutTypes.Carousel
});
break;
}
// user requests to be contacted. This is were the magic should happen ;-)
case '#Contact': {
await this.dialog.run(turnContext, this.dialogState);
break;
}
// if no 'special' requests, send the answer found in QnaMaker
default: {
await turnContext.sendActivity(qnaResults[0].answer);
break;
}
}
// QnAmaker did not find an answer with a high probability
} else {
await turnContext.sendActivity('Some response');
}
}
}
async onMessage(turnContext, next) {
// Run the Dialog with the new message Activity.
await this.dialog.run(turnContext, this.dialogState);
await next();
};
async onDialog(turnContext, next) {
// Save any state changes. The load happened during the execution of the Dialog.
await this.conversationState.saveChanges(turnContext, false);
await this.userState.saveChanges(turnContext, false);
await next();
};
}
module.exports.QnAMakerBot = QnAMakerBot;
最佳答案
您可以通过使用component dialogs来实现这一点.
在下面的示例中,我有一个组件对话框,它“监听”用户输入。在本例中,用户输入与获取用户名相关的内容。如果存在匹配,它会发出 QnA 调用来检索答案/响应。一旦检索并显示答案,机器人就会开始中间(子)对话,然后返回主对话。
首先,创建您想要在任何成功的 QnA 响应之后路由到的组件对话框。我已将此文件命名为“getUserNameDialog.js”。
const {
TextPrompt,
ComponentDialog,
WaterfallDialog
} = require('botbuilder-dialogs');
const GET_USER_NAME_DIALOG = 'GET_USER_NAME_DIALOG';
const TEXT_PROMPT = 'TEXT_PROMPT';
const WATERFALL_DIALOG = 'WATERFALL_DIALOG';
class GetUserNameDialog extends ComponentDialog {
constructor() {
super(GET_USER_NAME_DIALOG);
this.addDialog(new TextPrompt(TEXT_PROMPT));
this.addDialog(new WaterfallDialog(WATERFALL_DIALOG, [
this.getNameStep.bind(this),
this.displayNameStep.bind(this)
]));
this.initialDialogId = WATERFALL_DIALOG;
}
async getNameStep(stepContext) {
return await stepContext.prompt(TEXT_PROMPT, "Let's makeup a user name for fun. Enter something.");
// return stepContext.next();
}
async displayNameStep(stepContext) {
const stepResults = stepContext.result;
await stepContext.context.sendActivity(`${ stepResults } is a fine name!`);
return stepContext.endDialog();
}
}
module.exports.GetUserNameDialog = GetUserNameDialog;
module.exports.GET_USER_NAME_DIALOG = GET_USER_NAME_DIALOG;
接下来,创建 QnA 对话框(我将其命名为 qnaResponseDialog.js)。我的 QnA 凭据存储在 .env 文件中,从中检索它们。请注意,我需要上面创建的“getUserNameDialog”文件。
当 QnA 出现匹配/响应时(我正在寻找对“用户名”的一些引用),然后我调用 beginDialog() 来启动子对话框。我通过映射 QnA 响应中返回的问题并匹配用户输入来完成此操作。如果“用户”和/或“名称”出现在任何问题中,则我返回 true。如果为 true,则我返回 QnA 响应并开始子对话框。
这个匹配过程相当简单,更多的是用于演示,但如果它对你有用那就太好了。但是,我建议您查看使用 LUIS以匹配用户意图。它将使这个过程更加干净且更易于维护。
const { ComponentDialog } = require('botbuilder-dialogs');
const { QnAMaker } = require('botbuilder-ai');
const { GetUserNameDialog, GET_USER_NAME_DIALOG } = require('./getUserNameDialog');
class QnAResponseDialog extends ComponentDialog {
constructor() {
super(GET_USER_NAME_DIALOG);
this.addDialog(new GetUserNameDialog());
try {
this.qnaMaker = new QnAMaker({
knowledgeBaseId: process.env.QnAKnowledgebaseId,
endpointKey: process.env.QnAAuthKey,
host: process.env.QnAEndpointHostName
});
} catch (err) {
console.warn(`QnAMaker Exception: ${ err } Check your QnAMaker configuration in .env`);
}
}
async onBeginDialog(innerDc, options) {
const result = await this.interrupt(innerDc);
if (result) {
return result;
}
return await super.onBeginDialog(innerDc, options);
}
async onContinueDialog(innerDc) {
const result = await this.interrupt(innerDc);
if (result) {
return result;
}
return await super.onContinueDialog(innerDc);
}
async interrupt(innerDc) {
if (innerDc.context.activity.type === 'message') {
const text = innerDc.context.activity.text.toLowerCase();
const stepResults = innerDc.context;
let qnaResults = await this.qnaMaker.getAnswers(stepResults);
console.log(qnaResults[0]);
stepResults.qna = qnaResults[0];
if (qnaResults[0]) {
let mappedResult = null;
const includesText = qnaResults[0].questions.map((question) => {
if (text.includes('user') || text.includes('name')) {
mappedResult = true;
} else {
mappedResult = false;
}
console.log('RESULTS: ', mappedResult);
});
console.log('MAPPED: ', mappedResult);
switch (mappedResult) {
case true:
let answer = stepResults.qna.answer;
await innerDc.context.sendActivity(answer);
return await innerDc.beginDialog(GET_USER_NAME_DIALOG);
}
}
}
}
}
module.exports.QnAResponseDialog = QnAResponseDialog;
最后,在主对话框或顶级对话框中包含以下内容:
const { QnAResponseDialog } = require('./qnaResponseDialog');
class MainDialg extends QnAResponseDialog {
[...]
}
此时,如果所有配置都正确,当用户键入 QnA 识别并接受的短语时,它应该中断当前对话框,显示 QnA 响应,开始子组件对话框,完成后返回父对话框。
关于node.js - 向 qnamaker 机器人添加对话框的最有效方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56955428/
我的对话 fragment 有问题。我想使用 android:onClick 属性,因为在我看来代码更清晰。 在我的布局中,我有以下声明: 现在我的 DialogFragment import an
我正在制作一个使用谷歌地图的应用程序,我的主要 xml 代码 fragment 如下: 我的java代码是: import android.os.Bundle; import com.googl
是否可以在一个应用程序中有两个单独的首选项?我有一个在运行时连接到外部可执行文件(引擎)的应用程序。应用程序有自己的偏好,引擎也有。这两者不能混用,因为下次用户可能会决定加载具有不同偏好的完全不同的引
这是“Google Catalogs”应用程序的快照。我只是想知道我们如何进行这种图像重叠。![enter image description here][1] 最佳答案 您可以使用 FrameLay
我制作了一个 GridView ,其中添加了图像。但我的问题是它显示的 gridview 尺寸非常小,其中只有 3 张图像,就像图片中那样,我想在其中显示 9 张图像。 小号 但我希望 gridvie
我目前正在学习如何在 Android 上创建和使用服务。我查看了 android SDK 以获得进一步的帮助,我发现了 android:enable=[true |假]。 在SDK中是这样说的: Th
在完成我的 Android 游戏时,我希望用户将他/她的分数与高分进行比较。为此,我将当前的最高分存储在 SQLite 数据库中。但我认为我的方法(似乎可行)笨拙且丑陋: //in the final
出于某种原因,谷歌没有为模拟器提供任何通知声音,我找不到任何关于如何加载通知声音的引用。 我遇到过这个线程:How to play ringtone/alarm sound in Android但是除
我的应用有以下样式: true #ffffff true 它在我使用的大多数手机上运行良好。 (LG G5、Nexus 5、Moto G)但是当我在 LeEco Pro
我想确保我的网站阻止 Selenium 和 QTP 等自动化工具。有没有办法做到这一点 ?网站上的哪些设置会导致 Selenium 失败? 最佳答案 适当考虑对原始问题“你到底为什么要这样做?”的评论
我正在处理我的联系表,我希望它尽可能地防止垃圾邮件。我正在使用一些方法作为反击: 使用 JavaScript 正则表达式验证电子邮件的合法性 验证所有字段是否具有足够的值 制作一个不可见的字段来吸引机
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, over
我正在制作一个 android 应用程序,我需要在我的应用程序中显示远程图像我使用以下代码。但图像未显示: for(int i=0;i
我有几个与 Android 操作系统中的 AIML 集成相关的问题。我对 Java 了解不多,但我对 AIML 了解很多。我制作了 AIML 文件,现在我想做的是制作一个可以加载文件并在 GUI 中运
我有一个具有“登录”和“注销”操作的应用程序。用户登录后,在他们注销时堆栈中可能还剩下任意数量的 Activity 。 当用户注销时,我希望重置所有应用程序状态。我清除了我的磁盘缓存和首选项,但在运行
我是 Android 应用程序开发的新手,我正在尝试开发一个可用的应用程序。但是我创建的这个页面自创建以来就出现了问题,我真的希望有人能帮助我解决这个问题。每次我运行这个程序时,应用程序都会关闭。 这
我尝试将 android:imeOptions 设置为 actionSend、actionSearch。但是键盘上没有“发送”或“搜索”按钮,只有普通的“Enter”键。我还尝试设置不同的输入类型。
我想创建一种方法来查看相机坐标的中心是否在某个区域的边界内,如果是,则执行一些操作。 当我尝试这样做时,出现错误:Operator !不能应用于 LatLngBounds。 我也试过 if(temp
我正在尝试将视频录制时长限制为 5 秒。我正在使用默认相机和此代码: intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 5); 现在它在三星 S6 上工
我正在开发一款安卓游戏 https://code.google.com/p/something-soft/我的日志猫说它正试图激发游戏的 Intent ,但随后主线程似乎死了(出现 ActivityN
我是一名优秀的程序员,十分优秀!