wingbot 3.72.0 → 3.73.0

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.72.0",
3
+ "version": "3.73.0",
4
4
  "description": "Enterprise Messaging Bot Conversation Engine",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
package/src/LLM.js CHANGED
@@ -110,6 +110,7 @@ const Ai = require('./Ai');
110
110
  * @typedef {object} PromptInfo
111
111
  * @prop {LLMMessage[]} prompt
112
112
  * @prop {LLMMessage} result
113
+ * @prop {VectorSearchResult} [vectorSearchResult]
113
114
  */
114
115
 
115
116
  /**
@@ -122,6 +123,20 @@ const Ai = require('./Ai');
122
123
  * @prop {LogPrompt} logPrompt
123
124
  */
124
125
 
126
+ /**
127
+ * @typedef {object} VectorSearchDocument
128
+ * @property {string} id
129
+ * @property {string} name
130
+ * @property {string} text
131
+ * @property {number} cosineDistance
132
+ * @property {boolean} excludedByCosineDistanceThreshold
133
+ */
134
+ /**
135
+ * @typedef {object} VectorSearchResult
136
+ * @property {number} maximalCosineDistanceThreshold
137
+ * @property {number} nearestNeighbourCount
138
+ * @property {VectorSearchDocument[]} resultDocuments
139
+ */
125
140
  /**
126
141
  * @class LLM
127
142
  */
@@ -233,7 +248,7 @@ class LLM {
233
248
 
234
249
  const prompt = session.toArray(true);
235
250
  const result = await this._provider.requestChat(prompt, opts);
236
- this._logPrompt(prompt, result);
251
+ this.logPrompt(prompt, result);
237
252
  return result;
238
253
  }
239
254
 
@@ -241,11 +256,12 @@ class LLM {
241
256
  *
242
257
  * @param {LLMMessage[]} prompt
243
258
  * @param {LLMMessage} result
259
+ * @param {VectorSearchResult} [vectorSearchResult]
244
260
  */
245
- _logPrompt (prompt, result) {
261
+ logPrompt (prompt, result, vectorSearchResult) {
246
262
  this._lastResult = result;
247
263
  this._configuration.logger.logPrompt({
248
- prompt, result
264
+ prompt, result, vectorSearchResult
249
265
  });
250
266
  }
251
267
 
package/src/Processor.js CHANGED
@@ -405,6 +405,7 @@ class Processor extends EventEmitter {
405
405
  return { status: 304 };
406
406
  }
407
407
 
408
+ /** @type {LLMConfiguration} */
408
409
  const llmOptions = {
409
410
  provider: new LLMMockProvider(),
410
411
  ...this.options.llm
@@ -27,9 +27,6 @@ const DEFAULT_CACHE = 86400000; // 24 hours
27
27
  /** @typedef {import('../CallbackAuditLog')} AuditLog */
28
28
  /** @typedef {import('graphql')} GqlLib */
29
29
 
30
- /**
31
- * Experimental chatbot API
32
- */
33
30
  class GraphApi {
34
31
 
35
32
  /**
@@ -109,9 +109,24 @@ type LLMMessage {
109
109
  toolCalls: [ToolCall!]
110
110
  }
111
111
 
112
+ type VectorSearchDocument {
113
+ id: String!
114
+ name: String!
115
+ text: String!
116
+ cosineDistance: Float!
117
+ excludedByCosineDistanceThreshold: Boolean!
118
+ }
119
+
120
+ type VectorSearchResult {
121
+ maximalCosineDistanceThreshold: Float!
122
+ nearestNeighbourCount: Int!
123
+ resultDocuments: [VectorSearchDocument!]!
124
+ }
125
+
112
126
  type PromptInfo {
113
127
  prompt: [LLMMessage!]!
114
128
  result: LLMMessage!
129
+ vectorSearchResult: VectorSearchResult
115
130
  }
116
131
 
117
132
  type UserInteraction {
@@ -340,4 +355,4 @@ type Mutation {
340
355
 
341
356
  "subscribe with metadata"
342
357
  subscribeWithData (subscriptions: [SubscriptionData!]!): Boolean
343
- }
358
+ }
@@ -59,6 +59,18 @@ class PromptAssert {
59
59
  return this;
60
60
  }
61
61
 
62
+ /**
63
+ * Check if vector search documents contain selected string
64
+ *
65
+ * @param {string} search
66
+ * @returns {this}
67
+ */
68
+ vectorSearchContains (search) {
69
+ const documents = this._flatVectorSearchDocuments();
70
+ this._promptContains(search, documents, false, 'in vector search documents');
71
+ return this;
72
+ }
73
+
62
74
  /**
63
75
  *
64
76
  * @param {(value: LLMMessage, index: number, array: LLMMessage[]) => unknown} filter
@@ -79,6 +91,16 @@ class PromptAssert {
79
91
  .map((prompt) => prompt.result);
80
92
  }
81
93
 
94
+ /**
95
+ *
96
+ * @returns {LLMMessage[]}
97
+ */
98
+ _flatVectorSearchDocuments () {
99
+ return this._prompts
100
+ .flatMap((prompt) => prompt.vectorSearchResult?.resultDocuments || [])
101
+ .map((doc) => ({ role: 'system', content: doc.text }));
102
+ }
103
+
82
104
  _promptContains (search, messages, notContains = false, addMessage = 'No LLM message found') {
83
105
  if (messages.length === 0) {
84
106
  PromptAssert.debug(this._prompts, true);