一旦消息从LUIS转发到QnA,具体取决于意图,而不是从第二个实例返回到c#中的LUIS。该怎么办?

问题描述 投票:0回答:1

我正在尝试连接LUIS和QnA,但是从第一个实例上的消息控制器转到luis,如果需要则转到QnA,但是一旦在QnA中,下一个消息不会被发送到仅由QnA执行的LUIS。有人可以帮忙吗?

messageControler.cs

public virtual async Task<HttpResponseMessage> Post([FromBody] Activity activity)
        {
            //await Conversation.SendAsync(activity, () => new BasicLuisDialog());
            // check if activity is of type message
            if (activity.GetActivityType() == ActivityTypes.Message)
            {
                //await Conversation.SendAsync(activity, () => new BasicQnAMakerDialog());
                await Conversation.SendAsync(activity, () => new BasicLuisDialog());
            }
            else
            {
                //await Conversation.SendAsync(activity, () => new BasicQnAMakerDialog());
                HandleSystemMessage(activity);
            }
            return new HttpResponseMessage(System.Net.HttpStatusCode.Accepted);
        }
        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;
        }
    }
}

BasicLuisDialog.cs这是基本luisdialog的代码,如果意图匹配则从这里开始它应该提供所需的回复,否则它将把搜索重定向到基本qna。这仅适用于第一个实例。从第二个实例开始,如果它在qna中它不是从luis开始的。

public class BasicLuisDialog : LuisDialog<object>
    {
        [LuisIntent("")]
        [LuisIntent("None")]
        public async Task None(IDialogContext context, IAwaitable<IMessageActivity> message, LuisResult result)
        {
            var mForward = await message as Activity;
            var username = context.Activity.From.Name;
            string reply = $"Hello {username}! Your query we are taking forward, as we are not aware about what exactly you want to know.";
            //await context.PostAsync(reply);
            await context.Forward(new IDialog(), this.ResumeAfterQnA, mForward, CancellationToken.None);
        }

        private async Task ResumeAfterQnA(IDialogContext context, IAwaitable<object> result)
        {
           context.Wait(MessageReceived);
        }

        [LuisIntent("leave.apply")]
        public async Task ApplyLeave(IDialogContext context, IAwaitable<IMessageActivity> message, LuisResult result)
        {
            var username = context.Activity.From.Name;
            string reply = $"Hello {username}! we are processing it";
            await context.PostAsync(reply);
        }

        [LuisIntent("it")]
        public async Task IT(IDialogContext context, IAwaitable<IMessageActivity> message, LuisResult result)
        {
            var username = context.Activity.From.Name;
            string reply = $"Hello {username}! we would look into your IT problems shortly";
            await context.PostAsync(reply);
        }
    }

BasicQnAMakerDialog基本QnA代码如下。请帮我找出确切的问题所在。

public class IDialog : IDialog<object>
    {
        public async Task StartAsync(IDialogContext context)
        {
            /* Wait until the first message is received from the conversation and call MessageReceviedAsync 
            *  to process that message. */
            context.Wait(this.MessageReceivedAsync);
        }

        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
        {


            /* When MessageReceivedAsync is called, it's passed an IAwaitable<IMessageActivity>. To get the message,
             *  await the result. */
            var message = await result;
            var activity = await result as Activity;
            var qnaAuthKey = ConfigurationManager.AppSettings["QnAAuthKey"]; 
            var qnaKBId = ConfigurationManager.AppSettings["QnAKnowledgebaseId"];
            var endpointHostName = ConfigurationManager.AppSettings["QnAEndpointHostName"];


            // QnA Subscription Key and KnowledgeBase Id null verification
            if (!string.IsNullOrEmpty(qnaAuthKey) && !string.IsNullOrEmpty(qnaKBId))
            {
                // Forward to the appropriate Dialog based on whether the endpoint hostname is present
                if (string.IsNullOrEmpty(endpointHostName)) { 
                    await context.Forward(new BasicQnAMakerPreviewDialog(), AfterAnswerAsync, message, CancellationToken.None);
                    }
                else
                {
                    await context.Forward(new BasicQnAMakerDialog(), AfterAnswerAsync, message, CancellationToken.None);
                }

                }
            else
            {
                await context.PostAsync("Please set QnAKnowledgebaseId, QnAAuthKey and QnAEndpointHostName (if applicable) in App Settings. Learn how to get them at https://aka.ms/qnaabssetup.");
            }
            //var activity = await result as Activity;
            //await context.Forward(new BasicLuisDialog(), ResumeAfterLuisDialog, activity, CancellationToken.None);
        }
c# .net botframework luis azure-bot-service
1个回答
0
投票

当对话框完成它应该做的事情时,你需要调用context.Done(new MyDialogResult())。僵尸框架为每个对话保留一堆对话框,每当你执行一个context.Forward时,它会将一个新的对话框推送到堆栈,每个到机器人的消息总是会进入堆栈顶部的对话框并跳过下面的其他对话框,所以执行context.Done时,它会从堆栈弹出当前对话框,对话将返回上一个对话框。

热门问题
推荐问题
最新问题