[英]How should the LUIS intent methods in version 3 bot code be written in bot framework version 4?
我正在嘗試閱讀Microsoft Docs的這篇文章,以將我們的版本3代碼遷移到版本4。
但是,我不確定如何重寫Luis對話框。 必須做什么?
我在onturnasync中添加了以下代碼,不確定現在如何重寫AfterFAQ resume方法。
請幫助我重寫這些現有的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);
}
}
修改后的代碼:
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;
}
}
}
}
如果您的問題與Bot Framework核心v4有關,則PFB會獲取意圖:
var luisResults = await services.LuisServices[LuisKey].RecognizeAsync(turnContext, default(CancellationToken));
LUIS密鑰是注入LUIS服務時使用的密鑰。
luisResults.GetTopIntent(luisThresholdScore).intent;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.