wingbot 3.58.2 → 3.59.1
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.
|
|
3
|
+
"version": "3.59.1",
|
|
4
4
|
"description": "Enterprise Messaging Bot Conversation Engine",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"doc": "npm run doc:gql && node ./bin/makeApiDoc.js && cpy ./CHANGELOG.md ./doc && gitbook install ./doc && gitbook build ./doc && rimraf -rf ./docs && rimraf --rf ./doc/CHANGELOG.md && move-cli ./doc/_book ./docs",
|
|
10
10
|
"test": "npm run test:lint && npm run test:coverage && npm run test:coverage:threshold",
|
|
11
11
|
"test:coverage": "nyc --reporter=html mocha ./test && nyc report",
|
|
12
|
-
"test:coverage:threshold": "nyc check-coverage --lines
|
|
12
|
+
"test:coverage:threshold": "nyc check-coverage --lines 90 --functions 89 --branches 80",
|
|
13
13
|
"test:backend": "mocha ./test",
|
|
14
14
|
"test:lint": "eslint --ext .js src test *.js plugins"
|
|
15
15
|
},
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
'use strict';
|
|
5
5
|
|
|
6
6
|
const fetch = require('node-fetch').default;
|
|
7
|
+
const Responder = require('../../src/Responder');
|
|
7
8
|
const compileWithState = require('../../src/utils/compileWithState');
|
|
8
9
|
|
|
9
10
|
const MSG_REPLACE = '#MSG-REPLACE#';
|
|
@@ -31,7 +32,7 @@ function chatgptPlugin (params, configuration = {}) {
|
|
|
31
32
|
|
|
32
33
|
const maxTokens = parseFloat(compileWithState(req, res, params.maxTokens).trim() || '512') || 512;
|
|
33
34
|
|
|
34
|
-
const limit = parseInt(compileWithState(req, res, params.
|
|
35
|
+
const limit = parseInt(compileWithState(req, res, params.limit).trim() || '10', 10) || 10;
|
|
35
36
|
|
|
36
37
|
const user = `${req.pageId}|${req.senderId}`;
|
|
37
38
|
|
|
@@ -45,6 +46,7 @@ function chatgptPlugin (params, configuration = {}) {
|
|
|
45
46
|
let body;
|
|
46
47
|
|
|
47
48
|
try {
|
|
49
|
+
res.setFlag('gpt');
|
|
48
50
|
res.typingOn();
|
|
49
51
|
|
|
50
52
|
body = {
|
|
@@ -56,7 +58,9 @@ function chatgptPlugin (params, configuration = {}) {
|
|
|
56
58
|
user
|
|
57
59
|
};
|
|
58
60
|
|
|
59
|
-
const
|
|
61
|
+
const onlyFlag = Math.sign(limit) === -1 ? 'gpt' : null;
|
|
62
|
+
|
|
63
|
+
const ts = await res.getTranscript(Math.abs(limit), onlyFlag);
|
|
60
64
|
|
|
61
65
|
const messages = [
|
|
62
66
|
...(system ? [{ role: 'system', content: system }] : []),
|
|
@@ -119,6 +123,28 @@ function chatgptPlugin (params, configuration = {}) {
|
|
|
119
123
|
.forEach((t) => {
|
|
120
124
|
let trim = t.trim();
|
|
121
125
|
|
|
126
|
+
if (annotation) {
|
|
127
|
+
// replace the annotation first
|
|
128
|
+
|
|
129
|
+
const replacements = annotation.split(MSG_REPLACE);
|
|
130
|
+
const last = replacements.length > 1
|
|
131
|
+
? replacements.length - 1
|
|
132
|
+
: replacements.length;
|
|
133
|
+
replacements.forEach((r, i) => {
|
|
134
|
+
const foundI = trim.indexOf(r.trim(), i === last
|
|
135
|
+
? trim.length - r.trim().length
|
|
136
|
+
: 0);
|
|
137
|
+
|
|
138
|
+
if (foundI === -1
|
|
139
|
+
|| (i === 0 && foundI > 0)
|
|
140
|
+
|| (i === last && (trim.length - foundI - r.length) > 0)) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
trim = trim.replace(r.trim(), '').trim();
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
122
148
|
if (annotation && annotation.includes(MSG_REPLACE)) {
|
|
123
149
|
trim = annotation.replace(MSG_REPLACE, trim);
|
|
124
150
|
} else if (annotation) {
|
package/plugins/plugins.json
CHANGED
|
@@ -552,6 +552,18 @@
|
|
|
552
552
|
}
|
|
553
553
|
]
|
|
554
554
|
},
|
|
555
|
+
{
|
|
556
|
+
"type": "text",
|
|
557
|
+
"name": "limit",
|
|
558
|
+
"label": "History context limit: (10)",
|
|
559
|
+
"validations": [
|
|
560
|
+
{
|
|
561
|
+
"type": "regexp",
|
|
562
|
+
"value": "^-?[0-9]*$",
|
|
563
|
+
"message": "History context limit should be a valid number"
|
|
564
|
+
}
|
|
565
|
+
]
|
|
566
|
+
},
|
|
555
567
|
{
|
|
556
568
|
"type": "text",
|
|
557
569
|
"name": "persona",
|
package/src/Responder.js
CHANGED
|
@@ -216,14 +216,25 @@ class Responder {
|
|
|
216
216
|
return this._configuration._cachedPersonas.get(nameKey);
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
+
/**
|
|
220
|
+
*
|
|
221
|
+
* @param {string} flag
|
|
222
|
+
* @returns {this}
|
|
223
|
+
*/
|
|
224
|
+
setFlag (flag) {
|
|
225
|
+
this._senderMeta.flag = flag;
|
|
226
|
+
return this;
|
|
227
|
+
}
|
|
228
|
+
|
|
219
229
|
/**
|
|
220
230
|
*
|
|
221
231
|
* Returns current conversation transcript
|
|
222
232
|
*
|
|
223
233
|
* @param {number} [limit]
|
|
234
|
+
* @param {string} [onlyFlag]
|
|
224
235
|
* @returns {Promise<Transcript[]>}
|
|
225
236
|
*/
|
|
226
|
-
async getTranscript (limit = 10) {
|
|
237
|
+
async getTranscript (limit = 10, onlyFlag = null) {
|
|
227
238
|
const { chatLogStorage } = this._messageSender;
|
|
228
239
|
if (!chatLogStorage) {
|
|
229
240
|
return [];
|
|
@@ -232,7 +243,8 @@ class Responder {
|
|
|
232
243
|
chatLogStorage,
|
|
233
244
|
this._senderId,
|
|
234
245
|
this._pageId,
|
|
235
|
-
limit
|
|
246
|
+
limit,
|
|
247
|
+
onlyFlag
|
|
236
248
|
);
|
|
237
249
|
const { responseTexts = [] } = chatLogStorage;
|
|
238
250
|
transcript.push(...responseTexts.map((text) => ({
|
|
@@ -29,14 +29,25 @@ const extractText = require('./extractText');
|
|
|
29
29
|
* @param {IChatStorage} chatLogStorage
|
|
30
30
|
* @param {string} senderId
|
|
31
31
|
* @param {string} pageId
|
|
32
|
-
* @param {number} limit
|
|
32
|
+
* @param {number} [limit]
|
|
33
|
+
* @param {string} [onlyFlag]
|
|
33
34
|
* @returns {Promise<Transcript[]>}
|
|
34
35
|
*/
|
|
35
|
-
async function transcriptFromHistory (
|
|
36
|
+
async function transcriptFromHistory (
|
|
37
|
+
chatLogStorage,
|
|
38
|
+
senderId,
|
|
39
|
+
pageId,
|
|
40
|
+
limit = 20,
|
|
41
|
+
onlyFlag = null
|
|
42
|
+
) {
|
|
36
43
|
if (typeof chatLogStorage.getInteractions !== 'function') {
|
|
37
44
|
return [];
|
|
38
45
|
}
|
|
39
|
-
|
|
46
|
+
let data = await chatLogStorage.getInteractions(senderId, pageId, limit);
|
|
47
|
+
|
|
48
|
+
if (onlyFlag) {
|
|
49
|
+
data = data.filter((h) => h.flag === onlyFlag);
|
|
50
|
+
}
|
|
40
51
|
|
|
41
52
|
return data
|
|
42
53
|
.map((turn) => {
|