theprogrammablemind 9.7.1-beta.15 → 9.7.1-beta.17
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 +14 -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
|
}
|
|
@@ -296,11 +298,12 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
|
296
298
|
// '\\n' from tests of '\n' from users. the former is because newline is not a valid json character so the testfile has it encoded
|
|
297
299
|
let queries = query.split(/\\n|\n/)
|
|
298
300
|
const summaries = [] // for error
|
|
301
|
+
logs = logs || []
|
|
299
302
|
try {
|
|
300
303
|
const response = {
|
|
301
304
|
hierarchy: [],
|
|
302
305
|
load_cache_time: 0.0,
|
|
303
|
-
logs:
|
|
306
|
+
logs: logs,
|
|
304
307
|
metadata: {
|
|
305
308
|
opChoices: []
|
|
306
309
|
},
|
|
@@ -334,6 +337,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
|
334
337
|
data.utterance = queries[0]
|
|
335
338
|
data.start_counter = startCounter
|
|
336
339
|
let json = await doWithRetries(retries, url, queryParams, data)
|
|
340
|
+
logs.push(...json.logs)
|
|
337
341
|
let resetData = false
|
|
338
342
|
if (json.code === 'NOT_IN_CACHE') {
|
|
339
343
|
resetData = true
|
|
@@ -367,20 +371,17 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
|
367
371
|
const summary = { summaries: json.summaries, length: json.contexts.length }
|
|
368
372
|
summaries.push(summary)
|
|
369
373
|
const { updatedContextIdCounter, contextsPrime, generatedPrime, paraphrasesPrime, paraphrasesParenthesizedPrime, generatedParenthesizedPrime, responsesPrime } =
|
|
370
|
-
await processContextsB({ contextIdCounter, calls, isTest, isProcess, isModule, rebuildingTemplate, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
|
|
374
|
+
await processContextsB({ contextIdCounter, logs, calls, isTest, isProcess, isModule, rebuildingTemplate, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
|
|
371
375
|
contextIdCounter = updatedContextIdCounter
|
|
372
376
|
if (isTest) {
|
|
373
377
|
const end = runtime.performance.performance.now()
|
|
374
378
|
clientSideTime = end - start
|
|
375
379
|
}
|
|
376
|
-
response.associations = json.associations
|
|
380
|
+
// response.associations = json.associations
|
|
377
381
|
response.learned_contextual_priorities = json.learned_contextual_priorities
|
|
378
382
|
response.hierarchy = json.hierarchy
|
|
379
383
|
response.load_cache_time += json.load_cache_time
|
|
380
|
-
appendNoDups(response.logs, json.logs)
|
|
381
384
|
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
385
|
appendNoDups(response.metadata.opChoices, json.metadata.opChoices)
|
|
385
386
|
response.times += json.times
|
|
386
387
|
response.clientSideTimes += clientSideTime
|
|
@@ -388,7 +389,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
|
388
389
|
response.version = json.version
|
|
389
390
|
response.explain_priorities = json.explain_priorities
|
|
390
391
|
response.contextual_priorities_ambiguities = json.contextual_priorities_ambiguities
|
|
391
|
-
response.rtf_associations = json.rtf_associations
|
|
392
|
+
// response.rtf_associations = json.rtf_associations
|
|
392
393
|
|
|
393
394
|
response.contexts = response.contexts.concat(contextsPrime)
|
|
394
395
|
response.generated = response.generated.concat(generatedPrime)
|
|
@@ -1064,7 +1065,7 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
|
|
|
1064
1065
|
config.fragmentsBeingBuilt.push({ query: query.query, contexts: results.contexts })
|
|
1065
1066
|
}
|
|
1066
1067
|
accumulators.summaries = accumulators.summaries.concat(results.summaries)
|
|
1067
|
-
accumulators.associations = accumulators.associations.concat(results.associations)
|
|
1068
|
+
// accumulators.associations = accumulators.associations.concat(results.associations)
|
|
1068
1069
|
accumulators.learned_contextual_priorities = accumulators.learned_contextual_priorities.concat(results.learned_contextual_priorities)
|
|
1069
1070
|
await looper(configs)
|
|
1070
1071
|
} catch (e) {
|
|
@@ -1100,7 +1101,7 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
|
|
|
1100
1101
|
await looper([])
|
|
1101
1102
|
} else {
|
|
1102
1103
|
try {
|
|
1103
|
-
config.addInternal(_.cloneDeep(extraConfig), { handleCalculatedProps: true })
|
|
1104
|
+
config.addInternal(_.cloneDeep(extraConfig), { handleCalculatedProps: true, addFirst: true })
|
|
1104
1105
|
} catch (e) {
|
|
1105
1106
|
const where = extraConfig.where ? ` ${extraConfig.where}` : ''
|
|
1106
1107
|
throw new Error(`Error processing extra config${where}: ${e.stack}}`)
|
|
@@ -1122,7 +1123,7 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
|
|
|
1122
1123
|
associations.sort()
|
|
1123
1124
|
}
|
|
1124
1125
|
const stabilizeOutput = (template) => {
|
|
1125
|
-
stabilizeAssociations(template.associations)
|
|
1126
|
+
// stabilizeAssociations(template.associations)
|
|
1126
1127
|
const stabilize = (results) => {
|
|
1127
1128
|
for (let i = 0; i < results.length; ++i) {
|
|
1128
1129
|
const result = results[i]
|
|
@@ -1137,7 +1138,7 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
|
|
|
1137
1138
|
delete result.logs
|
|
1138
1139
|
delete result.version
|
|
1139
1140
|
result.hierarchy.sort()
|
|
1140
|
-
stabilizeAssociations(result.associations)
|
|
1141
|
+
// stabilizeAssociations(result.associations)
|
|
1141
1142
|
result.learned_contextual_priorities = safeNoDups(result.learned_contextual_priorities)
|
|
1142
1143
|
}
|
|
1143
1144
|
}
|
|
@@ -1988,7 +1989,7 @@ const knowledgeModuleImpl = async ({
|
|
|
1988
1989
|
global.beforeObjects = _.cloneDeep(objects)
|
|
1989
1990
|
}
|
|
1990
1991
|
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 }))
|
|
1992
|
+
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
1993
|
} catch (error) {
|
|
1993
1994
|
printConfig()
|
|
1994
1995
|
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) {
|