wingbot 3.57.1 → 3.58.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.57.1",
3
+ "version": "3.58.1",
4
4
  "description": "Enterprise Messaging Bot Conversation Engine",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -6,7 +6,13 @@
6
6
  const fetch = require('node-fetch').default;
7
7
  const compileWithState = require('../../src/utils/compileWithState');
8
8
 
9
- function chatgptPlugin (params) {
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 response = await useFetch('https://api.openai.com/v1/chat/completions', {
72
+ const apiUrl = openAiEndpoint
73
+ ? `${openAiEndpoint}/chat/completions?api-version=2023-03-15-preview`
74
+ : 'https://api.openai.com/v1/chat/completions';
75
+
76
+ const response = await useFetch(`${apiUrl}/chat/completions`, {
62
77
  method: 'POST',
63
78
  headers: {
64
79
  'Content-Type': 'application/json',
65
- Authorization: `Bearer ${token}`
80
+ ...(openAiEndpoint
81
+ ? { 'api-key': token || openAiApiKey }
82
+ : { Authorization: `Bearer ${token || openAiApiKey}` })
66
83
  },
67
84
  body: JSON.stringify(body)
68
85
  });
@@ -73,7 +90,9 @@ function chatgptPlugin (params) {
73
90
  || !Array.isArray(data.choices)) {
74
91
  const { status, statusText } = response;
75
92
  // eslint-disable-next-line no-console
76
- console.log('chat gpt error', { status, statusText, data });
93
+ console.log('chat gpt error', {
94
+ status, statusText, data, apiUrl
95
+ });
77
96
  throw new Error(`Chat GPT ${status}`);
78
97
  }
79
98
 
@@ -92,8 +111,26 @@ function chatgptPlugin (params) {
92
111
  filtered = filtered.slice(0, filtered.length - 1);
93
112
  }
94
113
 
114
+ if (persona) {
115
+ res.setPersona({ name: persona });
116
+ }
117
+
95
118
  filtered
96
- .forEach((t) => res.text(t.trim()));
119
+ .forEach((t) => {
120
+ let trim = t.trim();
121
+
122
+ if (annotation && annotation.includes(MSG_REPLACE)) {
123
+ trim = annotation.replace(MSG_REPLACE, trim);
124
+ } else if (annotation) {
125
+ trim = `${annotation} ${trim}`;
126
+ }
127
+
128
+ res.text(trim);
129
+ });
130
+
131
+ if (persona) {
132
+ res.setPersona({ name: null });
133
+ }
97
134
 
98
135
  return ch;
99
136
  });
@@ -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
@@ -378,7 +378,7 @@ class Tester {
378
378
  * Assert, that state contains a subset of provided value
379
379
  *
380
380
  * @param {object} object
381
- * @param {boolean} deep
381
+ * @param {boolean} [deep]
382
382
  * @example
383
383
  *
384
384
  * t.stateContains({ value: true });
@@ -24,7 +24,7 @@ class ResponseAssert {
24
24
  /**
25
25
  * Checks, that response contains text
26
26
  *
27
- * @param {string} search
27
+ * @param {string|object} search
28
28
  * @returns {this}
29
29
  *
30
30
  * @memberOf ResponseAssert