将LUIS与C#Bot框架集成-错误 [英] Ingtegrating LUIS with c# bot framework - ERROR
问题描述
我正在尝试将Luis.ai集成到C#机器人框架中.该代码运行,但是当我向机器人发送消息时,它显示此错误:
I'm trying to integrate Luis.ai to C# bot framework. The code runs but when I send a message to the bot it shows this error:
对不起,我的机器人代码出了问题"
"sorry my bot code is having an issue"
当根据使用意图的条目进行回复时,我只有两个意图"None"和"perfil".
When it should reply depending on the entry using the intents, I only have 2 intents "None" and "perfil".
这是我的日志:
这是我的课程Perfil.cs:
This is my class 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");
}
}
}
这是我的Controller MessageController.cs:
This is my Controller MessageController.cs:
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
namespace SistemaExperto
{
[BotAuthentication]
public class MessagesController : ApiController
{
/// <summary>
/// POST: api/Messages
/// Receive a message from a user and reply to it
/// </summary>
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
await Conversation.SendAsync(activity, () => new Dialogs.Perfil());
}
else
{
HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
private Activity HandleSystemMessage(Activity message)
{
if (message.Type == ActivityTypes.DeleteUserData)
{
// Implement user deletion here
// If we handle user deletion, return a real message
}
else if (message.Type == ActivityTypes.ConversationUpdate)
{
// Handle conversation state changes, like members being added and removed
// Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
// Not available in all channels
}
else if (message.Type == ActivityTypes.ContactRelationUpdate)
{
// Handle add/remove from contact lists
// Activity.From + Activity.Action represent what happened
}
else if (message.Type == ActivityTypes.Typing)
{
// Handle knowing tha the user is typing
}
else if (message.Type == ActivityTypes.Ping)
{
}
return null;
}
}
}
推荐答案
我测试您提供的代码,并用我的LUIS应用程序modelID&subscriptionKey替换,如果达到Perfil目的,该代码将按预期工作.
I test the code that you provided and replace with my LUIS app modelID&subscriptionKey, if it reach perfil intent, the code work as expected.
如果LuisDialog无法根据收到的消息来解析要执行的方法(意图),则会出现异常:
If the LuisDialog cannot resolve the method (intent) to execute based on the message received, I get the exception:
字典中不存在给定的键.
The given key was not present in the dictionary.
为解决此问题,我在None
方法的顶部添加了[LuisIntent("")]
.
To solve the issue, I add [LuisIntent("")]
on top of the None
method.
[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
意图:
异常错误:
这篇关于将LUIS与C#Bot框架集成-错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!