为了账号安全,请及时绑定邮箱和手机立即绑定

将LUIS与C#Bot框架集成-错误

将LUIS与C#Bot框架集成-错误

C#
杨__羊羊 2021-04-27 13:08:46
我正在尝试将Luis.ai集成到C#机器人框架中。该代码运行,但是当我向机器人发送消息时,它显示此错误:“很抱歉,我的机器人代码出了问题”当它根据使用意图的条目进行回复时,我只有两个意图“ None”和“ perfil”。这是我的日志:这是我的类Perfil.cs:using Microsoft.Bot.Builder.Dialogs;using Microsoft.Bot.Builder.Luis;using Microsoft.Bot.Builder.Luis.Models;using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using System.Web;namespace SistemaExperto.Dialogs{    [LuisModel(modelID: "e6168727-2f3e-438b-b46a-88449f4ab52f", subscriptionKey: "ed5f1bda20ac42649123b8969d30e1aa")]    [Serializable]    public class Perfil : LuisDialog<string>    {        [LuisIntent("None")]        public async Task None(IDialogContext context, LuisServiceResult result)        {            await context.PostAsync("I'm sorry I don't have that information");            await context.PostAsync("Try again");        }        [LuisIntent("perfil")]        public async Task perfil(IDialogContext context, LuisServiceResult result)        {            await context.PostAsync("My name is Alex");        }    }}
查看完整描述

1 回答

?
蝴蝶不菲

TA贡献1810条经验 获得超4个赞

我测试了您提供的代码,并用我的LUIS应用程序modelID&subscriptionKey替换了该代码,如果该代码达到了perfil意图,则该代码将按预期工作。


如果LuisDialog无法根据收到的消息解析要执行的方法(意图),则会收到异常:


给定的键在词典中不存在。


为了解决这个问题,我[LuisIntent("")]在None方法之上添加了内容。


[LuisModel(modelID: "{your_modelID}", subscriptionKey: "{your_ subscriptionKey}")]

[Serializable]

public class Perfil : LuisDialog<object>

{

    [LuisIntent("")]

    [LuisIntent("None")]

    public async Task None(IDialogContext context, LuisResult result)

    {

        await context.PostAsync("I'm sorry I don't have that information");

        await context.PostAsync("Try again");

    }


    [LuisIntent("perfil")]

    public async Task perfil(IDialogContext context, LuisResult result)

    {

        await context.PostAsync("My name is Alex");

    }


}

测试结果:


达成perfil目标:

//img1.sycdn.imooc.com//609643f500015a8d08860569.jpg

异常错误:

//img1.sycdn.imooc.com//609644020001db9508940571.jpg


查看完整回答
反对 回复 2021-05-08
  • 1 回答
  • 0 关注
  • 146 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信