Search code examples
c#azurebotframeworkazure-language-understanding

“No such host is known.” error when publishing bot with LUIS AI to Azure but working fine locally


I have hosted a bot in Azure and when debugging with ngrok via bot emulator I get an error stating: No such host is known. I’ve had such an experience with the bot before, and it meant that the LUIS AI configuration, specifically the LuisAPIHostName value, was not written in the right format in appsettings.json.

As it turned out, back then when the app wasn’t even hosted, the problem was that I was given an endpoint from the hosted LUIS service, https://<your.region>.api.cognitive.microsoft.com/, but I only needed to use <your.region> as the value for LuisAPIHostName and the app started working because the full Endpoint was written in the Luis Recognizer (code from Microsoft docs, link provided below) with string interpolation.

Back to the current issue, I tried to isolate the problem by bypassing the LUIS logic in my app, and published it again, and the bot started working just fine in Azure Web Chat. So, I’m guessing the problem may be with the LUIS configuration. But if it works locally with the previous solution, the LUIS service is hosted in the same subscription as the bot, what does it take to make it work on Azure? I tried a few combinations for LuisAPIHostName, including the whole string provided by Azure and adding an extra "/" at the end, but that didn’t change a thing…

The bot is written with:

v4.13.0 Bot Builder libraries

.NET Core 3.1 framework

In Azure hosted as a Web App Bot, with a corresponding AppService

UPDATE:

Adding how LUIS is configured in my app

Recognizer in BotServices can be found at Microsoft LUIS docs

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://learn.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; }
}

How services are called from the bot, can be found at Microsoft docs

//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);

Solution

  • In the Azure hosted bot App Service (not the Web App bot), there is a configuration tab on the left and by default once clicked it selects the Application settings tab on the right (see img)

    Application settings

    I created these keys and endpoints as I was creating the LUIS AI service. As it turns out, Application Settings in Azure overrides appsettings.json or web.config (what have you) as stated here. So if the values are correct in your appsettings file but are different from the Application settings in Azure, the app chooses the ones in Azure.

    Because in the recognizer I had string interpolation, I just wrote the region from the LUIS endpoint, and in Azure for LuisAPIHostName I had <your.region>.api.cognitive.microsoft.com. In the end the Endpoint would look like https://<your.region>.api.cognitive.microsoft.com.api.cognitive.microsoft.com/

    This is why it worked locally, but not when hosted in Azure.