我在 Azure 中托管了一个机器人,当通过机器人模拟器使用 ngrok 进行调试时,我收到一条错误消息:不知道这样的主机。我之前在机器人方面有过这样的经历,这意味着 LUIS AI 配置,特别是 LuisAPIHostName 值,在 appsettings.json 中没有以正确的格式写入。
事实证明,当时甚至没有托管应用程序时,问题是我从托管的 LUIS 服务中获得了一个端点https://<your.region>.api.cognitive.microsoft.com/,但我只需要使用<your.region>作为 LuisAPIHostName 的值,并且应用程序开始工作,因为完整的 Endpoint 是在 Luis Recognizer(来自 Microsoft 文档的代码,下面提供的链接)中编写的,带有字符串插值。
回到当前问题,我试图通过绕过我的应用程序中的 LUIS 逻辑来隔离问题,然后再次发布它,机器人开始在 Azure 网络聊天中正常工作。所以,我猜问题可能出在 LUIS 配置上。但是,如果它与以前的解决方案一起在本地工作,LUIS 服务与机器人托管在同一个订阅中,要让它在 Azure 上工作需要什么?我为 LuisAPIHostName 尝试了一些组合,包括 Azure 提供的整个字符串并在末尾添加了一个额外的“/”,但这并没有改变任何事情......</p>
机器人是这样写的:
v4.13.0 Bot Builder 库
.NET Core 3.1 框架
在 Azure 中作为 Web App Bot 托管,具有相应的 AppService
更新:
添加如何在我的应用程序中配置 LUIS
可以在Microsoft LUIS 文档中找到 BotServices 中的识别器
public BotServices(IConfiguration configuration)
{
// Read the setting for cognitive services (LUIS, QnA) from the appsettings.json
// If includeApiResults is set to true, the full response from the LUIS api (LuisResult)
// will be made available in the properties collection of the RecognizerResult
var luisApplication = new LuisApplication(
configuration["LuisAppId"],
configuration["LuisAPIKey"],
$"https://{configuration["LuisAPIHostName"]}.api.cognitive.microsoft.com");
// Set the recognizer options depending on which endpoint version you want to use.
// More details can be found in https://docs.microsoft.com/en-gb/azure/cognitive-services/luis/luis-migration-api-v3
var recognizerOptions = new LuisRecognizerOptionsV2(luisApplication)
{
IncludeAPIResults = true,
PredictionOptions = new LuisPredictionOptions()
{
IncludeAllIntents = true,
IncludeInstanceData = true
}
};
SampleQnA = new QnAMaker(new QnAMakerEndpoint
{
KnowledgeBaseId = configuration["QnAKnowledgebaseId"],
EndpointKey = configuration["QnAEndpointKey"],
Host = configuration["QnAEndpointHostName"]
});
Dispatch = new LuisRecognizer(recognizerOptions);
}
public LuisRecognizer Dispatch { get; private set; }
public QnAMaker SampleQnA { get; private set; }
}
如何从机器人调用服务,可以在Microsoft 文档中找到
//First, we use the dispatch model to determine which cognitive service(LUIS or QnA) to use.
var recognizerResult = await _botServices.Dispatch.RecognizeAsync(turnContext, cancellationToken);
// Top intent tell us which cognitive service to use.
var (intent, _) = recognizerResult.GetTopScoringIntent();
// Next, we call the dispatcher with the top intent.
await DispatchToTopIntentAsync(turnContext, intent, recognizerResult, cancellationToken, botUser);