wingbot 3.68.15 → 3.68.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wingbot",
3
- "version": "3.68.15",
3
+ "version": "3.68.17",
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
  */
@@ -97,14 +98,20 @@ class CachedModel extends CustomEntityDetectionModel {
97
98
  .filter((e) => this._entityDetectors.has(e.entity)
98
99
  && this._entityDetectors.get(e.entity).clearOverlaps);
99
100
 
101
+ if (this._options.verbose) this._log.log(`#NLP: ${text} [before]`, { before, intents, entities });
102
+
100
103
  [intents, entities] = this._attachEntities(intents, entities, before, expectedEntities);
101
104
 
102
105
  const after = local.entities
103
106
  .filter((e) => !this._entityDetectors.has(e.entity)
104
107
  || !this._entityDetectors.get(e.entity).clearOverlaps);
105
108
 
109
+ if (this._options.verbose) this._log.log(`#NLP: ${text} [after]`, { after, intents, entities });
110
+
106
111
  [intents, entities] = this._attachEntities(intents, entities, after);
107
112
 
113
+ if (this._options.verbose) this._log.log(`#NLP: ${text} [attached]`, { intents, entities, expectedEntities });
114
+
108
115
  return {
109
116
  text: local.text,
110
117
  intents,
@@ -94,6 +94,7 @@ class CustomEntityDetectionModel {
94
94
  /**
95
95
  * @param {object} options
96
96
  * @param {string} [options.prefix]
97
+ * @param {boolean} [options.verbose]
97
98
  * @param {{ warn: Function, error: Function, log: Function }} [log]
98
99
  */
99
100
  constructor (options, log = console) {
@@ -43,6 +43,7 @@ class WingbotModel extends CachedModel {
43
43
  * @param {string} options.model
44
44
  * @param {number} [options.cacheSize]
45
45
  * @param {number} [options.matches]
46
+ * @param {boolean} [options.verbose]
46
47
  * @param {Function} [options.fetch]
47
48
  * @param {{ warn: Function, log: Function, error: Function }} [log]
48
49
  */
@@ -101,6 +102,8 @@ class WingbotModel extends CachedModel {
101
102
  `matches=${encodeURIComponent(this._matches)}`
102
103
  ];
103
104
 
105
+ if (this._options.verbose) this._log.log(`#NLP: "${text}" [query]`, { matches: this._matches, localEntities: entities });
106
+
104
107
  if (entities) {
105
108
  const buf = await this._brotli(Buffer.from(JSON.stringify({ entities })));
106
109
  qs.push(`meta=${encodeURIComponent(buf.toString('base64url'))}`);
@@ -120,6 +123,8 @@ class WingbotModel extends CachedModel {
120
123
 
121
124
  const response = await res.json();
122
125
 
126
+ if (this._options.verbose) this._log.log(`#NLP: ${text} [response]`, { response });
127
+
123
128
  if (res.status >= 300) {
124
129
  this._log.warn(`AI query failed: ${response.message || res.statusText}`);
125
130
  return { intents: [], entities: [] };