2

我在 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);
4

2 回答 2

1

LUIS 应用程序似乎不是公开的。

在 LUIS 门户中检查这一点:

在此处输入图像描述

更新:在 Azure 门户中添加了 LUIS 配置页面

在此处输入图像描述

要获取 api 密钥和主机名,您必须检查Azure 中LUIS PUBLISHING资源上的Keys and Endpoint部分(您不应使用 AUTHORING 资源,因为它的请求计数有限,您可能会耗尽它)。

于 2021-04-22T09:47:39.333 回答
1

在 Azure 托管的机器人应用程序服务(不是 Web 应用程序机器人)中,左侧有一个配置选项卡,默认情况下,单击它会选择右侧的应用程序设置选项卡(参见 img)

应用程序设置

我在创建 LUIS AI 服务时创建了这些密钥和端点。事实证明,Azure 中的应用程序设置会覆盖 appsettings.json 或 web.config(你有什么),如此处所述。因此,如果您的 appsettings 文件中的值正确,但与 Azure 中的应用程序设置不同,则应用程序会选择 Azure 中的值。

因为在识别器中我有字符串插值,所以我只是从 LUIS 端点编写了区域,而在 Azure 中为 LuisAPIHostName 我有<your.region>.api.cognitive.microsoft.com。最后端点看起来像https://<your.region>.api.cognitive.microsoft.com.api.cognitive.microsoft.com/

这就是它在本地工作但在 Azure 中托管时不能工作的原因。

于 2021-04-23T12:21:55.103 回答