wingbot 3.68.16 → 3.68.18

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wingbot",
3
- "version": "3.68.16",
3
+ "version": "3.68.18",
4
4
  "description": "Enterprise Messaging Bot Conversation Engine",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
package/src/Ai.js CHANGED
@@ -237,20 +237,26 @@ class Ai {
237
237
  * @template {CustomEntityDetectionModel} T
238
238
  * @param {string|WingbotModel|T} model - wingbot model name or AI plugin
239
239
  * @param {string} prefix - model prefix
240
+ * @param {object} [options={}]
241
+ * @param {number} [options.cacheSize]
242
+ * @param {boolean} [options.verbose]
243
+ * @param {number} [options.cachePhrasesTime]
244
+ *
240
245
  *
241
246
  * @returns {T}
242
247
  * @memberOf Ai
243
248
  */
244
- register (model = null, prefix = this.DEFAULT_PREFIX) {
249
+ register (model = null, prefix = this.DEFAULT_PREFIX, options = {}) {
245
250
  /** @type {T} */
246
251
  let modelObj;
247
252
 
248
253
  if (!model) {
249
254
  // @ts-ignore
250
- modelObj = new CustomEntityDetectionModel({ prefix });
255
+ modelObj = new CustomEntityDetectionModel({ ...options, prefix });
251
256
  } else if (typeof model === 'string') {
252
257
  // @ts-ignore
253
258
  modelObj = new WingbotModel({
259
+ ...options,
254
260
  model,
255
261
  prefix
256
262
  }, this.logger);
@@ -37,6 +37,7 @@ class CachedModel extends CustomEntityDetectionModel {
37
37
  * @param {object} options
38
38
  * @param {string} [options.prefix]
39
39
  * @param {number} [options.cacheSize]
40
+ * @param {boolean} [options.verbose]
40
41
  * @param {number} [options.cachePhrasesTime]
41
42
  * @param {{ warn: Function, error: Function, log: Function }} [log]
42
43
  */
@@ -304,13 +304,14 @@ class CustomEntityDetectionModel {
304
304
  return zLen - aLen;
305
305
  });
306
306
 
307
+ if (this._options.verbose) this._log.log('#NLP [nonOverlapping]', { entities, expectedEntities, justDuplicates });
308
+
307
309
  let res = [];
308
310
 
309
311
  for (let i = 0; i < entities.length; i++) {
310
312
  const entity = entities[i];
311
313
 
312
314
  const isExpected = expectedEntities.includes(entity.entity);
313
-
314
315
  const duplicate = res
315
316
  .find((e) => e.start === entity.start && e.end === entity.end);
316
317
 
@@ -353,6 +354,10 @@ class CustomEntityDetectionModel {
353
354
  const othersConflict = res.some((e) => putback === e
354
355
  || (e.start < putback.end && e.end > putback.start));
355
356
 
357
+ this._log.log(`#NLP (${i}|${k} [putBack: ${entity.entity}|${putback.entity}] (${i}|${k})`, {
358
+ putback, entity, currentConflict, othersConflict
359
+ });
360
+
356
361
  if (!currentConflict && !othersConflict) {
357
362
  res.push(putback);
358
363
  }
@@ -360,6 +365,12 @@ class CustomEntityDetectionModel {
360
365
  }
361
366
  }
362
367
 
368
+ if (this._options.verbose) {
369
+ this._log.log(`#NLP (${i}) [nonOverlapping| ${entity.entity}:${entity.value}]`, {
370
+ willRemoveEntity: overlapping, overlapping, duplicate, isExpected, entity
371
+ });
372
+ }
373
+
363
374
  if (!overlapping) {
364
375
  res.push(entity);
365
376
  }
@@ -102,7 +102,7 @@ class WingbotModel extends CachedModel {
102
102
  `matches=${encodeURIComponent(this._matches)}`
103
103
  ];
104
104
 
105
- if (this._options.verbose) this._log.log(`#NLP: "${text}" [query]`, { matches: this._matches, localEntities: entities });
105
+ if (this._options.verbose) this._log.log(`#NLP: ${text} [query]`, { matches: this._matches, localEntities: entities });
106
106
 
107
107
  if (entities) {
108
108
  const buf = await this._brotli(Buffer.from(JSON.stringify({ entities })));
@@ -123,7 +123,7 @@ class WingbotModel extends CachedModel {
123
123
 
124
124
  const response = await res.json();
125
125
 
126
- if (this._options.verbose) this._log.log(`#NLP: ${text} [response]`, { response });
126
+ if (this._options.verbose) this._log.log(`#NLP: ${text} [response]`, response);
127
127
 
128
128
  if (res.status >= 300) {
129
129
  this._log.warn(`AI query failed: ${response.message || res.statusText}`);