wingbot 3.64.0 → 3.65.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.64.0",
3
+ "version": "3.65.0",
4
4
  "description": "Enterprise Messaging Bot Conversation Engine",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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,11 @@ 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) => `${c.lang}`.trim().toLowerCase() === 'default');
54
+
46
55
  let body;
47
56
 
48
57
  try {
@@ -62,6 +71,18 @@ function chatgptPlugin (params, configuration = {}) {
62
71
 
63
72
  const ts = await res.getTranscript(Math.abs(limit), onlyFlag);
64
73
 
74
+ let total = (system ? system.length : 0)
75
+ + (systemAfter ? systemAfter.length : 0)
76
+ + maxTokens
77
+ + content.length;
78
+
79
+ for (let i = ts.length - 1; i >= 0; i--) {
80
+ total += ts[i].text.length;
81
+ if (total > charLim) {
82
+ ts.splice(i, 1);
83
+ }
84
+ }
85
+
65
86
  const messages = [
66
87
  ...(system ? [{ role: 'system', content: system }] : []),
67
88
  ...ts.map((t) => ({ role: t.fromBot ? 'assistant' : 'user', content: t.text })),
@@ -106,6 +127,9 @@ function chatgptPlugin (params, configuration = {}) {
106
127
  const sent = data.choices
107
128
  .filter((ch) => ch.message && ch.message.role === 'assistant' && ch.message.content)
108
129
  .map((ch) => {
130
+
131
+ let sliced = false;
132
+
109
133
  let filtered = ch.message.content
110
134
  .replace(/\n\n/g, '\n')
111
135
  .split(/\n+(?!-)/g)
@@ -113,6 +137,7 @@ function chatgptPlugin (params, configuration = {}) {
113
137
 
114
138
  if (filtered.length > 2) {
115
139
  filtered = filtered.slice(0, filtered.length - 1);
140
+ sliced = true;
116
141
  }
117
142
 
118
143
  if (persona) {
@@ -120,7 +145,7 @@ function chatgptPlugin (params, configuration = {}) {
120
145
  }
121
146
 
122
147
  filtered
123
- .forEach((t) => {
148
+ .forEach((t, fi) => {
124
149
  let trim = t.trim();
125
150
 
126
151
  if (annotation) {
@@ -151,7 +176,14 @@ function chatgptPlugin (params, configuration = {}) {
151
176
  trim = `${annotation} ${trim}`;
152
177
  }
153
178
 
154
- res.text(trim);
179
+ res.text(trim, sliced && fi === (filtered.length - 1) && continueReply
180
+ ? [
181
+ {
182
+ title: continueReply.title,
183
+ action: res.currentAction()
184
+ }
185
+ ]
186
+ : null);
155
187
  });
156
188
 
157
189
  if (persona) {
@@ -578,6 +578,34 @@
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": "lang",
590
+ "label": "Language"
591
+ },
592
+ {
593
+ "name": "title",
594
+ "label": "Quick Reply"
595
+ }
596
+ ],
597
+ "inputs": [
598
+ {
599
+ "type": "text",
600
+ "name": "lang",
601
+ "label": "Language (or 'default')"
602
+ },
603
+ {
604
+ "type": "text",
605
+ "name": "title",
606
+ "label": "Quick reply title"
607
+ }
608
+ ]
581
609
  }
582
610
  ],
583
611
  "items": [
@@ -278,7 +278,10 @@ type Query {
278
278
 
279
279
  type Mutation {
280
280
  "validate conversation data"
281
- validateBot(bot:Any!): ValidationResult
281
+ validateBot(
282
+ bot:Any!,
283
+ compressed: Boolean = false
284
+ ): ValidationResult
282
285
 
283
286
  "invalidate a conversation cache in the chatbot"
284
287
  updateBot: Boolean
@@ -3,6 +3,7 @@
3
3
  */
4
4
  'use strict';
5
5
 
6
+ const { decompress } = require('compress-json');
6
7
  const Tester = require('../Tester');
7
8
  const apiAuthorizer = require('./apiAuthorizer');
8
9
 
@@ -95,7 +96,11 @@ function validateBotApi (botFactory, postBackTest = null, textTest = null, acl =
95
96
  return null;
96
97
  }
97
98
 
98
- const validationRequestBody = args.bot;
99
+ let validationRequestBody = args.bot;
100
+
101
+ if (args.compressed) {
102
+ validationRequestBody = decompress(validationRequestBody);
103
+ }
99
104
 
100
105
  const bot = botFactory();
101
106