services | platforms | author |
---|---|---|
cognitive-services, luis, language-understanding |
dotnet |
cahann |
A simple console demostrating how to consume the LUIS Runtime SDK to predict user utterances.
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.
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.
You'll need these two values to configure the LuisDialog through the LuisModel attribute:
-
Application ID
You can find the App ID in the LUIS application's settings.
-
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.
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.
You will see the following when running the application:
To get more information about how to get started in Bot Builder for .NET and Conversations please review the following resources: