Last active
October 3, 2017 23:13
-
-
Save nwhitmont/17c19b25580bdf97ae45c9539a2bbce8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This example assumes the existence of a .env file with the following contents: | |
// <START_DOT_ENV> | |
// LUIS_APP_ID="" | |
// LUIS_SUBSCRIPTION_KEY="" | |
// <END_DOT_ENV> | |
require('dotenv').config(); | |
var request = require('request'); | |
var querystring = require('querystring'); | |
function getLuisIntent(utterance) { | |
var endpoint = "https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/"; | |
var luisAppId = process.env.LUIS_APP_ID; | |
var queryParams = { | |
"subscription-key": process.env.LUIS_SUBSCRIPTION_KEY, | |
"timezoneOffset": "0", | |
"verbose": true, | |
"q": utterance | |
} | |
var luisRequest = endpoint + luisAppId + '?' + querystring.stringify(queryParams); | |
request(luisRequest, function (err, response, body) { | |
if (err) console.log(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); | |
} | |
}); | |
} | |
// this example calls IOT CarCommands LUIS model | |
getLuisIntent('turn on windsheild wipers'); | |
/* | |
Example output: | |
Query: turn on windsheild wipers | |
Top Intent: WipersOn | |
Intents: | |
[ { intent: 'WipersOn', score: 0.9560789 }, | |
{ intent: 'WipersOff', score: 0.0401056334 }, | |
{ intent: 'None', score: 0.0322750062 }, | |
{ intent: 'CabinLightsOn', score: 0.000005827829 }, | |
{ intent: 'HeadlightsOn', score: 6.615501e-8 }, | |
{ intent: 'HeadlightsOff', score: 7.603526e-15 } ] | |
*/ | |
// END OF LINE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment