Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
//
const msRest = require("@azure/ms-rest-js");
const LUIS = require("@azure/cognitiveservices-luis-authoring");
//
//
const key = 'REPLACE-WITH-YOUR-ASSIGNED-AUTHORING-KEY';
const endpoint = "https://REPLACE-WITH-RESOURCE-NAME.cognitiveservices.azure.com/"
//
//
const luisAuthoringCredentials = new msRest.ApiKeyCredentials({
inHeader: { "Ocp-Apim-Subscription-Key": key }
});
const luisAuthoringClient = new LUIS.LUISAuthoringClient(
luisAuthoringCredentials,
endpoint
);
//
//
const delayTimer = async timeInMs => {
return await new Promise(resolve => {
setTimeout(resolve, timeInMs);
});
};
//
//
const create_app = async () => {
const create_app_payload = {
//
//
const authoringEndpoint = `https://${authoringResourceName}.cognitiveservices.azure.com/`;
const predictionEndpoint = `https://${predictionResourceName}.cognitiveservices.azure.com/`;
const appName = "Contoso Pizza Company";
const versionId = "0.1";
const intentName = "OrderPizzaIntent";
//
//
const luisAuthoringCredentials = new msRest.ApiKeyCredentials({
inHeader: { "Ocp-Apim-Subscription-Key": authoringKey }
});
const client = new LUIS_Authoring.LUISAuthoringClient(
luisAuthoringCredentials,
authoringEndpoint
);
//
// Create app
const appId = await createApp(client, appName, versionId);
//
await client.model.addIntent(
appId,
versionId,
{ name: intentName }
);
//
throw new Error(
"Set/export your LUIS subscription key as an environment variable."
);
}
const endpoint = process.env["LUIS_AUTHORING_ENDPOINT"];
if (!endpoint) {
throw new Error("Set/export your LUIS endpoint as an environment variable.");
}
//
//
const luisAuthoringCredentials = new msRest.ApiKeyCredentials({
inHeader: { "Ocp-Apim-Subscription-Key": key }
});
const luisAuthoringClient = new LUIS.LUISAuthoringClient(
luisAuthoringCredentials,
endpoint
);
//
//
const delayTimer = async timeInMs => {
return await new Promise(resolve => {
setTimeout(resolve, timeInMs);
});
};
//
//
const create_app = async () => {
const create_app_payload = {
*
* If the environment variable is created after the application is launched in a console or with Visual
* Studio, the shell (or Visual Studio) needs to be closed and reloaded for changes to take effect.
*/
const key = process.env['LUIS_AUTHORING_KEY'];
if (!key) {
throw new Error('Set/export your LUIS subscription key as an environment variable.');
}
const endpoint = process.env['LUIS_AUTHORING_ENDPOINT'];
if (!endpoint) {
throw new Error('Set/export your LUIS endpoint as an environment variable.');
}
const creds = new msRest.ApiKeyCredentials({ inHeader: { 'Ocp-Apim-Subscription-Key': key } });
const client = new LUIS.LUISAuthoringClient(creds, endpoint);
function create_app() {
var d = new Date(Date.now());
var name = "Contoso " + (d.getMonth() + 1) + "-" + d.getDate() + "-" + d.getFullYear() + " " +
d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
var description = "Flight booking app built with Azure SDK for Java.";
var version = "0.1";
var locale = "en-us";
var create_app_payload = {
name: name,
description: description,
initialVersionId: version,
culture: locale
};
return client.apps.add(create_app_payload).then((result) => {
console.log("Created LUIS app with ID " + result.body);
const authoring_endpoint = process.env[authoring_endpoint_var];
const runtime_key_var = 'LUIS_RUNTIME_KEY';
if (!process.env[runtime_key_var]) {
throw new Error('please set/export the following environment variable: ' + runtime_key_var);
}
const runtime_key = process.env[runtime_key_var];
const runtime_endpoint_var = 'LUIS_RUNTIME_ENDPOINT';
if (!process.env[runtime_endpoint_var]) {
throw new Error('please set/export the following environment variable: ' + runtime_endpoint_var);
}
const runtime_endpoint = process.env[runtime_endpoint_var];
const authoring_creds = new msRest.ApiKeyCredentials({ inHeader: { 'Ocp-Apim-Subscription-Key': authoring_key } });
const authoring_client = new authoring.LUISAuthoringClient(authoring_creds, authoring_endpoint);
const runtime_creds = new msRest.ApiKeyCredentials({ inHeader: { 'Ocp-Apim-Subscription-Key': runtime_key } });
const runtime_client = new runtime.LUISRuntimeClient(runtime_creds, runtime_endpoint);
function create_app() {
var create_app_payload = {
domainName: "HomeAutomation",
culture: "en-us"
};
return authoring_client.apps.addCustomPrebuiltDomain(create_app_payload).then((result) => {
console.log("Created LUIS app with ID " + result.body)
let app_info = {
id : result.body,
version : "0.1"
}
return app_info