wingbot 3.57.0 → 3.58.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
|
@@ -6,7 +6,13 @@
|
|
|
6
6
|
const fetch = require('node-fetch').default;
|
|
7
7
|
const compileWithState = require('../../src/utils/compileWithState');
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
const MSG_REPLACE = '#MSG-REPLACE#';
|
|
10
|
+
|
|
11
|
+
function chatgptPlugin (params, configuration = {}) {
|
|
12
|
+
const {
|
|
13
|
+
openAiEndpoint = null,
|
|
14
|
+
openAiApiKey = null
|
|
15
|
+
} = configuration;
|
|
10
16
|
|
|
11
17
|
async function chatgpt (req, res) {
|
|
12
18
|
const content = req.text();
|
|
@@ -31,6 +37,11 @@ function chatgptPlugin (params) {
|
|
|
31
37
|
|
|
32
38
|
const systemAfter = compileWithState(req, res, params.systemAfter).trim();
|
|
33
39
|
|
|
40
|
+
const replacedAnnotation = `${params.annotation || ''}`.replace(/\{\{message\}\}/g, MSG_REPLACE);
|
|
41
|
+
const annotation = compileWithState(req, res, replacedAnnotation).trim();
|
|
42
|
+
|
|
43
|
+
const persona = compileWithState(req, res, params.persona).trim();
|
|
44
|
+
|
|
34
45
|
let body;
|
|
35
46
|
|
|
36
47
|
try {
|
|
@@ -58,11 +69,17 @@ function chatgptPlugin (params) {
|
|
|
58
69
|
|
|
59
70
|
const useFetch = params.fetch || fetch;
|
|
60
71
|
|
|
61
|
-
const
|
|
72
|
+
const apiUrl = openAiEndpoint
|
|
73
|
+
? `${openAiEndpoint}`
|
|
74
|
+
: 'https://api.openai.com/v1';
|
|
75
|
+
|
|
76
|
+
const response = await useFetch(`${apiUrl}/chat/completions`, {
|
|
62
77
|
method: 'POST',
|
|
63
78
|
headers: {
|
|
64
79
|
'Content-Type': 'application/json',
|
|
65
|
-
|
|
80
|
+
...(openAiEndpoint
|
|
81
|
+
? { 'api-key': token || openAiApiKey }
|
|
82
|
+
: { Authorization: `Bearer ${token || openAiApiKey}` })
|
|
66
83
|
},
|
|
67
84
|
body: JSON.stringify(body)
|
|
68
85
|
});
|
|
@@ -92,8 +109,26 @@ function chatgptPlugin (params) {
|
|
|
92
109
|
filtered = filtered.slice(0, filtered.length - 1);
|
|
93
110
|
}
|
|
94
111
|
|
|
112
|
+
if (persona) {
|
|
113
|
+
res.setPersona({ name: persona });
|
|
114
|
+
}
|
|
115
|
+
|
|
95
116
|
filtered
|
|
96
|
-
.forEach((t) =>
|
|
117
|
+
.forEach((t) => {
|
|
118
|
+
let trim = t.trim();
|
|
119
|
+
|
|
120
|
+
if (annotation && annotation.includes(MSG_REPLACE)) {
|
|
121
|
+
trim = annotation.replace(MSG_REPLACE, trim);
|
|
122
|
+
} else if (annotation) {
|
|
123
|
+
trim = `${annotation} ${trim}`;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
res.text(trim);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
if (persona) {
|
|
130
|
+
res.setPersona({ name: null });
|
|
131
|
+
}
|
|
97
132
|
|
|
98
133
|
return ch;
|
|
99
134
|
});
|
|
@@ -19,18 +19,15 @@ function slotsRegister ({
|
|
|
19
19
|
doneAction,
|
|
20
20
|
intents = ''
|
|
21
21
|
}) {
|
|
22
|
-
|
|
23
22
|
const useIntents = intents.split(',')
|
|
24
23
|
.map((i) => i.trim());
|
|
25
24
|
|
|
26
25
|
/** @type {Router<SlotBotState>} */
|
|
27
26
|
const bot = new Router();
|
|
28
27
|
|
|
29
|
-
const setEntities = [];
|
|
30
|
-
|
|
31
28
|
/** @type {SlotsResolver} */
|
|
32
29
|
const handler = async (req, res, postBack) => {
|
|
33
|
-
|
|
30
|
+
const setEntities = [];
|
|
34
31
|
|
|
35
32
|
/** @type {SlotState[]} */
|
|
36
33
|
const slotState = steps.map((step) => {
|
|
@@ -80,7 +77,7 @@ function slotsRegister ({
|
|
|
80
77
|
|
|
81
78
|
res.setState({
|
|
82
79
|
_slotState: slotState,
|
|
83
|
-
_slotSteps: steps,
|
|
80
|
+
_slotSteps: steps.slice(),
|
|
84
81
|
_slotDone: doneAction,
|
|
85
82
|
...setStateEntities
|
|
86
83
|
});
|
package/plugins/plugins.json
CHANGED
|
@@ -488,7 +488,7 @@
|
|
|
488
488
|
{
|
|
489
489
|
"id": "ai.wingbot.openai",
|
|
490
490
|
"name": "OpenAI - Chat",
|
|
491
|
-
"description": "Use within fallback to attach ChatGPT to your chatbot",
|
|
491
|
+
"description": "Use within fallback to attach ChatGPT to your chatbot\n\nYou can use {{message}} variable in a message annotation.",
|
|
492
492
|
"availableSince": 3.54,
|
|
493
493
|
"editable": false,
|
|
494
494
|
"isFactory": true,
|
|
@@ -552,6 +552,16 @@
|
|
|
552
552
|
}
|
|
553
553
|
]
|
|
554
554
|
},
|
|
555
|
+
{
|
|
556
|
+
"type": "text",
|
|
557
|
+
"name": "persona",
|
|
558
|
+
"label": "Message persona name"
|
|
559
|
+
},
|
|
560
|
+
{
|
|
561
|
+
"type": "text",
|
|
562
|
+
"name": "annotation",
|
|
563
|
+
"label": "Message annotation"
|
|
564
|
+
},
|
|
555
565
|
{
|
|
556
566
|
"type": "textarea",
|
|
557
567
|
"name": "systemAfter",
|
package/src/Tester.js
CHANGED