theprogrammablemind_4wp 9.7.1-beta.14 → 9.7.1-beta.16
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 +13 -13
- package/package.json +1 -1
- package/src/config.js +2 -0
- package/src/configHelpers.js +13 -12
- package/src/generators.js +7 -0
package/client.js
CHANGED
|
@@ -167,10 +167,12 @@ const writeTest = (fn, query, objects, generated, paraphrases, responses, contex
|
|
|
167
167
|
if (runtime.fs.existsSync(fn)) {
|
|
168
168
|
tests = JSON.parse(runtime.fs.readFileSync(fn))
|
|
169
169
|
}
|
|
170
|
+
/*
|
|
170
171
|
for (const association of associations) {
|
|
171
172
|
association.sort()
|
|
172
173
|
}
|
|
173
174
|
associations.sort()
|
|
175
|
+
*/
|
|
174
176
|
// tests[query] = sortJson({ paraphrases, responses, contexts, objects: convertToStable(objects), associations, metadata, config, developerTest: saveDeveloper }, { depth: 25 })
|
|
175
177
|
const results = sortJson({
|
|
176
178
|
query,
|
|
@@ -265,7 +267,7 @@ const throwErrorHandler = (error) => {
|
|
|
265
267
|
throw error
|
|
266
268
|
}
|
|
267
269
|
|
|
268
|
-
const _process = async (config, query, { initializer, commandLineArgs, credentials, writeTests, isProcess, isModule, isTest, saveDeveloper, rebuildingTemplate, testConfig, testsFN, errorHandler = throwErrorHandler } = {}) => {
|
|
270
|
+
const _process = async (config, query, { initializer, commandLineArgs, credentials, writeTests, logs, isProcess, isModule, isTest, saveDeveloper, rebuildingTemplate, testConfig, testsFN, errorHandler = throwErrorHandler } = {}) => {
|
|
269
271
|
if (credentials) {
|
|
270
272
|
config.server(credentials.server, credentials.key)
|
|
271
273
|
}
|
|
@@ -300,7 +302,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
|
300
302
|
const response = {
|
|
301
303
|
hierarchy: [],
|
|
302
304
|
load_cache_time: 0.0,
|
|
303
|
-
logs: [],
|
|
305
|
+
logs: logs || [],
|
|
304
306
|
metadata: {
|
|
305
307
|
opChoices: []
|
|
306
308
|
},
|
|
@@ -334,6 +336,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
|
334
336
|
data.utterance = queries[0]
|
|
335
337
|
data.start_counter = startCounter
|
|
336
338
|
let json = await doWithRetries(retries, url, queryParams, data)
|
|
339
|
+
logs.push(...json.logs)
|
|
337
340
|
let resetData = false
|
|
338
341
|
if (json.code === 'NOT_IN_CACHE') {
|
|
339
342
|
resetData = true
|
|
@@ -367,20 +370,17 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
|
367
370
|
const summary = { summaries: json.summaries, length: json.contexts.length }
|
|
368
371
|
summaries.push(summary)
|
|
369
372
|
const { updatedContextIdCounter, contextsPrime, generatedPrime, paraphrasesPrime, paraphrasesParenthesizedPrime, generatedParenthesizedPrime, responsesPrime } =
|
|
370
|
-
await processContextsB({ contextIdCounter, calls, isTest, isProcess, isModule, rebuildingTemplate, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
|
|
373
|
+
await processContextsB({ contextIdCounter, logs, calls, isTest, isProcess, isModule, rebuildingTemplate, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
|
|
371
374
|
contextIdCounter = updatedContextIdCounter
|
|
372
375
|
if (isTest) {
|
|
373
376
|
const end = runtime.performance.performance.now()
|
|
374
377
|
clientSideTime = end - start
|
|
375
378
|
}
|
|
376
|
-
response.associations = json.associations
|
|
379
|
+
// response.associations = json.associations
|
|
377
380
|
response.learned_contextual_priorities = json.learned_contextual_priorities
|
|
378
381
|
response.hierarchy = json.hierarchy
|
|
379
382
|
response.load_cache_time += json.load_cache_time
|
|
380
|
-
appendNoDups(response.logs, json.logs)
|
|
381
383
|
response.memory_free_percent = json.memory_free_percent
|
|
382
|
-
// appendNoDups(response.metadata.associations, json.metadata.associations)
|
|
383
|
-
// appendNoDups(response.metadata.priorities, json.metadata.priorities)
|
|
384
384
|
appendNoDups(response.metadata.opChoices, json.metadata.opChoices)
|
|
385
385
|
response.times += json.times
|
|
386
386
|
response.clientSideTimes += clientSideTime
|
|
@@ -388,7 +388,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
|
388
388
|
response.version = json.version
|
|
389
389
|
response.explain_priorities = json.explain_priorities
|
|
390
390
|
response.contextual_priorities_ambiguities = json.contextual_priorities_ambiguities
|
|
391
|
-
response.rtf_associations = json.rtf_associations
|
|
391
|
+
// response.rtf_associations = json.rtf_associations
|
|
392
392
|
|
|
393
393
|
response.contexts = response.contexts.concat(contextsPrime)
|
|
394
394
|
response.generated = response.generated.concat(generatedPrime)
|
|
@@ -1064,7 +1064,7 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
|
|
|
1064
1064
|
config.fragmentsBeingBuilt.push({ query: query.query, contexts: results.contexts })
|
|
1065
1065
|
}
|
|
1066
1066
|
accumulators.summaries = accumulators.summaries.concat(results.summaries)
|
|
1067
|
-
accumulators.associations = accumulators.associations.concat(results.associations)
|
|
1067
|
+
// accumulators.associations = accumulators.associations.concat(results.associations)
|
|
1068
1068
|
accumulators.learned_contextual_priorities = accumulators.learned_contextual_priorities.concat(results.learned_contextual_priorities)
|
|
1069
1069
|
await looper(configs)
|
|
1070
1070
|
} catch (e) {
|
|
@@ -1100,7 +1100,7 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
|
|
|
1100
1100
|
await looper([])
|
|
1101
1101
|
} else {
|
|
1102
1102
|
try {
|
|
1103
|
-
config.addInternal(_.cloneDeep(extraConfig), { handleCalculatedProps: true })
|
|
1103
|
+
config.addInternal(_.cloneDeep(extraConfig), { handleCalculatedProps: true, addFirst: true })
|
|
1104
1104
|
} catch (e) {
|
|
1105
1105
|
const where = extraConfig.where ? ` ${extraConfig.where}` : ''
|
|
1106
1106
|
throw new Error(`Error processing extra config${where}: ${e.stack}}`)
|
|
@@ -1122,7 +1122,7 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
|
|
|
1122
1122
|
associations.sort()
|
|
1123
1123
|
}
|
|
1124
1124
|
const stabilizeOutput = (template) => {
|
|
1125
|
-
stabilizeAssociations(template.associations)
|
|
1125
|
+
// stabilizeAssociations(template.associations)
|
|
1126
1126
|
const stabilize = (results) => {
|
|
1127
1127
|
for (let i = 0; i < results.length; ++i) {
|
|
1128
1128
|
const result = results[i]
|
|
@@ -1137,7 +1137,7 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
|
|
|
1137
1137
|
delete result.logs
|
|
1138
1138
|
delete result.version
|
|
1139
1139
|
result.hierarchy.sort()
|
|
1140
|
-
stabilizeAssociations(result.associations)
|
|
1140
|
+
// stabilizeAssociations(result.associations)
|
|
1141
1141
|
result.learned_contextual_priorities = safeNoDups(result.learned_contextual_priorities)
|
|
1142
1142
|
}
|
|
1143
1143
|
}
|
|
@@ -1988,7 +1988,7 @@ const knowledgeModuleImpl = async ({
|
|
|
1988
1988
|
global.beforeObjects = _.cloneDeep(objects)
|
|
1989
1989
|
}
|
|
1990
1990
|
try {
|
|
1991
|
-
await processResults(_process(config, args.query, { commandLineArgs: args, isProcess, isModule: !isProcess, dontAddAssociations: args.dontAddAssociations, writeTests: args.save || args.saveDeveloper, saveDeveloper: args.saveDeveloper, testConfig, testsFN: test }))
|
|
1991
|
+
await processResults(_process(config, args.query, { commandLineArgs: args, isProcess, logs: [], isModule: !isProcess, dontAddAssociations: args.dontAddAssociations, writeTests: args.save || args.saveDeveloper, saveDeveloper: args.saveDeveloper, testConfig, testsFN: test }))
|
|
1992
1992
|
} catch (error) {
|
|
1993
1993
|
printConfig()
|
|
1994
1994
|
console.log('Error', error)
|
package/package.json
CHANGED
package/src/config.js
CHANGED
package/src/configHelpers.js
CHANGED
|
@@ -345,9 +345,11 @@ const processContext = async (context, { objects = {}, config, logs = [] }) => {
|
|
|
345
345
|
const setupProcessB = ({ config, initializer, allowDelta = false, rebuildingTemplate = false } = {}) => {
|
|
346
346
|
const key = config._key
|
|
347
347
|
const data = Object.assign({ key, version: '3' }, { uuid: config._uuid })
|
|
348
|
+
/*
|
|
348
349
|
if (rebuildingTemplate) {
|
|
349
350
|
data.return_rtf_associations = true
|
|
350
351
|
}
|
|
352
|
+
*/
|
|
351
353
|
if (allowDelta && config.allowDelta && config.hasDelta()) {
|
|
352
354
|
// console.log('config', config)
|
|
353
355
|
data.delta = config.delta()
|
|
@@ -405,7 +407,7 @@ const setupContexts = (rawContexts) => {
|
|
|
405
407
|
return contexts
|
|
406
408
|
}
|
|
407
409
|
|
|
408
|
-
const processContextsB = async ({ config, calls, hierarchy, semantics, generators, json, isTest, isProcess, isModule, rebuildingTemplate, isInstance, instance, query, data, retries, url, commandLineArgs, forTemplate, contextIdCounter }) => {
|
|
410
|
+
const processContextsB = async ({ config, calls, hierarchy, logs, semantics, generators, json, isTest, isProcess, isModule, rebuildingTemplate, isInstance, instance, query, data, retries, url, commandLineArgs, forTemplate, contextIdCounter }) => {
|
|
409
411
|
// TODO fix this name to contextsPrime
|
|
410
412
|
const contextsPrime = []
|
|
411
413
|
const generatedPrime = []
|
|
@@ -417,10 +419,7 @@ const processContextsB = async ({ config, calls, hierarchy, semantics, generator
|
|
|
417
419
|
|
|
418
420
|
const objects = config.get('objects')
|
|
419
421
|
const args = { objects, isResponse: true, response: json, isTest, isInstance, getObjects: getObjects(objects), instance, contexts, isProcess, isModule, calls }
|
|
420
|
-
|
|
421
|
-
json.logs = []
|
|
422
|
-
}
|
|
423
|
-
setupArgs(args, config, json.logs, hierarchy)
|
|
422
|
+
setupArgs(args, config, logs, hierarchy)
|
|
424
423
|
const toDo = [...contexts]
|
|
425
424
|
args.insert = (context) => toDo.unshift(context)
|
|
426
425
|
let overlap, lastRange
|
|
@@ -438,7 +437,7 @@ const processContextsB = async ({ config, calls, hierarchy, semantics, generator
|
|
|
438
437
|
}
|
|
439
438
|
const generateParenthesized = isTest || (commandLineArgs && commandLineArgs.save)
|
|
440
439
|
if (!config.get('skipSemantics')) {
|
|
441
|
-
const semantics = config.getSemantics(
|
|
440
|
+
const semantics = config.getSemantics(logs)
|
|
442
441
|
try {
|
|
443
442
|
contextPrime = await semantics.apply(args, context)
|
|
444
443
|
// contextPrime.greg = 'yes'
|
|
@@ -481,11 +480,11 @@ const processContextsB = async ({ config, calls, hierarchy, semantics, generator
|
|
|
481
480
|
// noop
|
|
482
481
|
} else {
|
|
483
482
|
let assumed = { isResponse: true }
|
|
484
|
-
const generated = contextPrime.isResponse ? await config.getGenerators(
|
|
483
|
+
const generated = contextPrime.isResponse ? await config.getGenerators(logs).apply({ ...args, assumed }, contextPrime, assumed) : ''
|
|
485
484
|
let generatedParenthesized = []
|
|
486
485
|
if (generateParenthesized) {
|
|
487
486
|
config.setParenthesized(true)
|
|
488
|
-
generatedParenthesized = contextPrime.isResponse ? await config.getGenerators(
|
|
487
|
+
generatedParenthesized = contextPrime.isResponse ? await config.getGenerators(logs).apply({ ...args, assumed }, contextPrime, assumed) : ''
|
|
489
488
|
config.setParenthesized(false)
|
|
490
489
|
}
|
|
491
490
|
// assumed = { paraphrase: true, response: false };
|
|
@@ -493,11 +492,11 @@ const processContextsB = async ({ config, calls, hierarchy, semantics, generator
|
|
|
493
492
|
if (generateParenthesized) {
|
|
494
493
|
config.setParenthesized(false)
|
|
495
494
|
}
|
|
496
|
-
const paraphrases = await config.getGenerators(
|
|
495
|
+
const paraphrases = await config.getGenerators(logs).apply({ ...args, assumed }, contextPrime, assumed)
|
|
497
496
|
let paraphrasesParenthesized = []
|
|
498
497
|
if (generateParenthesized) {
|
|
499
498
|
config.setParenthesized(true)
|
|
500
|
-
paraphrasesParenthesized = await config.getGenerators(
|
|
499
|
+
paraphrasesParenthesized = await config.getGenerators(logs).apply({ ...args, assumed }, contextPrime, assumed)
|
|
501
500
|
config.setParenthesized(false)
|
|
502
501
|
}
|
|
503
502
|
contextsPrime.push(contextPrime)
|
|
@@ -526,9 +525,9 @@ const processContextsB = async ({ config, calls, hierarchy, semantics, generator
|
|
|
526
525
|
}
|
|
527
526
|
e.context = contextPrime
|
|
528
527
|
if (e.logs) {
|
|
529
|
-
e.logs = e.logs.concat(
|
|
528
|
+
e.logs = e.logs.concat(logs)
|
|
530
529
|
} else {
|
|
531
|
-
e.logs =
|
|
530
|
+
e.logs = logs
|
|
532
531
|
}
|
|
533
532
|
e.metadata = json.metadata
|
|
534
533
|
if (json.trace) {
|
|
@@ -545,10 +544,12 @@ const loadInstance = async (config, instance) => {
|
|
|
545
544
|
const transitoryMode = global.transitoryMode
|
|
546
545
|
global.transitoryMode = false
|
|
547
546
|
|
|
547
|
+
/*
|
|
548
548
|
const rl = instance.resultss.length
|
|
549
549
|
if (rl > 0) {
|
|
550
550
|
config.addAssociations(instance.resultss[instance.resultss.length - 1].rtf_associations || [])
|
|
551
551
|
}
|
|
552
|
+
*/
|
|
552
553
|
/*
|
|
553
554
|
TODO needs updating if still wanted
|
|
554
555
|
if (instance && (instance.associations || instance.learned_contextual_priorities)) {
|
package/src/generators.js
CHANGED
|
@@ -191,6 +191,13 @@ class Generators {
|
|
|
191
191
|
const log = (message) => { this.logs.push(message) }
|
|
192
192
|
// this.logs.push(`Generators: applied ${generator.toString()}\n to\n ${stringify(context)}`)
|
|
193
193
|
let errorMessage = 'The apply function did not return a value'
|
|
194
|
+
if (process.env.TPMKMS_TRACE) {
|
|
195
|
+
console.error("TPMKMS_TRACE", debug.counter("TPMKMS_TRACE"))
|
|
196
|
+
console.error(generator.toLabel())
|
|
197
|
+
console.error(generator.toString())
|
|
198
|
+
console.log(`To debug this use debug.breakAt('${args.calls.current()}')`)
|
|
199
|
+
}
|
|
200
|
+
|
|
194
201
|
try {
|
|
195
202
|
generated = await generator.apply(args, objects, context, hierarchy, config, response, log, options)
|
|
196
203
|
} catch (e) {
|