gpt4 book ai didi

c# - 带有 LUIS 和 WaterFall 对话框的 Azure Bot Framework Bot 以异常方式执行。意外的对话流程

转载 作者:太空狗 更新时间:2023-10-29 21:42:37 24 4
gpt4 key购买 nike

我正在为我自己的目的破解 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第二次?

enter image description here

更新:根据建议,我已将我的 WaterFallDialogs 更新为具有唯一名称,并重新测试。我仍然有错误的行为。请参见下面的屏幕截图:

enter image description here

我的期望是,在描述了危险之后,我接下来会被问及它的紧急程度。相反,我在“ block ”中得到以下对话响应。

  • 询问事情的紧急程度(正确)
  • 再次欢迎我(不正确 - 这是来自父 Waterfall)
  • 再次询问有多紧急(不正确)

我有点迷路了。我会从我的代码中想象/想到,在返回父对话框之前,子瀑布对话框需要完全完成/结束。

最佳答案

对话名称在机器人中是全局唯一的。您的两个瀑布对话框都被命名为“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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com