gpt4 book ai didi

c# - 如何让机器人根据意图响应正确答案

转载 作者:行者123 更新时间:2023-12-03 03:05:58 27 4
gpt4 key购买 nike

我正在使用 luis.ai 和 botframework:

我的问题是,当我尝试发送消息(不属于话语的一部分,因此未知输入时,我没有收到消息:$“抱歉,我不明白'{result.Query}'。请再试一次”; ...但每次都会出现欢迎消息,来自问候意图。

我不知道为什么会发生这种情况。请你帮助我好吗 ?

这是我的代码:MessagController.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 FirstBotApplication
{
//[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 AllTheBot());
}
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;
}
}
}

路易斯.cs

   using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Luis;
using Microsoft.Bot.Builder.Luis.Models;
using Microsoft.Bot.Connector;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Web;


namespace FirstBotApplication
{
// [LuisModel("Please Enter Your LUIS Model ID", "Please Enter Your LUIS
Subscription Key")]

[Serializable]
[LuisModel("xxxxxxx", "xxxxxxxxxxxx")]

public class AllTheBot : LuisDialog<object>
{
// internal static string results;
public async Task None(IDialogContext context, LuisResult result)
{
string message = $"Sorry, I did not understand '{result.Query}'. Please try again";

await context.PostAsync(message);

context.Wait(this.MessageReceived);

}









[LuisIntent("grettings")]
[LuisIntent("intentfr")]
public async Task Greeting(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult result)
{
//await context.PostAsync
//("Yes, you can leave your baggage at the Left Baggage counters located in all terminals. This service is available 24 hours daily at:"
//+ Environment.NewLine + "\n\n Terminal 1" +Environment.NewLine + " - Departure Transit Lounge West, Level 2" + Environment.NewLine + " - Level 3, Public Area"
//+ Environment.NewLine + "\n\n Terminal 2" +Environment.NewLine + " - Departure Transit Lounge Central, Level 2" + Environment.NewLine + " - Arrival Hall North, Level 1, Public Area"
//+ Environment.NewLine + "\n\n Terminal 3" + Environment.NewLine + " - Departure Transit Lounge North, Level 2" + Environment.NewLine + " - Departure Transit Lounge North, Level 2"


await context.PostAsync("Welcome :) ");

context.Wait(MessageReceived);
// results = "BaggageStorage";
}

[LuisIntent("test")]
public async Task test(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult result)
{
await context.PostAsync("Do you want to test our bot ? We suggest to type : hi or who are you, help etc..");
context.Wait(MessageReceived);
}

[LuisIntent("thankyou")]
public async Task thankyou(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult result)
{
await context.PostAsync("I want to thank you for your time.");
context.Wait(MessageReceived);
}



[LuisIntent("exit")]
[LuisIntent("Utilities.Stop")]
public async Task exit(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult result)
{
await context.PostAsync("Thank you for your time ! You are welcome again here :) ");
context.Wait(MessageReceived);
}




}
}

最佳答案

您的 None 方法未使用“None”和 Empty 意图进行修饰。更新您的方法,使其如下所示:

[LuisIntent("None")]
[LuisIntent("")]
public async Task None(IDialogContext context, LuisResult result)
{
string message = $"Sorry, I did not understand '{result.Query}'. Please try again";

await context.PostAsync(message);

context.Wait(this.MessageReceived);
}

关于c# - 如何让机器人根据意图响应正确答案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44519566/

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