Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

orchestrator-core

Package Overview
Dependencies
Maintainers
1
Versions
100
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

orchestrator-core - npm Package Compare versions

Comparing version 4.10.0-dev.20200923.0daddf9 to 4.11.0-beta.0

tests/snapshot/VA.txt

74

oc_app.js
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
function buf2hex(buffer) { // buffer is an ArrayBuffer

@@ -9,3 +8,2 @@ return Array.prototype.map.call(new Uint8Array(buffer), x => ('00' + x.toString(16)).slice(-2)).join(' ');

const oc = require('./orchestrator-core.node');

@@ -15,13 +13,13 @@ const util = require('util')

async function addExamples() {
console.log('Create Orchestrator..')
console.log('---- Create Orchestrator..')
const orchestrator = new oc.Orchestrator();
console.log('Loading NLR..')
const load_result = orchestrator.load('../dep/model'); // Return boolean, separate load.
console.log('---- Loading NLR..')
const load_result = orchestrator.load('../dep/model/roberta'); // Return boolean, separate load.
if (load_result === false)
{
console.log('Loading NLR failed!!');
console.log('ERROR: Loading NLR failed!!');
}
console.log('Creating labeler..');
console.log('---- Creating labeler..');
let labeler = orchestrator.createLabelResolver();

@@ -35,3 +33,3 @@

{
console.log("Set runtime params successfully!")
console.log("SUCCESS: set runtime params successfully!")
}

@@ -55,10 +53,10 @@ else

console.log('Adding example COMPLEX..');
console.log('---- Adding example COMPLEX..');
var val = labeler.addExample(example);
if (val == true)
{
console.log('Added example!');
console.log('SUCCESS: added example - 0!');
}
console.log('Adding Labels array.')
console.log('---- Adding Labels array.')
const example_multi_single = {

@@ -78,3 +76,3 @@ text: 'another book a flight to miami.',

{
console.log('Added example2!');
console.log('SUCCESS: added example - 1!');
}

@@ -104,3 +102,3 @@ const example_multi_label = {

{
console.log('Added example2!');
console.log('SUCCESS: added example - 2!');
}

@@ -114,3 +112,3 @@ const example2 = {

{
console.log('Added example2!');
console.log('SUCCESS: added example - 3!');
}

@@ -124,13 +122,22 @@ const example3 = {

{
console.log('Added example3!');
console.log('SUCCESS: added example3 - 4!');
}
//
// Score
//
console.log('---- Scoring')
var results = labeler.score("hey");
console.log(util.inspect(results, true, null, true /* enable colors */));
//
// Score
//
console.log('---- Creating Snapshot')
var snapshot = labeler.createSnapshot();
console.log('Created snapshot!');
console.log('Going to create labeler #2');
console.log('SUCCESS: created snapshot!');
console.log('---- Going to create labeler #2');
let labeler2 = orchestrator.createLabelResolver(snapshot);
console.log('Created Labeler #2.');
console.log('SUCCESS: created Labeler #2.');

@@ -140,3 +147,3 @@ //

//
console.log('Getting examples')
console.log('---- Getting examples')
let examples = labeler2.getExamples();

@@ -147,2 +154,3 @@ console.log(util.inspect(examples, true, null, true /* enable colors */));

//
console.log('---- Removing examples')
labeler2.removeExample(example3);

@@ -155,17 +163,23 @@ examples = labeler2.getExamples();

//
console.log('---- Get Labels');
var labels = labeler2.getLabels();
console.log(util.inspect(labels, true, null, true /* enable colors */));
//
// Get Intent Labels
//
console.log('---- Get Intent Labels');
var labels = labeler2.getLabels(1);
console.log(util.inspect(labels, true, null, true /* enable colors */));
}
addExamples();
const readline = require('readline');
const rl = readline.createInterface({ input: process.stdin, output: process.stdout});
rl.question('>', (answer) => {
console.log('Completed embedding:')
console.log(buf2hex(embedding))
rl.close();
});
// ==== TODO-CANNOT-GET-embedding-FROM-ABI ==== const readline = require('readline');
// ==== TODO-CANNOT-GET-embedding-FROM-ABI ==== const rl = readline.createInterface({ input: process.stdin, output: process.stdout});
// ==== TODO-CANNOT-GET-embedding-FROM-ABI ====
// ==== TODO-CANNOT-GET-embedding-FROM-ABI ==== rl.question('>', (answer) => {
// ==== TODO-CANNOT-GET-embedding-FROM-ABI ==== console.log('Completed embedding:')
// ==== TODO-CANNOT-GET-embedding-FROM-ABI ==== console.log(buf2hex(embedding))
// ==== TODO-CANNOT-GET-embedding-FROM-ABI ==== rl.close();
// ==== TODO-CANNOT-GET-embedding-FROM-ABI ==== });

@@ -5,3 +5,3 @@ {

"description": "Orchestrator for Node.js",
"version": "4.10.0-dev.20200923.0daddf9",
"version": "4.11.0-beta.0",
"license": "MIT",

@@ -26,4 +26,5 @@ "keywords": [

"node-addon-api": "^3.0.0",
"node-gyp": "7.0.0",
"node-pre-gyp": "0.15.0"
"node-gyp": "^7.1.2",
"node-pre-gyp": "^0.15.0",
"onnxruntime": "1.4.0"
},

@@ -45,3 +46,3 @@ "binary": {

"test": "nyc mocha tests/",
"start": "cross-env OC_MODEL_DIR='../dep/model/' node oc_app.js",
"start": "cross-env OC_MODEL_DIR='../dep/model/roberta/' node oc_app.js",
"build:dev": "node-gyp -j 16 build --debug",

@@ -48,0 +49,0 @@ "build": "node-gyp -j 16 build",

@@ -34,3 +34,3 @@ // Copyright (c) Microsoft Corporation. All rights reserved.

if (config.hasOwnProperty('VocabFile') && config.hasOwnProperty('MergeFile')
&& config.hasOwnProperty('ModelFile') && config.hasOwnProperty('Version')) {
&& config.hasOwnProperty('ModelFile') && config.hasOwnProperty('Name')) {
// console.log(' => VALID!');

@@ -102,4 +102,47 @@ return true;

it('0) Create BLU file example.', function () {
this.timeout(1000000);
// Arrange
var orc = new oc.Orchestrator();
var onnx_dir = findOnnxDir(1);
orc.load(onnx_dir);
var labeler = orc.createLabelResolver();
try {
const snapshotPath = path.join(__dirname, 'snapshot', 'VA.txt');
var data = fs.readFileSync(snapshotPath, 'utf8');
console.log('OPENING FILE ' + snapshotPath);
var lines = data.split(/\r?\n/);
var skipfirst = false;
for (let line of lines) {
if (!line.trim()) {
continue;
}
// console.log(line);
tokens = line.split('\t');
if (skipfirst)
skipfirst = false;
else
{
var example = {
label: tokens[0],
text: tokens[1],
};
it('should succeed creating orchestrator.', function () {
var result = labeler.addExample(example);
}
}
var snapshot = labeler.createSnapshot();
console.log('Created snapshot!');
const outputSnapshotPath = path.join(__dirname, 'snapshot', 'VA_snapshot.blu');
fs.writeFile(outputSnapshotPath, snapshot, (err) => {
if (err) { throw err; }
console.log('Snapshot saved!' + outputSnapshotPath);
});
} catch(e) {
console.log('Error:', e.stack);
}
});
it('1) should succeed creating orchestrator.', function () {
// Initialize Orchestrator

@@ -110,5 +153,5 @@ const nlr = new oc.Orchestrator();

it('should load NLR.', function () {
it('2) should load NLR.', function () {
// Initialize Orchestrator
this.timeout(600000);
this.timeout(1000000);
const nlr = new oc.Orchestrator();

@@ -118,3 +161,3 @@ const result = nlr.load();

});
it('should throw load() method must provide valid path to NLR.', async function () {
it('3) should throw load() method must provide valid path to NLR.', async function () {
// Initialize Orchestrator

@@ -127,7 +170,7 @@ this.timeout(600);

});
it('should create a LabelResolver without a NLR nodel, but with a BLU snapshot.', function () {
it('4) should create a LabelResolver without a NLR nodel, but with a BLU snapshot.', function () {
this.timeout(1000000);
const orchestrator = new oc.Orchestrator();
console.log(`DEBUGGING - nodejs - orchestrator-core: __dirname=${__dirname}`);
assert.ok(orchestrator.load(), 'cannot load without a NLR');
assert.ok(orchestrator.load(), 'orchestrator.load() failed');

@@ -141,12 +184,61 @@ const snapshotPath = path.join(__dirname, 'snapshot', 'Email.blu');

assert.ok(snapshotContent.length > 0, `snapshot content length is ${snapshotContent.length}`);
const labelResolver = orchestrator.createLabelResolver(snapshotContent);
console.log(`DEBUGGING - nodejs - orchestrator-core: labelResolver=${labelResolver}`);
assert.ok(labelResolver !== undefined, 'cannot create a labelResolver object');
const examples = labelResolver.getExamples();
console.log(`DEBUGGING - nodejs - orchestrator-core: examples=${examples}`);
// console.log(`DEBUGGING - nodejs - orchestrator-core: examples=${examples}`);
console.log(`DEBUGGING - nodejs - orchestrator-core: examples.length=${examples.length}`);
assert.ok(examples.length === 601, `#examples is ${examples.length}`);
const labels = labelResolver.getLabels();
console.log(`DEBUGGING - nodejs - orchestrator-core: labels=${labels}`);
console.log(`DEBUGGING - nodejs - orchestrator-core: labels.length=${labels.length}`);
assert.ok(labels.length === 15, `#labels is ${labels.length}`);
const labelsIntent = labelResolver.getLabels(1);
console.log(`DEBUGGING - nodejs - orchestrator-core: labelsIntent=${labelsIntent}`);
console.log(`DEBUGGING - nodejs - orchestrator-core: labelsIntent.length=${labelsIntent.length}`);
assert.ok(labelsIntent.length === 15, `#labelsIntent is ${labelsIntent.length}`);
});
it('should throw Invalid JSON config or path provided', function () {
it('5) Add a snapshot test after creating an empty LabelResolver.', function () {
this.timeout(1000000);
const orchestrator = new oc.Orchestrator();
console.log(`DEBUGGING - nodejs - orchestrator-core: __dirname=${__dirname}`);
assert.ok(orchestrator.load(), 'orchestrator.load() failed');
console.log('DEBUGGING - nodejs - orchestrator-core: ready to call OrchestratorHelper.getSnapshotFromFile()');
const snapshotPath = path.join(__dirname, 'snapshot', 'Email.blu');
console.log(`DEBUGGING - nodejs - orchestrator-core: snapshotPath=${snapshotPath}`);
assert.ok(fs.existsSync(snapshotPath), `snapshot file ${snapshotPath} does not exist`);
const snapshot = new TextEncoder().encode(fs.readFileSync(snapshotPath, 'utf8'));
assert.ok(snapshot.length > 0, `snapshot content length is ${snapshot.length}`);
console.log(`DEBUGGING - nodejs - orchestrator-core: typeof(snapshot)=${typeof snapshot}`);
console.log(`DEBUGGING - nodejs - orchestrator-core: snapshot.byteLength=${snapshot.byteLength}`);
console.log('DEBUGGING - nodejs - orchestrator-core: after calling OrchestratorHelper.getSnapshotFromFile()');
const labelResolver = orchestrator.createLabelResolver();
console.log(`DEBUGGING - nodejs - orchestrator-core: labelResolver=${labelResolver}`);
assert.ok(labelResolver !== undefined, 'cannot create a labelResolver object');
console.log('DEBUGGING - nodejs - orchestrator-core: ready to call LabelResolver.addSnapshot()');
labelResolver.addSnapshot(snapshot);
console.log('DEBUGGING - nodejs - orchestrator-core: after calling LabelResolver.addSnapshot()');
const examples = labelResolver.getExamples();
// console.log(`DEBUGGING - nodejs - orchestrator-core: examples=${examples}`);
console.log(`DEBUGGING - nodejs - orchestrator-core: examples.length=${examples.length}`);
assert.ok(examples.length === 601, `#examples is ${examples.length}`);
const labels = labelResolver.getLabels();
console.log(`DEBUGGING - nodejs - orchestrator-core: labels=${labels}`);
console.log(`DEBUGGING - nodejs - orchestrator-core: labels.length=${labels.length}`);
assert.ok(labels.length === 15, `#labels is ${labels.length}`);
const labelsIntent = labelResolver.getLabels(1);
console.log(`DEBUGGING - nodejs - orchestrator-core: labelsIntent=${labelsIntent}`);
console.log(`DEBUGGING - nodejs - orchestrator-core: labelsIntent.length=${labelsIntent.length}`);
assert.ok(labelsIntent.length === 15, `#labelsIntent is ${labelsIntent.length}`);
});
it('6) should throw Invalid JSON config or path provided', function () {
this.timeout(100000);

@@ -156,5 +248,6 @@ const nlr = new oc.Orchestrator();

// assert.throws(() => { nlr.load('/foo/bar/path'); }, /^TypeError: Invalid JSON config or path provided: .*/);
console.log('DEBUGGING - nodejs - orchestrator-core: after an exception caught -- 0');
});
it('should throw Invalid config JSON syntax in config file', function () {
it('7) should throw Invalid config JSON syntax in config file', function () {
this.timeout(100000);

@@ -166,5 +259,6 @@ expected = Error;

// assert.throws(() => { nlr.load(bad_config); }, /^TypeError: Invalid config JSON syntax in config file: .*/);
console.log('DEBUGGING - nodejs - orchestrator-core: after an exception caught -- 1');
});
it('should throw Invalid or non-existent JSON config file', function () {
it('8) should throw Invalid or non-existent JSON config file', function () {
this.timeout(100000);

@@ -176,5 +270,6 @@ expected = Error;

// assert.throws(() => { nlr.load(no_config); }, /^TypeError: Invalid or non-existent JSON config file: .*/);
console.log('DEBUGGING - nodejs - orchestrator-core: after an exception caught -- 2');
});
it('Add example.', function () {
it('9) Add example.', function () {
// Arrange

@@ -191,4 +286,29 @@ var labeler = this.orchestrator.createLabelResolver();

});
it('10) Add snapshot as file.', function () {
// Arrange
var labeler = this.orchestrator.createLabelResolver();
const example = {
label: 'travel',
text: 'book a flight to miami.',
};
var result = labeler.addExample(example);
const snapshot = labeler.createSnapshot();
const snapshot_file = 'snapshot.blu';
try {
fs.unlinkSync(snapshot_file)
} catch(err) {
// Swallow error
}
fs.appendFileSync(snapshot_file, Buffer.from(snapshot));
it('Remove example.', function () {
// Act
var labeler2 = this.orchestrator.createLabelResolver();
result = labeler2.addSnapshot(fs.readFileSync(snapshot_file, null));
// Assert
assert.strictEqual(result, true, 'Failed to add snapshot');
});
it('11) Remove example.', function () {
// Arrange

@@ -216,3 +336,3 @@ var orc = new oc.Orchestrator();

});
it('Add example - complex label.', function () {
it('12) Add example - complex label.', function () {
// Arrange

@@ -234,5 +354,3 @@ var labeler = this.orchestrator.createLabelResolver();

});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc