gpt4 book ai didi

c# - 更新到 1.2.0.1 后 LuisDialog 不再工作

转载 作者:行者123 更新时间:2023-11-30 21:49:06 26 4
gpt4 key购买 nike

我已经更新了我的 NuGet 包以使用 Microsoft Bot Framework 1.2.0.1 版。

一些重大变化是 reported here ,并且我设法修复了构建错误。但是应用程序不再工作了..

我有两个问题:

  1. 当我向 Controller 发送消息或话语时,代码会抛出 InvalidIntentHandlerException
  2. 在我的“intent”方法(装饰有 LuisIntent 属性)中,可以读取实体的值。像这样:

    [Serializable]
    [LuisModel("xxxxx", "xxxx")]
    public class BookFlightDialog : LuisDialog<BookFlightForm>
    {
    private readonly BuildFormDelegate<BookFlightForm> BuildForm;

    internal BookFlightDialog(BuildFormDelegate<BookFlightForm> buildForm)
    {
    BuildForm = buildForm;
    }

    [LuisIntent("")]
    [LuisIntent("None")]
    public async Task None(IDialogContext context, LuisResult result)
    {
    await context.PostAsync("I'm sorry. I didn't understand you.");

    context.Wait(MessageReceived);
    }

    [LuisIntent("BookAFlight")]
    public async Task BookAFlight(IDialogContext context, LuisResult result)
    {
    var form = new BookFlightForm();
    // var entities = new List<EntityRecommendation>(result.Entities);

    var locations = result.Entities.Where(e => e.Type.Equals("builtin.geography") || e.Type.Equals("builtin.geography.city")).OrderBy(e => e.StartIndex);

    if (locations.Any())
    {
    form.LocationFrom = locations.First().Name;

    if (locations.Count() == 2)
    {
    form.LocationTo = locations.Skip(1).First().Name;
    }
    }

    var date = result.Entities.FirstOrDefault(e => e.Type == "builtin.datetime.date");
    if (date != null) form.DepartureDate = DateTime.Parse(date.Name);

    var formDialog = new FormDialog<BookFlightForm>(form, BuildForm, FormOptions.PromptInStart);

    context.Call(formDialog, OnComplete);
    }

    private async Task OnComplete(IDialogContext context, IAwaitable<BookFlightForm> result)
    {
    BookFlightForm booking;
    try
    {
    booking = await result;
    }
    catch (OperationCanceledException)
    {
    await context.PostAsync("Ok, see you later.");
    return;
    }

    if (booking != null)
    {
    var service = new SkyScannerService();
    var possibilities = await service.Search(booking);

    await context.PostAsync(possibilities);
    }
    else
    {
    await context.PostAsync("Form returned empty response!");
    }

    context.Wait(MessageReceived);
    }
    }

如何修复异常以及如何读取实体的值?

再次感谢!

最佳答案

这是因为您没有通过 using LuisResult = Bots.Results.LuisResult; 使用内置的 LuisResult 类。将其替换为 using Microsoft.Bot.Builder.Luis.Models;

关于c# - 更新到 1.2.0.1 后 LuisDialog 不再工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37211092/

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