- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在为我自己的目的破解 Bot Framework V4(使用 LUIS)的 GitHub“CoreBot”示例代码,并且在执行响应和瀑布对话步骤的方式中遇到了障碍。
我有一个顶级对话框。我的期望是此对话框根据输入对 LUIS 进行初始调用,并根据该输入路由到不同的对话框。目前,只能问候机器人并报告危险。我的对话框设置如下(忽略 BookingDialog,它是示例的一部分)。
public MainDialog(IConfiguration configuration, ILogger<MainDialog> logger)
: base(nameof(MainDialog))
{
Configuration = configuration;
Logger = logger;
AddDialog(new TextPrompt(nameof(TextPrompt)));
AddDialog(new BookingDialog());
AddDialog(new HazardDialog());
AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
{
MainStepAsync,
EndOfMainDialogAsync
}));
// The initial child Dialog to run.
InitialDialogId = nameof(WaterfallDialog);
}
我的期望是执行 MainStepAsync,它运行以下内容:
private async Task<DialogTurnResult> MainStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
CoreBot.StorageLogging.LogToTableAsync($"Main step entered. I am contacting LUIS to determine the intent");
string what_i_got = await LuisHelper.ExecuteMyLuisQuery(Configuration, Logger, stepContext.Context, cancellationToken);
CoreBot.StorageLogging.LogToTableAsync($"LUIS intent matched: {what_i_got}");
//await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = MessageFactory.Text($"Hi! My name is Sorella. Your intent was {what_i_got}") }, cancellationToken);
switch (what_i_got)
{
case "Hazard":
StorageLogging.LogToTableAsync($"We have been asked to report a hazard");
StorageLogging.LogToTableAsync(stepContext);
var hazardDetails = new ResponseSet.Hazard();
return await stepContext.BeginDialogAsync(nameof(HazardDialog), hazardDetails, cancellationToken);
case "Greeting":
StorageLogging.LogToTableAsync($"We have been asked to provide a greeting. After this greeting the waterfall will end");
StorageLogging.LogToTableAsync(stepContext);
await stepContext.Context.SendActivityAsync(MessageFactory.Text("Hi there! :). What can I help you with today? "), cancellationToken);
return await stepContext.EndDialogAsync(null, cancellationToken);
default:
StorageLogging.LogToTableAsync($"We got an intent we haven't catered for. After this the waterfall will end");
StorageLogging.LogToTableAsync(stepContext);
return await stepContext.NextAsync(null, cancellationToken);
}
}
如果意图是 Harzard,则开始 HazardDialog。否则,如果他们正在问候机器人,只需打个招呼并结束这个顶级瀑布对话。如果用户被路由到 HazardDialog,启动下一个 Waterfall,设置如下:
public class HazardDialog : CancelAndHelpDialog
{
public HazardDialog()
: base(nameof(HazardDialog))
{
AddDialog(new TextPrompt(nameof(TextPrompt)));
AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
{
GetInitialHazardInfoAsync,
GetHazardUrgencyAsync,
FinalStepAsync
}));
// The initial child Dialog to run.
InitialDialogId = nameof(WaterfallDialog);
}
他们首先被要求描述危险:
private async Task<DialogTurnResult> GetInitialHazardInfoAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
CoreBot.StorageLogging.LogToTableAsync("Entered hazard step 1. Asking for hazard type");
var hazardDetails = (ResponseSet.Hazard)stepContext.Options;
hazardDetails.HazardType = (string)stepContext.Result;
if (hazardDetails.HazardType == null)
{
CoreBot.StorageLogging.LogToTableAsync($"No hazard type provided. Asking");
return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = MessageFactory.Text("What kind of hazard would you like to report? Provide me a brief description") }, cancellationToken);
}
else
{
CoreBot.StorageLogging.LogToTableAsync($"Hazard provided. Moving on");
return await stepContext.NextAsync(hazardDetails.HazardType, cancellationToken);
}
}
然后为了紧急:
private async Task<DialogTurnResult> GetHazardUrgencyAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
CoreBot.StorageLogging.LogToTableAsync($"Entered hazard step 2. Asking for urgency");
var hazardDetails = (ResponseSet.Hazard)stepContext.Options;
hazardDetails.HazardType = (string)stepContext.Result;
var hazardAsJson = JsonConvert.SerializeObject(hazardDetails);
StorageLogging.LogToTableAsync(hazardAsJson);
if (hazardDetails.HarzardUrgency == null)
{
CoreBot.StorageLogging.LogToTableAsync($"No urgency provided. Asking");
return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = MessageFactory.Text($"Thanks. So your hazard is {hazardDetails.HazardType}? How urgent is it?") }, cancellationToken);
}
else
{
CoreBot.StorageLogging.LogToTableAsync($"Urgency given. We're all done");
var guid = Guid.NewGuid();
var ticketId = "HAZ" + Convert.ToString(guid).ToUpper().Substring(1,4);
await stepContext.Context.SendActivityAsync(MessageFactory.Text($"Thanks! I've got all the informatio I need. I'll raise this with the API team on your behalf. Your Ticket ID is: {ticketId} "), cancellationToken);
return await stepContext.NextAsync(cancellationToken, cancellationToken);
}
}
如果我们既有紧迫感又有类型,那么我们会“举票”并转到最后一步,这只是结束堆栈。
private async Task<DialogTurnResult> FinalStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
CoreBot.StorageLogging.LogToTableAsync($"Entered hazard step 3. Final step");
var hazardDetails = (ResponseSet.Hazard)stepContext.Options;
hazardDetails.HarzardUrgency = (string)stepContext.Result;
var hazardAsJson = JsonConvert.SerializeObject(hazardDetails);
StorageLogging.LogToTableAsync(hazardAsJson);
return await stepContext.EndDialogAsync(hazardDetails, cancellationToken);
}
我的期望是结束 HarzardDialog 然后返回到“父”瀑布对话框中的下一步,即 EndOfMainDialogAsync,它只是说我们都完成了,我可以做任何其他事情来帮助吗?
private async Task<DialogTurnResult> EndOfMainDialogAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
StorageLogging.LogToTableAsync($"Ending the main dialog");
StorageLogging.LogToTableAsync(stepContext);
await stepContext.Context.SendActivityAsync(MessageFactory.Text("Ok, I think we're all done with that. Can I do anything else to help?"), cancellationToken);
return await stepContext.EndDialogAsync(null, cancellationToken);
}
但是,在我的实际对话中,流最终行为异常,事实上(如果您看下面的对话)从子瀑布触发 GetHazardUrgencyAsync,然后从父瀑布触发 MainStepAsync,然后从子瀑布触发 GetHazardUrgencyAsync第二次?
更新:根据建议,我已将我的 WaterFallDialogs 更新为具有唯一名称,并重新测试。我仍然有错误的行为。请参见下面的屏幕截图:
我的期望是,在描述了危险之后,我接下来会被问及它的紧急程度。相反,我在“ block ”中得到以下对话响应。
我有点迷路了。我会从我的代码中想象/想到,在返回父对话框之前,子瀑布对话框需要完全完成/结束。
最佳答案
对话名称在机器人中是全局唯一的。您的两个瀑布对话框都被命名为“WaterfallDialog”。因此,您基本上是在即时更换瀑布。
将它们更改为唯一的名称。
AddDialog(new WaterfallDialog("MainDialogWaterfall", new WaterfallStep[]
{
MainStepAsync,
EndOfMainDialogAsync
}));
AddDialog(new WaterfallDialog("HazardInfoWaterfallDialog", new WaterfallStep[]
{
GetInitialHazardInfoAsync,
GetHazardUrgencyAsync,
FinalStepAsync
}));
关于c# - 带有 LUIS 和 WaterFall 对话框的 Azure Bot Framework Bot 以异常方式执行。意外的对话流程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56659285/
我一直在阅读有关汇编函数的内容,但对于是使用进入和退出还是仅使用调用/返回指令来快速执行,我感到很困惑。一种方式快而另一种方式更小吗?例如,在不内联函数的情况下,在汇编中执行此操作的最快(stdcal
我正在处理一个元组列表,如下所示: res = [('stori', 'JJ'), ('man', 'NN'), ('unnatur', 'JJ'), ('feel', 'NN'), ('pig',
最近我一直在做很多网络或 IO 绑定(bind)操作,使用线程有助于加快代码速度。我注意到我一直在一遍又一遍地编写这样的代码: threads = [] for machine, user, data
假设我有一个名为 user_stats 的资源,其中包含用户拥有的帖子、评论、喜欢和关注者的数量。是否有一种 RESTful 方式只询问该统计数据的一部分(即,对于 user_stats/3,请告诉我
我有一个简单的 api,它的工作原理是这样的: 用户创建一个请求 ( POST /requests ) 另一个用户检索所有请求 ( GET /requests ) 然后向请求添加报价 ( POST /
考虑以下 CDK Python 中的示例(对于这个问题,不需要 AWS 知识,这应该对基本上任何构建器模式都有效,我只是在这个示例中使用 CDK,因为我使用这个库遇到了这个问题。): from aws
Scala 中管理对象池的首选方法是什么? 我需要单线程创建和删除大规模对象(不需要同步)。在 C++ 中,我使用了静态对象数组。 在 Scala 中处理它的惯用和有效方法是什么? 最佳答案 我会把它
我有一个带有一些内置方法的类。这是该类的抽象示例: class Foo: def __init__(self): self.a = 0 self.b = 0
返回和检查方法执行的 Pythonic 方式 我目前在 python 代码中使用 golang 编码风格,决定移动 pythonic 方式 例子: import sys from typing imp
我正在开发一个 RESTful API。其中一个 URL 允许调用者通过 id 请求特定人员的记录。 返回该 id 不存在的记录的常规值是什么?服务器是否应该发回一个空对象或者一个 404,或者其他什
我正在使用 pathlib.Path() 检查文件是否存在,并使用 rasterio 将其作为图像打开. filename = pathlib.Path("./my_file-name.tif") 但
我正在寻找一种 Pythonic 方式来从列表和字典创建嵌套字典。以下两个语句产生相同的结果: a = [3, 4] b = {'a': 1, 'b': 2} c = dict(zip(b, a))
我有一个正在操裁剪理设备的脚本。设备有时会发生物理故障,当它发生时,我想重置设备并继续执行脚本。我有这个: while True: do_device_control() device
做组合别名的最pythonic和正确的方法是什么? 这是一个假设的场景: class House: def cleanup(self, arg1, arg2, kwarg1=False):
我正在开发一个小型客户端服务器程序来收集订单。我想以“REST(ful)方式”来做到这一点。 我想做的是: 收集所有订单行(产品和数量)并将完整订单发送到服务器 目前我看到有两种选择: 将每个订单行发
我知道在 Groovy 中您可以使用字符串调用类/对象上的方法。例如: Foo."get"(1) /* or */ String meth = "get" Foo."$meth"(1) 有没有办法
在 ECMAScript6 中,您可以使用扩展运算符来解构这样的对象 const {a, ...rest} = obj; 它将 obj 浅拷贝到 rest,不带属性 a。 有没有一种干净的方法可以在
我有几个函数返回数字或None。我希望我的包装函数返回第一个不是 None 的结果。除了下面的方法之外,还有其他方法吗? def func1(): return None def func2(
假设我想设计一个 REST api 来讨论歌曲、专辑和艺术家(实际上我就是这样做的,就像我之前的 1312414 个人一样)。 歌曲资源始终与其所属专辑相关联。相反,专辑资源与其包含的所有歌曲相关联。
这是我认为必须经常出现的问题,但我一直无法找到一个好的解决方案。假设我有一个函数,它可以作为参数传递一个开放资源(如文件或数据库连接对象),或者需要自己创建一个。如果函数需要自己打开文件,最佳实践通常
我是一名优秀的程序员,十分优秀!