【问题标题】:How to add LUIS in a existing QnA bot?如何在现有 QnA 机器人中添加 LUIS?
【发布时间】:2019-11-15 11:39:54
【问题描述】:

我有一个现有的 QnA 机器人(C#、SDK-v4),现在我想在不使用 LUIS 模板创建新机器人的情况下将 LUIS 添加到其中。

我的 QnABot.cs 文件 -

public class QnABot : ActivityHandler
    {
        private readonly IConfiguration _configuration;
        private readonly ILogger<QnABot> _logger;
        private readonly IHttpClientFactory _httpClientFactory;


        public QnABot(IConfiguration configuration, ILogger<QnABot> logger, IHttpClientFactory httpClientFactory)
        {
            _configuration = configuration;
            _logger = logger;
            _httpClientFactory = httpClientFactory;
        }

        protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            var httpClient = _httpClientFactory.CreateClient();

            var qnaMaker = new QnAMaker(new QnAMakerEndpoint
            {
                KnowledgeBaseId = _configuration["QnAKnowledgebaseId"],
                EndpointKey = _configuration["QnAAuthKey"],
                Host = GetHostname()
            },
            null,
            httpClient);

            _logger.LogInformation("Calling QnA Maker");

            // The actual call to the QnA Maker service.
            var response = await qnaMaker.GetAnswersAsync(turnContext);
            if (response != null && response.Length > 0)
            {
                awaitturnContext.SendActivityAsync(
              MessageFactory.Text(response[0].Answer), cancellationToken);
            }
            else
            {
                await turnContext.SendActivityAsync(MessageFactory.Text("No QnA Maker answers were found."), cancellationToken);
            }
        }

        private string GetHostname()
        {
            var hostname = _configuration["QnAEndpointHostName"];
            if (!hostname.StartsWith("https://"))
            {
                hostname = string.Concat("https://", hostname);
            }

            if (!hostname.EndsWith("/qnamaker"))
            {
                hostname = string.Concat(hostname, "/qnamaker");
            }

            return hostname;
        }
    }

我知道调度工具可以调度具有知识库的 LUIS 应用程序,但我不知道如何在这个机器人中处理 Luis 意图。 如何将 LUIS 集成到此机器人中?

【问题讨论】:

标签: c# bots azure-language-understanding azure-bot-service


【解决方案1】:

您可以将 LUIS 添加到现有 QnA 机器人,但实际上您会从 this sample 复制大量代码,因此从示例开始并复制您想要从现有 QnA 中保留的任何代码几乎更快机器人。

您的 OnMessageActivity 应该从看起来像 this 直接调用 qnamaker 客户端变成看起来像 this ,其中用户的输入被传递到 LUIS 调度应用程序,该应用程序确定将用户路由到的意图。

用户的路由在 [DispatchToTopIntent]https://github.com/microsoft/BotBuilder-Samples/blob/master/samples/csharp_dotnetcore/14.nlp-with-dispatch/Bots/DispatchBot.cs#L51) 方法内处理,case 语句中的字符串与门户中的 LUIS 应用下的意图名称匹配。

不用说,你需要在你的机器人中包含一些额外的包 Microsoft.Bot.Builder.Ai.LUIS 是一个,你需要在你的项目中创建 IBotServices 接口和 BotServices 类以及其他更改.

整个过程记录在here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-28
    • 1970-01-01
    • 2018-07-04
    • 2019-12-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多