Skip to content

Commit a610636

Browse files
author
Ahmed Elhinidy
committed
Updated SDK to version 2
1 parent 9200450 commit a610636

File tree

3 files changed

+10
-27
lines changed

3 files changed

+10
-27
lines changed

luis_sdk/index.js

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,24 @@ var LUISResponse = require("./luis_response");
4444
* Constructs a LUISClient with the corresponding user's App ID and Subscription Keys
4545
* Starts the prediction procedure for the user's text, and accepts a callback function
4646
*
47-
* @param initData an object that has 4 propertes:
47+
* @param initData an object that has 3 propertes:
4848
* @1- appId a String containing the Application Id
4949
* @2- appKey a String containing the Subscription Key
50-
* @3- preview a Boolean to choose whether to use the preview version or not
51-
* @4- verbose a Boolean to choose whether to use the verbose version or not
50+
* @3- verbose a Boolean to choose whether to use the verbose version or not
5251
* @returns {{predict: predict, reply: reply}} an object containing the functions that need to be used
5352
*/
5453
var LUISClient = function(initData) {
5554
validateInitData(initData);
5655
var appId = initData.appId;
5756
var appKey = initData.appKey;
58-
var preview = initData.preview;
5957
var verbose = initData.verbose;
6058
validateAppInfoParam(appId, "Application Id");
6159
validateAppInfoParam(appKey, "Subscription Key");
62-
preview = validateBooleanParam(preview, "Preview");
6360
verbose = validateBooleanParam(verbose, "Verbose");
6461
const LUISURL = "api.projectoxford.ai";
65-
const LUISPreviewURL = preview ? "/preview" : "";
66-
const LUISPredictMask = "/luis/v1/application%s?id=%s&subscription-key=%s%s&q=%s";
67-
const LUISReplyMask = "/luis/v1/application%s?id=%s&subscription-key=%s&contextid=%s%s&q=%s";
68-
const LUISVerboseURL = verbose ? "&verbose=true" : "";
62+
const LUISPredictMask = "/luis/v2.0/apps/%s?subscription-key=%s&q=%s&verbose=%s";
63+
const LUISReplyMask = "/luis/v2.0/apps/%s?subscription-key=%s&q=%s&contextid=%s&verbose=%s";
64+
const LUISVerbose = verbose ? "true" : "false";
6965
return {
7066
/**
7167
* Initiates the prediction procedure
@@ -79,7 +75,7 @@ var LUISClient = function(initData) {
7975
validateResponseHandlers(responseHandlers);
8076
var LUISOptions = {
8177
hostname: LUISURL,
82-
path: util.format(LUISPredictMask, LUISPreviewURL, appId, appKey, LUISVerboseURL, encodeURIComponent(text))
78+
path: util.format(LUISPredictMask, appId, appKey, encodeURIComponent(text), LUISVerbose)
8379
};
8480
httpHelper(LUISOptions, responseHandlers);
8581
},
@@ -92,17 +88,13 @@ var LUISClient = function(initData) {
9288
* on the success or failure of the web request
9389
*/
9490
reply: function (text, LUISresponse, responseHandlers, forceSetParameterName) {
95-
//TODO: When the reply can be used in the published version this condition has to be removed
96-
if (!preview) {
97-
throw new Error("Reply can only be used with the preview version");
98-
}
9991
text = validateText(text);
10092
validateLUISresponse(LUISresponse);
10193
validateResponseHandlers(responseHandlers);
10294
var LUISOptions = {
10395
hostname: LUISURL,
104-
path: util.format(LUISReplyMask, LUISPreviewURL, appId, appKey,
105-
LUISresponse.dialog.contextId, LUISVerboseURL, encodeURIComponent(text))
96+
path: util.format(LUISReplyMask, appId, appKey, encodeURIComponent(text),
97+
LUISresponse.dialog.contextId, LUISVerbose)
10698
};
10799
if (forceSetParameterName !== null && typeof forceSetParameterName === "string") {
108100
LUISOptions.path += util.format("&forceset=%s", forceSetParameterName);
@@ -143,8 +135,7 @@ var httpHelper = function (LUISOptions, responseHandlers) {
143135
* @param initData an object that has 4 propertes:
144136
* @1- appId a String containing the Application Id
145137
* @2- appKey a String containing the Subscription Key
146-
* @3- preview a Boolean to choose whether to use the preview version or not
147-
* @4- verbose a Boolean to choose whether to use the verbose version or not
138+
* @3- verbose a Boolean to choose whether to use the verbose version or not
148139
*/
149140
var validateInitData = function (initData) {
150141
if (initData === null || typeof initData === "undefined") {
@@ -212,7 +203,7 @@ var validateStringParam = function (param, paramName) {
212203
*/
213204
var validateBooleanParam = function (param, paramName) {
214205
if (typeof param === "undefined" || param === null) {
215-
param = false;
206+
param = true;
216207
}
217208
if (typeof param !== "boolean") {
218209
throw new Error(paramName + " flag is not boolean");

luis_sdk/luis_response.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,6 @@ module.exports = function (JsonResponse) {
4848
if (LUISresponse.hasOwnProperty("statusCode")) {
4949
throw new Error("Invalid Subscription Key");
5050
}
51-
if (LUISresponse.hasOwnProperty("topScoringIntent") && LUISresponse.topScoringIntent !== null
52-
&& typeof LUISresponse.topScoringIntent !== "undefined") {
53-
LUISresponse.intents = [LUISresponse.topScoringIntent];
54-
} else if (LUISresponse.hasOwnProperty("intents") && LUISresponse.intents !== null
55-
&& typeof LUISresponse.intents !== "undefined" && LUISresponse.intents.length > 0) {
56-
LUISresponse.topScoringIntent = LUISresponse.intents[0];
57-
}
5851
if (LUISresponse.hasOwnProperty("dialog") && typeof LUISresponse.dialog !== "undefined") {
5952
LUISresponse.dialog.isFinished = function () {
6053
return this.status === "Finished";

sample.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ const APPKEY = "Enter your Subscription Key here";
4343
var LUISclient = LUISClient({
4444
appId: APPID,
4545
appKey: APPKEY,
46-
preview: true,
4746
verbose: true
4847
});
4948

0 commit comments

Comments
 (0)