theprogrammablemind 7.3.0 → 7.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.js +79 -18
- package/package.json +39 -39
- package/src/config.js +3 -0
package/client.js
CHANGED
@@ -270,16 +270,37 @@ const writeTest = (fn, query, objects, generated, paraphrases, responses, contex
|
|
270
270
|
writeTestFile(fn, tests)
|
271
271
|
}
|
272
272
|
|
273
|
-
const
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
273
|
+
const combineRange = (r1, r2) => {
|
274
|
+
let start = r2.start;
|
275
|
+
if (r1.start < r2.start) {
|
276
|
+
start = r1.start
|
277
|
+
}
|
278
|
+
let end = r2.end
|
279
|
+
if (r1.end > r2.end) {
|
280
|
+
end = r2.end
|
281
|
+
}
|
282
|
+
return { start, end }
|
283
|
+
}
|
284
|
+
|
285
|
+
const overlaps = (r1, context) => {
|
286
|
+
if (!context.range) {
|
287
|
+
return true;
|
288
|
+
}
|
289
|
+
const r2 = context.range
|
290
|
+
if (r1.start <= r2.end && r1.start >= r2.start) {
|
291
|
+
return true;
|
292
|
+
}
|
293
|
+
if (r1.end <= r2.end && r1.end >= r2.start) {
|
294
|
+
return true;
|
295
|
+
}
|
296
|
+
return false
|
297
|
+
}
|
298
|
+
|
299
|
+
const setupContexts = (rawContexts) => {
|
280
300
|
let first = true
|
301
|
+
const contexts = []
|
281
302
|
contexts.push({ marker: 'controlStart', controlRemove: true })
|
282
|
-
for (const context of
|
303
|
+
for (const context of rawContexts) {
|
283
304
|
if (first) {
|
284
305
|
first = false
|
285
306
|
} else {
|
@@ -288,14 +309,49 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
288
309
|
contexts.push(context)
|
289
310
|
}
|
290
311
|
contexts.push({ marker: 'controlEnd', controlRemove: true })
|
312
|
+
return contexts
|
313
|
+
}
|
314
|
+
|
315
|
+
const processContextsB = ({ config, hierarchy, semantics, generators, json, isTest, query, data, retries, url }) => {
|
316
|
+
// TODO fix this name to contextsPrime
|
317
|
+
const contextsPrime = []
|
318
|
+
const generatedPrime = []
|
319
|
+
const paraphrasesPrime = []
|
320
|
+
const responsesPrime = []
|
321
|
+
const contexts = setupContexts(json.contexts)
|
322
|
+
|
291
323
|
const objects = config.get('objects')
|
292
324
|
const args = { objects, isResponse: true, response: json, isTest, getObjects: getObjects(objects) }
|
293
325
|
setupArgs(args, config, json.logs, hierarchy)
|
294
326
|
const toDo = [...contexts]
|
295
327
|
args.insert = (context) => toDo.unshift(context)
|
328
|
+
let overlap, lastRange;
|
296
329
|
while (toDo.length > 0) {
|
297
|
-
args.calls.next()
|
298
330
|
const context = toDo.shift()
|
331
|
+
/*
|
332
|
+
if (false && query) {
|
333
|
+
if (config.wasChanged()) {
|
334
|
+
// process contexts that overlap
|
335
|
+
overlap = lastRange
|
336
|
+
} else {
|
337
|
+
config.watch()
|
338
|
+
}
|
339
|
+
if (overlap) {
|
340
|
+
if (overlaps(overlap, context)) {
|
341
|
+
// okay
|
342
|
+
query = query.slice(overlap.end+1)
|
343
|
+
data.utterance = query
|
344
|
+
debugger;
|
345
|
+
const json = await doWithRetries(retries, url, data)
|
346
|
+
toDo = setupContexts(json.contexts).slice(1) // take off the start context
|
347
|
+
}
|
348
|
+
overlap = undefined
|
349
|
+
}
|
350
|
+
lastRange = context.range
|
351
|
+
}
|
352
|
+
*/
|
353
|
+
|
354
|
+
args.calls.next()
|
299
355
|
let contextPrime = context
|
300
356
|
context.topLevel = true
|
301
357
|
try {
|
@@ -924,7 +980,7 @@ const build = async ({ config, target, beforeQuery, template, errorHandler = def
|
|
924
980
|
semantics: [],
|
925
981
|
associations: [],
|
926
982
|
}
|
927
|
-
const looper = (queries) => {
|
983
|
+
const looper = async (queries) => {
|
928
984
|
if (queries.length === 0) {
|
929
985
|
finish()
|
930
986
|
return
|
@@ -955,7 +1011,7 @@ const build = async ({ config, target, beforeQuery, template, errorHandler = def
|
|
955
1011
|
}
|
956
1012
|
|
957
1013
|
try {
|
958
|
-
const results = _process(config, query.query, { beforeQuery })
|
1014
|
+
const results = await _process(config, query.query, { beforeQuery })
|
959
1015
|
if (config.config.debug) {
|
960
1016
|
// TODO pass in the error handler like the other ones
|
961
1017
|
defaultInnerProcess(config, defaultErrorHandler, results)
|
@@ -967,7 +1023,7 @@ const build = async ({ config, target, beforeQuery, template, errorHandler = def
|
|
967
1023
|
results.key = { query: query.query, hierarchy }
|
968
1024
|
accumulators[property].push(results)
|
969
1025
|
accumulators.associations = accumulators.associations.concat(results.associations)
|
970
|
-
looper(queries)
|
1026
|
+
await looper(queries)
|
971
1027
|
} catch(e) {
|
972
1028
|
const error = { errors: [e], query: query.query };
|
973
1029
|
config.config.skipSemantics = null
|
@@ -979,7 +1035,7 @@ const build = async ({ config, target, beforeQuery, template, errorHandler = def
|
|
979
1035
|
const extraConfig = queryOrExtraConfig
|
980
1036
|
console.log('config', extraConfig)
|
981
1037
|
accumulators[property].push({ extraConfig: true, ...extraConfig })
|
982
|
-
looper(queries)
|
1038
|
+
await looper(queries)
|
983
1039
|
}
|
984
1040
|
}
|
985
1041
|
|
@@ -1031,7 +1087,7 @@ const build = async ({ config, target, beforeQuery, template, errorHandler = def
|
|
1031
1087
|
let todo = (template.queries || []).map((query) => { return { property: 'resultss', query, skipSemantics: false } })
|
1032
1088
|
todo = todo.concat((template.fragments || []).map((query) => { return Object.assign({}, toProperties(query), { property: 'fragments', skipSemantics: false }) }))
|
1033
1089
|
todo = todo.concat((template.semantics || []).map((definition) => { return { property: 'semantics', query: `${definition.from}\n${definition.to}`, skipSemantics: true } }))
|
1034
|
-
looper(Object.assign([], todo))
|
1090
|
+
await looper(Object.assign([], todo))
|
1035
1091
|
}
|
1036
1092
|
|
1037
1093
|
const knowledgeModule = async ({
|
@@ -1325,8 +1381,11 @@ const knowledgeModule = async ({
|
|
1325
1381
|
} else if (args.test || args.testVerbose || args.testAllVerbose) {
|
1326
1382
|
// TODO make test always a string
|
1327
1383
|
if (typeof test === 'string') {
|
1328
|
-
const l = (n) => {
|
1384
|
+
const l = (n, hasError) => {
|
1329
1385
|
if (n === 0) {
|
1386
|
+
if (hasError) {
|
1387
|
+
process.exit(-1)
|
1388
|
+
}
|
1330
1389
|
return
|
1331
1390
|
}
|
1332
1391
|
runTests(config, test, { debug: args.debug, testConfig: testConfig, verbose: args.testVerbose || args.testAllVerbose, stopAtFirstError: !args.testAllVerbose, beforeQuery, beforeTests, afterTests, beforeTest, afterTest }).then((results) => {
|
@@ -1335,6 +1394,7 @@ const knowledgeModule = async ({
|
|
1335
1394
|
vimdiff(result.expected, result.actual)
|
1336
1395
|
}
|
1337
1396
|
}
|
1397
|
+
let newError = false
|
1338
1398
|
if (results.length > 0) {
|
1339
1399
|
let headerShown = false
|
1340
1400
|
console.log('**************************** ERRORS ************************')
|
@@ -1346,7 +1406,7 @@ const knowledgeModule = async ({
|
|
1346
1406
|
}
|
1347
1407
|
console.log(' expected paraphrases', result.expected.paraphrases)
|
1348
1408
|
console.log(' actual paraphrases ', result.actual.paraphrases)
|
1349
|
-
|
1409
|
+
newError = true
|
1350
1410
|
headerShown = true
|
1351
1411
|
}
|
1352
1412
|
if (JSON.stringify(result.expected.responses) !== JSON.stringify(result.actual.responses)) {
|
@@ -1355,6 +1415,7 @@ const knowledgeModule = async ({
|
|
1355
1415
|
}
|
1356
1416
|
console.log(' expected responses ', result.expected.responses)
|
1357
1417
|
console.log(' actual responses ', result.actual.responses)
|
1418
|
+
newError = true
|
1358
1419
|
headerShown = true
|
1359
1420
|
}
|
1360
1421
|
}
|
@@ -1366,12 +1427,12 @@ const knowledgeModule = async ({
|
|
1366
1427
|
console.log('**************************** ERRORS ************************')
|
1367
1428
|
}
|
1368
1429
|
// const contexts = { failures: results }
|
1369
|
-
l(n - 1)
|
1430
|
+
l(n - 1, hasError || newError)
|
1370
1431
|
}).catch((error) => {
|
1371
1432
|
errorHandler(error)
|
1372
1433
|
})
|
1373
1434
|
}
|
1374
|
-
l(args.count)
|
1435
|
+
l(args.count, false)
|
1375
1436
|
} else {
|
1376
1437
|
test()
|
1377
1438
|
}
|
package/package.json
CHANGED
@@ -1,4 +1,42 @@
|
|
1
1
|
{
|
2
|
+
"dependencies": {
|
3
|
+
"base-64": "^1.0.0",
|
4
|
+
"sort-json": "^2.0.0",
|
5
|
+
"json-stable-stringify": "^1.0.1",
|
6
|
+
"lodash": "^4.17.20",
|
7
|
+
"json-diff": "^1.0.3",
|
8
|
+
"uuid": "^8.3.2",
|
9
|
+
"readline": "^1.3.0",
|
10
|
+
"scriptjs": "^2.5.9",
|
11
|
+
"deep-equal": "^2.0.4",
|
12
|
+
"underscore": "^1.13.1",
|
13
|
+
"node-fetch": "^2.6.1",
|
14
|
+
"fs": "0.0.1-security"
|
15
|
+
},
|
16
|
+
"author": "dev@thinktelligence.com",
|
17
|
+
"devDependencies": {
|
18
|
+
"eslint-plugin-promise": "^5.1.0",
|
19
|
+
"eslint-config-standard": "^16.0.3",
|
20
|
+
"eslint-plugin-import": "^2.23.4",
|
21
|
+
"@typescript-eslint/eslint-plugin": "^4.28.4",
|
22
|
+
"eslint-plugin-node": "^11.1.0",
|
23
|
+
"@typescript-eslint/parser": "^4.28.4",
|
24
|
+
"jest": "^26.6.3",
|
25
|
+
"eslint": "^7.31.0"
|
26
|
+
},
|
27
|
+
"version": "7.3.2",
|
28
|
+
"scripts": {
|
29
|
+
"to:debug": "node inspect node_modules/.bin/jest --runInBand -t NEO",
|
30
|
+
"to": "node node_modules/.bin/jest --runInBand -t NEO",
|
31
|
+
"test": "jest --config ./jest.config.json",
|
32
|
+
"tod": "node inspect node_modules/.bin/jest --runInBand -t NEO",
|
33
|
+
"lint": "eslint \"**/*.js\"",
|
34
|
+
"test:debug": "node inspect node_modules/.bin/jest --runInBand --config ./jest.config.json",
|
35
|
+
"test:watch": "npm run test -- --watch",
|
36
|
+
"lint:fix": "eslint \"**/*.js\" --fix"
|
37
|
+
},
|
38
|
+
"license": "ISC",
|
39
|
+
"name": "theprogrammablemind",
|
2
40
|
"keywords": [
|
3
41
|
"NLP",
|
4
42
|
"NLU",
|
@@ -8,17 +46,6 @@
|
|
8
46
|
"natural language understanding",
|
9
47
|
"chatbot"
|
10
48
|
],
|
11
|
-
"devDependencies": {
|
12
|
-
"@typescript-eslint/parser": "^4.28.4",
|
13
|
-
"jest": "^26.6.3",
|
14
|
-
"eslint": "^7.31.0",
|
15
|
-
"eslint-plugin-node": "^11.1.0",
|
16
|
-
"eslint-plugin-import": "^2.23.4",
|
17
|
-
"eslint-plugin-promise": "^5.1.0",
|
18
|
-
"eslint-config-standard": "^16.0.3",
|
19
|
-
"@typescript-eslint/eslint-plugin": "^4.28.4"
|
20
|
-
},
|
21
|
-
"name": "theprogrammablemind",
|
22
49
|
"files": [
|
23
50
|
"client.js",
|
24
51
|
"index.js",
|
@@ -34,32 +61,5 @@
|
|
34
61
|
"src/generators.js",
|
35
62
|
"src/semantics.js"
|
36
63
|
],
|
37
|
-
"
|
38
|
-
"author": "dev@thinktelligence.com",
|
39
|
-
"dependencies": {
|
40
|
-
"base-64": "^1.0.0",
|
41
|
-
"json-stable-stringify": "^1.0.1",
|
42
|
-
"uuid": "^8.3.2",
|
43
|
-
"readline": "^1.3.0",
|
44
|
-
"scriptjs": "^2.5.9",
|
45
|
-
"node-fetch": "^2.6.1",
|
46
|
-
"fs": "0.0.1-security",
|
47
|
-
"sort-json": "^2.0.0",
|
48
|
-
"deep-equal": "^2.0.4",
|
49
|
-
"lodash": "^4.17.20",
|
50
|
-
"underscore": "^1.13.1",
|
51
|
-
"json-diff": "^1.0.3"
|
52
|
-
},
|
53
|
-
"main": "index.js",
|
54
|
-
"license": "ISC",
|
55
|
-
"scripts": {
|
56
|
-
"test:watch": "npm run test -- --watch",
|
57
|
-
"lint:fix": "eslint \"**/*.js\" --fix",
|
58
|
-
"test": "jest --config ./jest.config.json",
|
59
|
-
"to:debug": "node inspect node_modules/.bin/jest --runInBand -t NEO",
|
60
|
-
"lint": "eslint \"**/*.js\"",
|
61
|
-
"test:debug": "node inspect node_modules/.bin/jest --runInBand --config ./jest.config.json",
|
62
|
-
"to": "node node_modules/.bin/jest --runInBand -t NEO",
|
63
|
-
"tod": "node inspect node_modules/.bin/jest --runInBand -t NEO"
|
64
|
-
}
|
64
|
+
"main": "index.js"
|
65
65
|
}
|