@telefonica/luis-cli
Advanced tools
Comparing version 5.1.0 to 5.2.0
@@ -130,3 +130,3 @@ /// <reference types="node" /> | ||
export declare class LuisApiClient extends EventEmitter { | ||
protected applicationId: string; | ||
private config; | ||
private readonly serviceReq; | ||
@@ -133,0 +133,0 @@ private readonly provisionReq; |
@@ -25,4 +25,4 @@ "use strict"; | ||
}; | ||
const REQUESTS_PER_SECOND = 4; | ||
const SERVICE_API_REQUESTS_PER_SECOND = 20; | ||
const REQUESTS_PER_SECOND = 10; | ||
const SERVICE_API_REQUESTS_PER_SECOND = 10; | ||
const MAX_EXAMPLES_COUNT = 100; | ||
@@ -34,4 +34,3 @@ const MAX_PARALLEL_EXAMPLES_REQUESTS = 15; | ||
super(); | ||
this.applicationId = null; | ||
this.applicationId = config.applicationId; | ||
this.config = config; | ||
let baseUrl = config.baseUrl || LUIS_API_BASE_URL; | ||
@@ -84,3 +83,3 @@ this.serviceReq = request.defaults({ | ||
method: 'GET', | ||
uri: `/${this.applicationId}`, | ||
uri: `/${this.config.applicationId}`, | ||
qs: { q: sentence } | ||
@@ -113,3 +112,3 @@ }; | ||
let promiseThrottle = new PromiseThrottle({ | ||
requestsPerSecond: SERVICE_API_REQUESTS_PER_SECOND, | ||
requestsPerSecond: this.config.requestsPerSecond || SERVICE_API_REQUESTS_PER_SECOND, | ||
promiseImplementation: Promise | ||
@@ -123,3 +122,3 @@ }); | ||
method: 'GET', | ||
uri: `/${this.applicationId}` | ||
uri: `/${this.config.applicationId}` | ||
}; | ||
@@ -140,3 +139,3 @@ return this.retryRequest(opts, 200) | ||
method: 'GET', | ||
uri: `/${this.applicationId}/versions/${appVersion}/intents` | ||
uri: `/${this.config.applicationId}/versions/${appVersion}/intents` | ||
}; | ||
@@ -149,3 +148,3 @@ return this.retryRequest(opts, 200) | ||
method: 'POST', | ||
uri: `/${this.applicationId}/versions/${appVersion}/intents`, | ||
uri: `/${this.config.applicationId}/versions/${appVersion}/intents`, | ||
body: intent | ||
@@ -168,3 +167,3 @@ }; | ||
method: 'DELETE', | ||
uri: `/${this.applicationId}/versions/${appVersion}/intents/${intent.id}` | ||
uri: `/${this.config.applicationId}/versions/${appVersion}/intents/${intent.id}` | ||
}; | ||
@@ -183,3 +182,3 @@ return this.retryRequest(opts, 200) | ||
method: 'GET', | ||
uri: `/${this.applicationId}/versions/${appVersion}/entities` | ||
uri: `/${this.config.applicationId}/versions/${appVersion}/entities` | ||
}; | ||
@@ -192,3 +191,3 @@ return this.retryRequest(opts, 200) | ||
method: 'POST', | ||
uri: `/${this.applicationId}/versions/${appVersion}/entities`, | ||
uri: `/${this.config.applicationId}/versions/${appVersion}/entities`, | ||
body: entity | ||
@@ -212,3 +211,3 @@ }; | ||
method: 'DELETE', | ||
uri: `/${this.applicationId}/versions/${appVersion}/entities/${entity.id}` | ||
uri: `/${this.config.applicationId}/versions/${appVersion}/entities/${entity.id}` | ||
}; | ||
@@ -227,3 +226,3 @@ return this.retryRequest(opts, 200) | ||
method: 'GET', | ||
uri: `/${this.applicationId}/versions/${appVersion}/phraselists` | ||
uri: `/${this.config.applicationId}/versions/${appVersion}/phraselists` | ||
}; | ||
@@ -236,3 +235,3 @@ return this.retryRequest(opts, 200) | ||
method: 'POST', | ||
uri: `/${this.applicationId}/versions/${appVersion}/phraselists`, | ||
uri: `/${this.config.applicationId}/versions/${appVersion}/phraselists`, | ||
body: phraseList | ||
@@ -255,3 +254,3 @@ }; | ||
method: 'DELETE', | ||
uri: `/${this.applicationId}/versions/${appVersion}/phraselists/${phraseList.id}` | ||
uri: `/${this.config.applicationId}/versions/${appVersion}/phraselists/${phraseList.id}` | ||
}; | ||
@@ -270,3 +269,3 @@ return this.retryRequest(opts, 200) | ||
method: 'GET', | ||
uri: `/${this.applicationId}/versions/${appVersion}/examples`, | ||
uri: `/${this.config.applicationId}/versions/${appVersion}/examples`, | ||
qs: { skip, count } | ||
@@ -307,3 +306,3 @@ }; | ||
method: 'POST', | ||
uri: `/${this.applicationId}/versions/${appVersion}/examples`, | ||
uri: `/${this.config.applicationId}/versions/${appVersion}/examples`, | ||
body: examples | ||
@@ -329,3 +328,3 @@ }; | ||
method: 'DELETE', | ||
uri: `/${this.applicationId}/versions/${appVersion}/examples/${example.id}` | ||
uri: `/${this.config.applicationId}/versions/${appVersion}/examples/${example.id}` | ||
}; | ||
@@ -357,3 +356,3 @@ return this.retryRequest(opts, 200) | ||
method: 'POST', | ||
uri: `/${this.applicationId}/versions/${appVersion}/train` | ||
uri: `/${this.config.applicationId}/versions/${appVersion}/train` | ||
}; | ||
@@ -366,3 +365,3 @@ return this.retryRequest(opts, 202) | ||
method: 'GET', | ||
uri: `/${this.applicationId}/versions/${appVersion}/train` | ||
uri: `/${this.config.applicationId}/versions/${appVersion}/train` | ||
}; | ||
@@ -376,3 +375,3 @@ return this.retryRequest(opts, 200) | ||
method: 'POST', | ||
uri: `/${this.applicationId}/publish`, | ||
uri: `/${this.config.applicationId}/publish`, | ||
body: { | ||
@@ -398,3 +397,3 @@ versionId: appVersion, | ||
method: 'GET', | ||
uri: `/${this.applicationId}/versions/${appVersion}/export` | ||
uri: `/${this.config.applicationId}/versions/${appVersion}/export` | ||
}; | ||
@@ -401,0 +400,0 @@ return this.retryRequest(opts, 200) |
@@ -20,3 +20,5 @@ "use strict"; | ||
.option('-e, --endpoint <endpoint>', `LUIS endpoint (also got from the LUIS_ENDPOINT env var) [${DEFAULT_LUIS_ENDPOINT}]`, DEFAULT_LUIS_ENDPOINT) | ||
.option('-s, --subscription-key <subscription-key>', 'LUIS subscription key (also got from the LUIS_SUBSCRIPTION_KEY env var)'); | ||
.option('-s, --subscription-key <subscription-key>', 'LUIS subscription key (also got from the LUIS_SUBSCRIPTION_KEY env var)') | ||
.option('-q, --requests-per-second <float-or-integer-number>', 'The maximum number of requests per second to send ' + | ||
'to the authoring and service LUIS endpoint. Optional. Default value: 10 requests per second for each endpoint.'); | ||
program | ||
@@ -55,3 +57,3 @@ .command('update') | ||
.option('-a, --application-id <application-id>', 'LUIS application id (also got from the LUIS_APPLICATION_ID env var)') | ||
.option('-f, --errors-filename <filename>', `JSON file where prediction errors will be stored`) | ||
.option('-f, --errors <filename>', `JSON file where prediction errors will be stored`) | ||
.action(options => selectRunner(Commands.CheckPredictions, options)) | ||
@@ -69,3 +71,3 @@ .on('--help', function () { | ||
.option('-m, --model <filename>', 'JSON file containing the model whose examples will be used to test the LUIS application') | ||
.option('-f, --errors-filename <filename>', `JSON file where prediction errors will be stored`) | ||
.option('-f, --errors <filename>', `JSON file where prediction errors will be stored`) | ||
.action(options => selectRunner(Commands.TestExamples, options)) | ||
@@ -89,2 +91,3 @@ .on('--help', function () { | ||
let subscriptionKey = options.parent.subscriptionKey || process.env.LUIS_SUBSCRIPTION_KEY; | ||
let requestsPerSecond = parseFloat(options.parent.requestsPerSecond || process.env.REQUESTS_PER_SECOND); | ||
let applicationId = options.applicationId || process.env.LUIS_APPLICATION_ID; | ||
@@ -104,3 +107,4 @@ if (!subscriptionKey) { | ||
subscriptionKey: subscriptionKey, | ||
applicationId: applicationId | ||
applicationId: applicationId, | ||
requestsPerSecond: requestsPerSecond | ||
} | ||
@@ -134,3 +138,3 @@ }; | ||
printError('missing JSON file to which the differences will be saved. Provide one through the ' + | ||
'`-f, --errors-filename` option.'); | ||
'`-f, --errors` option.'); | ||
} | ||
@@ -145,3 +149,3 @@ runner = checkPrediction(luisTrainer, applicationId, options.appVersion, options.errors); | ||
printError('missing JSON file to which the differences will be saved. Provide one through the ' + | ||
'`-f, --errors-filename` option.'); | ||
'`-f, --errors` option.'); | ||
} | ||
@@ -258,3 +262,3 @@ runner = testExamples(luisTrainer, applicationId, options.model, options.errors); | ||
} | ||
function checkPrediction(luisTrainer, applicationId, appVersion, errorsFilename) { | ||
function checkPrediction(luisTrainer, applicationId, appVersion, errors) { | ||
console.log(`Checking predictions for the application ${applicationId}...`); | ||
@@ -271,3 +275,3 @@ luisTrainer.on('startGetAllExamples', () => { | ||
if (predictionResult.errors.length) { | ||
processPredictionResult(predictionResult, errorsFilename); | ||
processPredictionResult(predictionResult, errors); | ||
return predictionResult.errors.length; | ||
@@ -282,3 +286,3 @@ } | ||
} | ||
function testExamples(luisTrainer, applicationId, modelFilename, errorsFilename) { | ||
function testExamples(luisTrainer, applicationId, modelFilename, errors) { | ||
let model; | ||
@@ -309,3 +313,3 @@ try { | ||
if (predictionResult.errors.length) { | ||
processPredictionResult(predictionResult, errorsFilename); | ||
processPredictionResult(predictionResult, errors); | ||
return predictionResult.errors.length; | ||
@@ -320,3 +324,3 @@ } | ||
} | ||
function processPredictionResult(predictionResult, errorsFilename) { | ||
function processPredictionResult(predictionResult, errors) { | ||
let intentErrors = predictionResult.errors.filter(error => error.intentPredictions && !error.ambiguousPredictedIntent).length; | ||
@@ -341,4 +345,4 @@ let ambiguousIntentErrors = predictionResult.errors.filter(error => error.intentPredictions && error.ambiguousPredictedIntent).length; | ||
let sortedErrors = predictionResult.errors.sort((a, b) => a.intent.localeCompare(b.intent)); | ||
fs.writeFileSync(errorsFilename, JSON.stringify(sortedErrors, null, 2)); | ||
console.log(`\nAll the prediction errors have been saved in "${errorsFilename}"`); | ||
fs.writeFileSync(errors, JSON.stringify(sortedErrors, null, 2)); | ||
console.log(`\nAll the prediction errors have been saved in "${errors}"`); | ||
console.log(`\n\n ${colors.bold('INTENT PREDICTION ERRORS')}\n`); | ||
@@ -345,0 +349,0 @@ const HEADERS = { COL1: 'INTENTS', COL2: 'ERRORS', COL3: 'AMBIGUITIES' }; |
{ | ||
"name": "@telefonica/luis-cli", | ||
"version": "5.1.0", | ||
"version": "5.2.0", | ||
"description": "CLI for Microsoft LUIS API", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
@@ -188,4 +188,4 @@ /** | ||
// Maximum number of parallel requests per second to send to the API (to minimize 429 rate errors) | ||
const REQUESTS_PER_SECOND = 4; | ||
const SERVICE_API_REQUESTS_PER_SECOND = 20; // The private endpoint is not throttled | ||
const REQUESTS_PER_SECOND = 10; | ||
const SERVICE_API_REQUESTS_PER_SECOND = 10; // The private endpoint is not throttled | ||
// count parameter of the getExamples API (the API doesn't support more than 100) | ||
@@ -206,3 +206,3 @@ const MAX_EXAMPLES_COUNT = 100; | ||
export class LuisApiClient extends EventEmitter { | ||
protected applicationId: string = null; | ||
private config: LuisApiClientConfig; | ||
private readonly serviceReq: any; | ||
@@ -214,3 +214,3 @@ private readonly provisionReq: any; | ||
super(); | ||
this.applicationId = config.applicationId; | ||
this.config = config; | ||
let baseUrl = config.baseUrl || LUIS_API_BASE_URL; | ||
@@ -272,3 +272,3 @@ this.serviceReq = request.defaults({ | ||
method: 'GET', | ||
uri: `/${this.applicationId}`, | ||
uri: `/${this.config.applicationId}`, | ||
qs: { q: sentence } | ||
@@ -303,3 +303,3 @@ }; | ||
let promiseThrottle = new PromiseThrottle({ | ||
requestsPerSecond: SERVICE_API_REQUESTS_PER_SECOND, | ||
requestsPerSecond: this.config.requestsPerSecond || SERVICE_API_REQUESTS_PER_SECOND, | ||
promiseImplementation: Promise | ||
@@ -314,3 +314,3 @@ }); | ||
method: 'GET', | ||
uri: `/${this.applicationId}` | ||
uri: `/${this.config.applicationId}` | ||
}; | ||
@@ -332,3 +332,3 @@ return this.retryRequest(opts, 200) | ||
method: 'GET', | ||
uri: `/${this.applicationId}/versions/${appVersion}/intents` | ||
uri: `/${this.config.applicationId}/versions/${appVersion}/intents` | ||
}; | ||
@@ -342,3 +342,3 @@ return this.retryRequest(opts, 200) | ||
method: 'POST', | ||
uri: `/${this.applicationId}/versions/${appVersion}/intents`, | ||
uri: `/${this.config.applicationId}/versions/${appVersion}/intents`, | ||
body: intent | ||
@@ -363,3 +363,3 @@ }; | ||
method: 'DELETE', | ||
uri: `/${this.applicationId}/versions/${appVersion}/intents/${intent.id}` | ||
uri: `/${this.config.applicationId}/versions/${appVersion}/intents/${intent.id}` | ||
}; | ||
@@ -381,3 +381,3 @@ return this.retryRequest(opts, 200) | ||
method: 'GET', | ||
uri: `/${this.applicationId}/versions/${appVersion}/entities` | ||
uri: `/${this.config.applicationId}/versions/${appVersion}/entities` | ||
}; | ||
@@ -391,3 +391,3 @@ return this.retryRequest(opts, 200) | ||
method: 'POST', | ||
uri: `/${this.applicationId}/versions/${appVersion}/entities`, | ||
uri: `/${this.config.applicationId}/versions/${appVersion}/entities`, | ||
body: entity | ||
@@ -413,3 +413,3 @@ }; | ||
method: 'DELETE', | ||
uri: `/${this.applicationId}/versions/${appVersion}/entities/${entity.id}` | ||
uri: `/${this.config.applicationId}/versions/${appVersion}/entities/${entity.id}` | ||
}; | ||
@@ -430,3 +430,3 @@ return this.retryRequest(opts, 200) | ||
method: 'GET', | ||
uri: `/${this.applicationId}/versions/${appVersion}/phraselists` | ||
uri: `/${this.config.applicationId}/versions/${appVersion}/phraselists` | ||
}; | ||
@@ -440,3 +440,3 @@ return this.retryRequest(opts, 200) | ||
method: 'POST', | ||
uri: `/${this.applicationId}/versions/${appVersion}/phraselists`, | ||
uri: `/${this.config.applicationId}/versions/${appVersion}/phraselists`, | ||
body: phraseList | ||
@@ -461,3 +461,3 @@ }; | ||
method: 'DELETE', | ||
uri: `/${this.applicationId}/versions/${appVersion}/phraselists/${phraseList.id}` | ||
uri: `/${this.config.applicationId}/versions/${appVersion}/phraselists/${phraseList.id}` | ||
}; | ||
@@ -478,3 +478,3 @@ return this.retryRequest(opts, 200) | ||
method: 'GET', | ||
uri: `/${this.applicationId}/versions/${appVersion}/examples`, | ||
uri: `/${this.config.applicationId}/versions/${appVersion}/examples`, | ||
qs: { skip, count } | ||
@@ -528,3 +528,3 @@ }; | ||
method: 'POST', | ||
uri: `/${this.applicationId}/versions/${appVersion}/examples`, | ||
uri: `/${this.config.applicationId}/versions/${appVersion}/examples`, | ||
body: examples | ||
@@ -553,3 +553,3 @@ }; | ||
method: 'DELETE', | ||
uri: `/${this.applicationId}/versions/${appVersion}/examples/${example.id}` | ||
uri: `/${this.config.applicationId}/versions/${appVersion}/examples/${example.id}` | ||
}; | ||
@@ -584,3 +584,3 @@ return this.retryRequest(opts, 200) | ||
method: 'POST', | ||
uri: `/${this.applicationId}/versions/${appVersion}/train` | ||
uri: `/${this.config.applicationId}/versions/${appVersion}/train` | ||
}; | ||
@@ -594,3 +594,3 @@ return this.retryRequest(opts, 202) | ||
method: 'GET', | ||
uri: `/${this.applicationId}/versions/${appVersion}/train` | ||
uri: `/${this.config.applicationId}/versions/${appVersion}/train` | ||
}; | ||
@@ -605,3 +605,3 @@ return this.retryRequest(opts, 200) | ||
method: 'POST', | ||
uri: `/${this.applicationId}/publish`, | ||
uri: `/${this.config.applicationId}/publish`, | ||
// We don't really know what this body is for but it must be included for the API to work | ||
@@ -629,3 +629,3 @@ body: { | ||
method: 'GET', | ||
uri: `/${this.applicationId}/versions/${appVersion}/export` | ||
uri: `/${this.config.applicationId}/versions/${appVersion}/export` | ||
}; | ||
@@ -632,0 +632,0 @@ return this.retryRequest(opts, 200) |
@@ -25,3 +25,2 @@ /** | ||
const DEFAULT_LUIS_ENDPOINT = 'https://westus.api.cognitive.microsoft.com'; | ||
@@ -37,3 +36,5 @@ | ||
DEFAULT_LUIS_ENDPOINT) | ||
.option('-s, --subscription-key <subscription-key>', 'LUIS subscription key (also got from the LUIS_SUBSCRIPTION_KEY env var)'); | ||
.option('-s, --subscription-key <subscription-key>', 'LUIS subscription key (also got from the LUIS_SUBSCRIPTION_KEY env var)') | ||
.option('-q, --requests-per-second <float-or-integer-number>', 'The maximum number of requests per second to send ' + | ||
'to the authoring and service LUIS endpoint. Optional. Default value: 10 requests per second for each endpoint.'); | ||
@@ -49,3 +50,3 @@ program | ||
.option('-t, --is-staging <is-staging>', 'Flag indication if the publication is for the staging environment. ' + | ||
'Possible values: "true" or "false". Default: false.') | ||
'Possible values: "true" or "false". Default: false.') | ||
.action(options => selectRunner(Commands.Update, options)) | ||
@@ -76,3 +77,3 @@ .on('--help', function () { | ||
.option('-a, --application-id <application-id>', 'LUIS application id (also got from the LUIS_APPLICATION_ID env var)') | ||
.option('-f, --errors-filename <filename>', `JSON file where prediction errors will be stored`) | ||
.option('-f, --errors <filename>', `JSON file where prediction errors will be stored`) | ||
.action(options => selectRunner(Commands.CheckPredictions, options)) | ||
@@ -91,3 +92,3 @@ .on('--help', function () { | ||
.option('-m, --model <filename>', 'JSON file containing the model whose examples will be used to test the LUIS application') | ||
.option('-f, --errors-filename <filename>', `JSON file where prediction errors will be stored`) | ||
.option('-f, --errors <filename>', `JSON file where prediction errors will be stored`) | ||
.action(options => selectRunner(Commands.TestExamples, options)) | ||
@@ -118,2 +119,3 @@ .on('--help', function () { | ||
let subscriptionKey = options.parent.subscriptionKey || process.env.LUIS_SUBSCRIPTION_KEY; | ||
let requestsPerSecond = parseFloat(options.parent.requestsPerSecond || process.env.REQUESTS_PER_SECOND); | ||
let applicationId = options.applicationId || process.env.LUIS_APPLICATION_ID; | ||
@@ -136,3 +138,4 @@ | ||
subscriptionKey: subscriptionKey, | ||
applicationId: applicationId | ||
applicationId: applicationId, | ||
requestsPerSecond: requestsPerSecond | ||
} | ||
@@ -169,3 +172,3 @@ }; | ||
printError('missing JSON file to which the differences will be saved. Provide one through the ' + | ||
'`-f, --errors-filename` option.'); | ||
'`-f, --errors` option.'); | ||
} | ||
@@ -181,3 +184,3 @@ runner = checkPrediction(luisTrainer, applicationId, options.appVersion, options.errors); | ||
printError('missing JSON file to which the differences will be saved. Provide one through the ' + | ||
'`-f, --errors-filename` option.'); | ||
'`-f, --errors` option.'); | ||
} | ||
@@ -301,3 +304,3 @@ runner = testExamples(luisTrainer, applicationId, options.model, options.errors); | ||
function checkPrediction(luisTrainer: LuisTrainer, applicationId: string, appVersion: string, | ||
errorsFilename: string): Promise<number | void> { | ||
errors: string): Promise<number | void> { | ||
console.log(`Checking predictions for the application ${applicationId}...`); | ||
@@ -316,3 +319,3 @@ | ||
if (predictionResult.errors.length) { | ||
processPredictionResult(predictionResult, errorsFilename); | ||
processPredictionResult(predictionResult, errors); | ||
return predictionResult.errors.length; | ||
@@ -328,3 +331,3 @@ } else { | ||
function testExamples(luisTrainer: LuisTrainer, applicationId: string, modelFilename: string, | ||
errorsFilename: string): Promise<number | void> { | ||
errors: string): Promise<number | void> { | ||
let model: LuisModel.Model; | ||
@@ -356,3 +359,3 @@ try { | ||
if (predictionResult.errors.length) { | ||
processPredictionResult(predictionResult, errorsFilename); | ||
processPredictionResult(predictionResult, errors); | ||
return predictionResult.errors.length; | ||
@@ -367,3 +370,3 @@ } else { | ||
function processPredictionResult(predictionResult: PredictionResult, errorsFilename: string) { | ||
function processPredictionResult(predictionResult: PredictionResult, errors: string) { | ||
// Print a summary of errors | ||
@@ -393,4 +396,4 @@ let intentErrors = predictionResult.errors.filter(error => | ||
let sortedErrors = predictionResult.errors.sort((a, b) => a.intent.localeCompare(b.intent)); | ||
fs.writeFileSync(errorsFilename, JSON.stringify(sortedErrors, null, 2)); | ||
console.log(`\nAll the prediction errors have been saved in "${errorsFilename}"`); | ||
fs.writeFileSync(errors, JSON.stringify(sortedErrors, null, 2)); | ||
console.log(`\nAll the prediction errors have been saved in "${errors}"`); | ||
@@ -397,0 +400,0 @@ // Print intent stats |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
201005
2954
6