Learning about LUIS and Consuming LUIS API in node.js

LUIS is Language Understanding Intelligent Service from Microsoft, as part of Azure Cognitive Services.

Several Microsoft technologies work with LUIS:

  • Bot Framework allows a chat bot to talk with a user via text input.
  • Bing Speech API converts spoken language requests into text. Once converted to text, LUIS processes the requests.

LUIS allows us to create an AI based model in the form of an applocation which can consumed via REST endpoint.

LUIS model is based on creating intents, entities and utterances. For more details visit the official docs here.

Let us see how a LUIS App looks like:

Intents in a Luis app

luis1
Intents

Entities in LUIS app:

 

luis2
Entities

Utterances in LUIS app:

luis3
Utterance in an intent(Note.Create)

Training and Testing the LUIS App:

luis4
Testing the utterance to determine which intent they belong to and what entities are present.

Publishing your LUIS app:

luis5
After the LUIS app is published an endpoint LUIS REST API is generated.

LUIS REST API looks as below:

https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/xxxxxxxxxxxxxx?subscription-key=xxxxxxxxxxxxxxf&verbose=true&timezoneOffset=0&q=read meeting notes to me

The above API will produce a response shown as below: The response consists of query name, top scoring intent. all intents with their scores, also the entities present in the utterance.

luis6
LUIS API response

 

Let us see how our client app can consume the LUIS API using node.js:

luis.js

var request = require('request');
var querystring = require('querystring');
 module.exports = {
getLuisIntent:(utterance) => {
 return new Promise((resolve, reject) => { 
   var endpoint = "https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/";
       var luisAppId = "xxxxxxxxxxxxxx";
    var queryParams = {  
           "subscription-key": "xxxxxxxxxxxxxx",      
           "timezoneOffset": "0",     
           "verbose":  true,        
           "q": utterance    }
    var luisRequest =  endpoint + luisAppId +        '?' + querystring.stringify(queryParams);
    request(luisRequest,function (err,response, body) {
            if (err){console.log(err);
               reject(err);
             }else {
                var data = JSON.parse(body);
                    console.log(`Query: ${data.query}`);
                    console.log(`Top Intent: ${data.topScoringIntent.intent}`);
                    console.log('Intents:'); 
                    console.log(data.intents); 
                    var topIntent = data.topScoringIntent.intent;
                    resolve(topIntent);
                  
            }    
    }); 
}); 
}
};
       

client.js

var luisIntent = require('/luis.js');
luisIntent.getLuisIntent('read meeting notes to me').then(response =>{
console.log('Top Scoring Intent--- '+response);
});

 

The program will produce following output:

luis7

 

Check more here:

CHAT BOT USING MICROSOFT AZURE BOT SERVICE & LUIS

BUILDING CHAT BOTs: MICROSOFT QnA MAKER

Microsoft Bot Framework: How to validate user response to bot Prompts?

Node.js: Developing a chat bot on Microsoft Azure Portal

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s