wingbot 3.64.1 → 3.65.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 +1 -1
- package/plugins/ai.wingbot.openai/plugin.js +35 -2
- package/plugins/plugins.json +24 -0
- package/src/Tester.js +7 -1
package/package.json
CHANGED
|
@@ -9,6 +9,8 @@ const compileWithState = require('../../src/utils/compileWithState');
|
|
|
9
9
|
|
|
10
10
|
const MSG_REPLACE = '#MSG-REPLACE#';
|
|
11
11
|
|
|
12
|
+
const CHAR_LIM = 4096;
|
|
13
|
+
|
|
12
14
|
function chatgptPlugin (params, configuration = {}) {
|
|
13
15
|
const {
|
|
14
16
|
openAiEndpoint = null,
|
|
@@ -18,6 +20,8 @@ function chatgptPlugin (params, configuration = {}) {
|
|
|
18
20
|
async function chatgpt (req, res) {
|
|
19
21
|
const content = req.text();
|
|
20
22
|
|
|
23
|
+
const charLim = params.charLim || CHAR_LIM;
|
|
24
|
+
|
|
21
25
|
const token = compileWithState(req, res, params.token).trim();
|
|
22
26
|
|
|
23
27
|
// gpt-3.5-turbo-0301 gpt-3.5-turbo
|
|
@@ -43,6 +47,12 @@ function chatgptPlugin (params, configuration = {}) {
|
|
|
43
47
|
|
|
44
48
|
const persona = compileWithState(req, res, params.persona).trim();
|
|
45
49
|
|
|
50
|
+
const continueConfig = params.continueConfig || [];
|
|
51
|
+
const lang = `${res.newState.lang || req.state.lang || 'default'}`.trim().toLocaleLowerCase();
|
|
52
|
+
const continueReply = continueConfig.find((c) => `${c.lang}`.trim().toLowerCase() === lang)
|
|
53
|
+
|| continueConfig.find((c) => ['default', '']
|
|
54
|
+
.includes(`${c.lang || ''}`.trim().toLowerCase()));
|
|
55
|
+
|
|
46
56
|
let body;
|
|
47
57
|
|
|
48
58
|
try {
|
|
@@ -62,6 +72,18 @@ function chatgptPlugin (params, configuration = {}) {
|
|
|
62
72
|
|
|
63
73
|
const ts = await res.getTranscript(Math.abs(limit), onlyFlag);
|
|
64
74
|
|
|
75
|
+
let total = (system ? system.length : 0)
|
|
76
|
+
+ (systemAfter ? systemAfter.length : 0)
|
|
77
|
+
+ maxTokens
|
|
78
|
+
+ content.length;
|
|
79
|
+
|
|
80
|
+
for (let i = ts.length - 1; i >= 0; i--) {
|
|
81
|
+
total += ts[i].text.length;
|
|
82
|
+
if (total > charLim) {
|
|
83
|
+
ts.splice(i, 1);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
65
87
|
const messages = [
|
|
66
88
|
...(system ? [{ role: 'system', content: system }] : []),
|
|
67
89
|
...ts.map((t) => ({ role: t.fromBot ? 'assistant' : 'user', content: t.text })),
|
|
@@ -106,6 +128,9 @@ function chatgptPlugin (params, configuration = {}) {
|
|
|
106
128
|
const sent = data.choices
|
|
107
129
|
.filter((ch) => ch.message && ch.message.role === 'assistant' && ch.message.content)
|
|
108
130
|
.map((ch) => {
|
|
131
|
+
|
|
132
|
+
let sliced = false;
|
|
133
|
+
|
|
109
134
|
let filtered = ch.message.content
|
|
110
135
|
.replace(/\n\n/g, '\n')
|
|
111
136
|
.split(/\n+(?!-)/g)
|
|
@@ -113,6 +138,7 @@ function chatgptPlugin (params, configuration = {}) {
|
|
|
113
138
|
|
|
114
139
|
if (filtered.length > 2) {
|
|
115
140
|
filtered = filtered.slice(0, filtered.length - 1);
|
|
141
|
+
sliced = true;
|
|
116
142
|
}
|
|
117
143
|
|
|
118
144
|
if (persona) {
|
|
@@ -120,7 +146,7 @@ function chatgptPlugin (params, configuration = {}) {
|
|
|
120
146
|
}
|
|
121
147
|
|
|
122
148
|
filtered
|
|
123
|
-
.forEach((t) => {
|
|
149
|
+
.forEach((t, fi) => {
|
|
124
150
|
let trim = t.trim();
|
|
125
151
|
|
|
126
152
|
if (annotation) {
|
|
@@ -151,7 +177,14 @@ function chatgptPlugin (params, configuration = {}) {
|
|
|
151
177
|
trim = `${annotation} ${trim}`;
|
|
152
178
|
}
|
|
153
179
|
|
|
154
|
-
res.text(trim)
|
|
180
|
+
res.text(trim, sliced && fi === (filtered.length - 1) && continueReply
|
|
181
|
+
? [
|
|
182
|
+
{
|
|
183
|
+
title: continueReply.title,
|
|
184
|
+
action: res.currentAction()
|
|
185
|
+
}
|
|
186
|
+
]
|
|
187
|
+
: null);
|
|
155
188
|
});
|
|
156
189
|
|
|
157
190
|
if (persona) {
|
package/plugins/plugins.json
CHANGED
|
@@ -578,6 +578,30 @@
|
|
|
578
578
|
"type": "textarea",
|
|
579
579
|
"name": "systemAfter",
|
|
580
580
|
"label": "Current message (system)"
|
|
581
|
+
},
|
|
582
|
+
{
|
|
583
|
+
"type": "array",
|
|
584
|
+
"name": "continueConfig",
|
|
585
|
+
"label": "Continue quick reply",
|
|
586
|
+
"keyPropertyName": "lang",
|
|
587
|
+
"columns": [
|
|
588
|
+
{
|
|
589
|
+
"name": "title",
|
|
590
|
+
"label": "Quick Reply"
|
|
591
|
+
}
|
|
592
|
+
],
|
|
593
|
+
"inputs": [
|
|
594
|
+
{
|
|
595
|
+
"type": "text",
|
|
596
|
+
"name": "lang",
|
|
597
|
+
"label": "Language (optional)"
|
|
598
|
+
},
|
|
599
|
+
{
|
|
600
|
+
"type": "text",
|
|
601
|
+
"name": "title",
|
|
602
|
+
"label": "Quick reply title"
|
|
603
|
+
}
|
|
604
|
+
]
|
|
581
605
|
}
|
|
582
606
|
],
|
|
583
607
|
"items": [
|
package/src/Tester.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
'use strict';
|
|
5
5
|
|
|
6
6
|
const assert = require('assert');
|
|
7
|
+
const { inspect } = require('util');
|
|
7
8
|
const deepExtend = require('deep-extend');
|
|
8
9
|
const Processor = require('./Processor');
|
|
9
10
|
const Request = require('./Request');
|
|
@@ -597,7 +598,12 @@ class Tester {
|
|
|
597
598
|
'\n===== actions =====\n',
|
|
598
599
|
this._actionsDebug(true),
|
|
599
600
|
'\n---- responses ----\n',
|
|
600
|
-
|
|
601
|
+
inspect(
|
|
602
|
+
this.responses.map(({ messaging_type: m, recipient, ...o }) => o),
|
|
603
|
+
false,
|
|
604
|
+
null,
|
|
605
|
+
true
|
|
606
|
+
),
|
|
601
607
|
'\n------ state ------\n',
|
|
602
608
|
Object.fromEntries(
|
|
603
609
|
Object.entries(this.getState().state)
|