简体   繁体   English

在第3版bot代码中应如何在bot框架第4版中编写LUIS intent方法?

[英]How should the LUIS intent methods in version 3 bot code be written in bot framework version 4?

I am trying to follow this article from Microsoft Docs in order to migrate our version 3 code to version 4. 我正在尝试阅读Microsoft Docs的这篇文章,以将我们的版本3代码迁移到版本4。

However, I am not sure how to rewrite the Luis dialog. 但是,我不确定如何重写Luis对话框。 What has to be done? 必须做什么?

I have added the below code in onturnasync, not sure how to rewrite the AfterFAQ resume method now. 我在onturnasync中添加了以下代码,不确定现在如何重写AfterFAQ resume方法。

Kindly help me rewrite these existing Luis methods: 请帮助我重写这些现有的Luis方法:

      //The LUIS dialog service call the back the method if the conversation is part of Greeting intent
    [LuisIntent("Greetings")]
    public async Task Greetings(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult result)
    {
        needMoreInformation = false;
        qnaInvalidMessageCount = 0;
        var messageToForward = await activity;
        string[] supportList = { "HELP", "FEEDBACK", "SUPPORT", "ESCALATE", "AGENT" };
        string qnaAnswer;

        if (messageToForward.Text == null || supportList.Any(x => x == messageToForward.Text.ToUpper()))
        {
            await context.PostAsync("Please reach out to ...");
            context.Wait(MessageReceived);
        }
        else if (GreetingColl.TryGetValue(messageToForward.Text.Trim().ToLower(), out qnaAnswer))
        {
            await context.PostAsync(qnaAnswer);
            context.Wait(MessageReceived);
        }
        else
        {
            await context.Forward(new QnAGreetingsDialog(), AfterFAQDialog, messageToForward, CancellationToken.None);
        }

    }

modified code: 修改后的代码:

 public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
    {
        if (turnContext.Activity.Type == ActivityTypes.Message)
        {
          ...
           var luisResults = await botServices.LuisServices[LuisKey].RecognizeAsync(turnContext, cancellationToken);
                    var topScoringIntent = luisResults?.GetTopScoringIntent();
                    var topIntent = topScoringIntent.Value.intent;                        

                    // Continue the current dialog
                    var dialogResult = await dc.ContinueDialogAsync();
                    // if no one has responded,
                    if (!dc.Context.Responded)
                    {
                        // examine results from active dialog
                        switch (dialogResult.Status)
                        {
                            case DialogTurnStatus.Empty:
                                switch (topIntent)
                                {
                                    case NoneIntent:

                                    case GreetingsIntent:
                                        await dc.BeginDialogAsync(nameof(QnAGreetingsDialog));
                                        break;

                                    case CredentialsIntent:


                                    case ContactusIntent:
                                        await LuisVar.Feedback(turnContext);
                                        break;

                                    case FeedbackIntent:
                                        await LuisVar.Feedback(turnContext);
                                        break;

                                    default:
                                        // No intent identified, provide some help to the user
                                        await dc.Context.SendActivityAsync("I didn't understand what you just said to me.");
                                        break;
                                }

                                break;

                            case DialogTurnStatus.Waiting:
                                // The active dialog is waiting for a response from the user, so do nothing.
                                break;

                            case DialogTurnStatus.Complete:
                                await dc.EndDialogAsync();
                                break;

                            default:
                                await dc.CancelAllDialogsAsync();
                                break;
                        }
                    }

                }
            }

if your question is regarding Bot Framework core v4, PFB steps to fetch intents: 如果您的问题与Bot Framework核心v4有关,则PFB会获取意图:

  1. first you need to inject LUIS services in services with key in bot framework. 首先,您需要在具有Bot框架密钥的服务中注入LUIS服务。
  2. Fetch recognizer result object using below code 使用以下代码获取识别器结果对象
var luisResults = await services.LuisServices[LuisKey].RecognizeAsync(turnContext, default(CancellationToken));

LUIS key is key used while injection of LUIS service. LUIS密钥是注入LUIS服务时使用的密钥。

  1. this is how you can fetch intents using RecognizerResult object. 这是使用RecognizerResult对象获取意图的方式。
luisResults.GetTopIntent(luisThresholdScore).intent;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM