3

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);
Bojan
  • 769
  • 9
  • 16
  • Can you provide the code you use to set up your LUIS connector and/or call your LUIS API (with your key/application details removed)? Also, can you confirm which keys and applications names you are using, as LUIS has both prediction and authoring endpoints? – billoverton Apr 22 '21 at 12:49
  • @billoverton code provided – Bojan Apr 22 '21 at 14:04
  • Emulator you are getting LUIS App output then try to re-publish the app in prod or slot environment and check the output. Also verify your qna maker call. – Rajeesh Menoth Apr 23 '21 at 02:07
  • Sorry @Rajeesh I don't understand your text, could you reformulate it? – Bojan Apr 23 '21 at 07:15

3 Answers3

1

It looks like the LUIS application isn't public.

Check for this in the LUIS portal:

enter image description here

UPDATE: Added the LUIS configuration page in Azure portal

enter image description here

To get the api keys and hostname, you have to check the Keys and Endpoint section on your LUIS PUBLISHING resource in Azure (you shouldn't use the AUTHORING resource, b/c it has a limited request count and you might deplete it).

Miguel Veloso
  • 1,055
  • 10
  • 16
  • Hey @Miguel, I tried it, and while this may bring me a step closer, the error still persists. Do you have other suggestions? – Bojan Apr 22 '21 at 10:37
  • Hmmm, the host name looks odd, look at my updated answer, I added the azure portal page where you get the keys and endpoint from. – Miguel Veloso Apr 22 '21 at 16:19
  • In the code provided you can see that the Endpoint/LuisAPIHostName only needs the region in appsettings, because the full Endpoint is created in my LUIS recognizer done with string interpolation. As for the keys, my "LuisAPIKey" is one of those keys you pointed out. – Bojan Apr 23 '21 at 07:08
  • Well, what called my attention was that the host you're getting is `*.api.cognitive.microsoft.com` and what I've been seeing lately (this year) is `*.cognitiveservices.azure.com`. did you check if the endpoint from the Azure resource page is the same as what's being built in the recognizer? – Miguel Veloso Apr 23 '21 at 07:58
  • No, *.api.cognitive.microsoft.com is the part in the code and the LUIS endpoint in azure. As I said, the LUIS config works fine locally, so I'm guessing it might be something to do with Azure – Bojan Apr 23 '21 at 08:16
  • When I say "something to do with Azure" I mean the bot hosted in Azure, because that is the only difference. LUIS config and workflow doesn't change for local or published, only the bot does. In appsettings the LUIS config is placed only in the main json file, so when I run locally the strings are propagated to the appsettings.development.json (since no LUIS config there is present). – Bojan Apr 23 '21 at 08:27
  • Hmmm, where wave you deployed your bot? a Windows AppService? can you try with curl from a CMD debug console from the App Service, for example: `curl -i "https://YOUR-LUIS-RESOURCE-PREDICTION-ENDPOINT/luis/prediction/v3.0/apps/LUIS-AP-ID/slots/production/predict?subscription-key=LUIS-RESOURCE-ENPOINT-KEY&verbose=true&show-all-intents=true&log=true&query=A-TEST-UTTERANCE"` just to check the network is OK. You can get a complete example query url from: **Luis portal > Luis app > Manage > Azure resources > Prediction Resources** after selecting one prediction resource from your subscription. – Miguel Veloso Apr 23 '21 at 15:05
  • 1
    I found the problem Miguel, posted it a couple of hours ago, thanks anyway – Bojan Apr 23 '21 at 16:39
  • Glad you could solve it , and we all learned something else to check. What I do to avoid this type of errors is configuring all dev settings in appsettings.Development.json. This way appsettings only has the setting names, but no values, so you know you always have to use the AppService configuration. – Miguel Veloso Apr 23 '21 at 18:14
  • Yes, sounds like a neat way to remind a new developer on the project to look for these settings elsewhere. – Bojan Apr 24 '21 at 11:08
1

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.

Bojan
  • 769
  • 9
  • 16
0

I got that error because I was incorrectly concatenating the Uri.

Example:

string endPointUrl: "https://sampleresource-authoring.cognitiveservices.azure.com";
var uri = $"{endPointUrl}luis/authoring/v3.0-preview/apps....";

And the error gave me: "No such host is known"

the error is that I was missing: "/" after {endPointUrl}, where it should be like this:

var uri = $"{endPointUrl}/luis/authoring/v3.0-preview/apps....";

I would recommend that you check your final url. I hope it helps.

Yudner
  • 533
  • 4
  • 9