Cognitive Services: LUIS Console Application Sample

Last updated: 12/20/2017
Edit on GitHub

A simple console demostrating how to consume the LUIS Runtime SDK to predict user utterances.

Prerequisites

The minimum prerequisites to run this sample are: * The latest update of Visual Studio 2015 or 2017. You can download the community version here for free. * A LUIS.ai account where to upload the sample's LUIS model.

LUIS Application

The first step to using LUIS is to create or import an application. Go to the home page, www.luis.ai, and log in. After creating your LUIS account you'll be able to Import an Existing Application where can you can select a local copy of the LuisApp.json file an import it.

If you want to test this sample, you have to import the pre-build LuisApp.json file to your LUIS account.

Once you imported the application you'll need to "train" the model (Training) before you can "Publish" the model in an HTTP endpoint. For more information, take a look at Publishing a Model.

Finally, edit the appsettings.json file and update the attribute placeholders with the values corresponding to your Subscription, Application and Azure Region where the application was deployed.

Where to find the Application ID and Subscription Key

You'll need these two values to configure the LuisDialog through the LuisModel attribute:

  1. Application ID

    You can find the App ID in the LUIS application's settings.

  2. Subscription Key and Azure Region

    Click on the Publish App link from the top of the LUIS application dashboard. Once your app is published, copy the Region and Key String from Starter_Key from the Endpoints table on the Publish App page.

Code Highlights

One of the key problems in human-computer interactions is the ability of the computer to understand what a person wants, and to find the pieces of information that are relevant to their intent. In the LUIS application, you will bundle together the intents and entities that are important to your task. Read more about Planning an Application in the LUIS Docs.

Once your model is set, you can invoke de LUIS Runtime API to analize user input and obtain its intent and possible entities.

From .NET you can use the Microsoft.Azure.CognitiveServices.Language.LUIS NuGet package. Once you have reference the library, you can start making call to the API.

using Microsoft.Azure.CognitiveServices.Language.LUIS;
using Microsoft.Azure.CognitiveServices.Language.LUIS.Models;

// Create client with SuscriptionKey and AzureRegion
ILuisRuntimeAPI client = new LuisRuntimeAPI(new ApiKeyServiceClientCredentials("[LUIS_SUBSCRIPTION_KEY]"))
{
    AzureRegion = AzureRegions.Westus
};

// Predict
LuisResult result = await client.Prediction.ResolveAsync("[LUIS_APPLICATION_ID]", "Text to Predict or User input");

The LuisResult object contains the possible detected intents and entities that could be extracted from the input.

Outcome

You will see the following when running the application:

More Information

To get more information about how to get started in Bot Builder for .NET and Conversations please review the following resources: * Language Understanding Intelligent Service * LUIS.ai * LUIS Docs * LUIS Runtime API v2 - Specification