c# – Microsoft Bot Framework,LUIS,当消息没有意图时采取一些行动
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – Microsoft Bot Framework,LUIS,当消息没有意图时采取一些行动,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3127字,纯文字阅读大概需要5分钟。
内容图文
![c# – Microsoft Bot Framework,LUIS,当消息没有意图时采取一些行动](/upload/InfoBanner/zyjiaocheng/820/b58b711a74ed4b08b1c758786d8344da.jpg)
我最近开始学习Microsoft Bot Framework,所以我开始制作一个Chatbot,我想我做错了
我用这种方式制作聊天机器人:
–> I get the message’s user
–> send to LUIS
–> get the intent and the entities
–> select my answer and send it.
没关系,但得到以下情况:
USER: I wanna change my email. –> intent : ChangeInfo entities:
email/value:emailCHATBOT: Tell me your new Email please. –> intent: noIntent
entities: noEntitiesUSER: email@email.com –> intent: IDon’tKnow entities:
email/value:email@email.com
我采取这种情况,当用户发送他的电子邮件时,我发送给LUI,但是电子邮件没有意图,只有一个实体,但是可以使用很多不同的情况,我的问题是,我的机器人如何知道对话的上下文,以了解此电子邮件是为了更改电子邮件,而不是发送电子邮件,或更新此电子邮件或其他东西.
我的代码在gitHub here上,它是一个丑陋的代码,我知道,但我这只是为了理解机器人框架,之后我会让这段代码更美观
解决方法:
这应该像使用LuisDialog和一组提示来管理用户流一样简单.下面你会找到一些快速的代码,我把它们放在一起,向你展示如何做到这一点.您不需要额外的步骤或添加额外的实体,也不需要使用用户提供的电子邮件前往Luis.
我建议你阅读更多关于LuisDialog和Dialogs的内容,因为你在控制器中使用Luis的方式我认为不是这样的.
Here是一个很好的路易斯样本,在multi-dialogs左右这是一个很好的.
示例代码
namespace MyNamespace
{
using System;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Internals.Fibers;
using Microsoft.Bot.Builder.Luis;
using Microsoft.Bot.Builder.Luis.Models;
using Microsoft.Bot.Connector;
[Serializable]
[LuisModel("YourModelId", "YourSubscriptionKey")]
public class MyLuisDialog : LuisDialog<object>
{
[LuisIntent("")]
[LuisIntent("None")]
public async Task None(IDialogContext context, LuisResult result)
{
string message = "N?o entendi, me diga com outras palavras!";
await context.PostAsync(message);
context.Wait(this.MessageReceived);
}
[LuisIntent("ChangeInfo")]
public async Task ChangeInfo(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult result)
{
// no need to go to luis again..
PromptDialog.Text(context, AfterEmailProvided, "Tell me your new email please?");
}
private async Task AfterEmailProvided(IDialogContext context, IAwaitable<string> result)
{
try
{
var email = await result;
// logic to store your email...
}
catch
{
// here handle your errors in case the user doesn't not provide an email
}
context.Wait(this.MessageReceived);
}
[LuisIntent("PaymentInfo")]
public async Task Payment(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult result)
{
// logic to retrieve the current payment info..
var email = "test@email.com";
PromptDialog.Confirm(context, AfterEmailConfirmation, $"Is it {email} your current email?");
}
private async Task AfterEmailConfirmation(IDialogContext context, IAwaitable<bool> result)
{
try
{
var response = await result;
// if the way to store the payment email is the same as the one used to store the email when going through the ChangeInfo intent, then you can use the same After... method; otherwise create a new one
PromptDialog.Text(context, AfterEmailProvided, "What's your current email?");
}
catch
{
// here handle your errors in case the user doesn't not provide an email
}
context.Wait(this.MessageReceived);
}
}
}
内容总结
以上是互联网集市为您收集整理的c# – Microsoft Bot Framework,LUIS,当消息没有意图时采取一些行动全部内容,希望文章能够帮你解决c# – Microsoft Bot Framework,LUIS,当消息没有意图时采取一些行动所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。