【发布时间】: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