wingbot 3.70.5 → 3.70.7
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/src/ChatGpt.js +16 -2
- package/src/LLM.js +32 -0
- package/src/LLMSession.js +16 -3
- package/src/ReturnSender.js +22 -3
- package/src/graphApi/schema.gql +20 -0
package/package.json
CHANGED
package/src/ChatGpt.js
CHANGED
|
@@ -65,6 +65,7 @@ const LLM = require('./LLM');
|
|
|
65
65
|
* @prop {'stop'|'length'|'tool_calls'|'content_filter'|null} finish_reason
|
|
66
66
|
* @prop {number} index
|
|
67
67
|
* @prop {Message} message
|
|
68
|
+
* @prop {GptToolCall[]} [tool_calls]
|
|
68
69
|
*/
|
|
69
70
|
|
|
70
71
|
/**
|
|
@@ -89,6 +90,15 @@ const LLM = require('./LLM');
|
|
|
89
90
|
* @prop {Function} error
|
|
90
91
|
*/
|
|
91
92
|
|
|
93
|
+
/**
|
|
94
|
+
* @typedef {object} GptToolCall
|
|
95
|
+
* @prop {string} id
|
|
96
|
+
* @prop {'function'|string} type
|
|
97
|
+
* @prop {object} function
|
|
98
|
+
* @prop {string} function.name
|
|
99
|
+
* @prop {string} function.arguments - JSON string
|
|
100
|
+
*/
|
|
101
|
+
|
|
92
102
|
/**
|
|
93
103
|
* @typedef {object} SlicedAnnotation
|
|
94
104
|
* @prop {boolean} [sliced]
|
|
@@ -246,13 +256,17 @@ class ChatGpt {
|
|
|
246
256
|
* @returns {Promise<LLMMessage>}
|
|
247
257
|
*/
|
|
248
258
|
async requestChat (prompt, options) {
|
|
249
|
-
|
|
250
259
|
const choice = await this._request(prompt, options);
|
|
251
260
|
|
|
252
|
-
const { finish_reason: finishReason, message } = choice;
|
|
261
|
+
const { finish_reason: finishReason, message, tool_calls: toolCalls = [] } = choice;
|
|
253
262
|
|
|
254
263
|
return {
|
|
255
264
|
finishReason,
|
|
265
|
+
toolCalls: toolCalls.map(({ id, function: { name, arguments: args } }) => ({
|
|
266
|
+
id,
|
|
267
|
+
name,
|
|
268
|
+
args
|
|
269
|
+
})),
|
|
256
270
|
...message
|
|
257
271
|
};
|
|
258
272
|
}
|
package/src/LLM.js
CHANGED
|
@@ -9,6 +9,7 @@ const { PHONE_REGEX, EMAIL_REGEX } = require('./systemEntities/regexps');
|
|
|
9
9
|
/** @typedef {import('./Responder').Persona} Persona */
|
|
10
10
|
/** @typedef {import('./Router').BaseConfiguration} BaseConfiguration */
|
|
11
11
|
/** @typedef {import('./LLMSession').LLMMessage<any>} LLMMessage */
|
|
12
|
+
/** @typedef {import('./LLMSession').ToolCall} ToolCall */
|
|
12
13
|
/** @typedef {import('./LLMSession').LLMRole} LLMRole */
|
|
13
14
|
/** @typedef {import('./LLMSession')} LLMSession */
|
|
14
15
|
/** @typedef {import('./transcript/transcriptFromHistory').Transcript} Transcript */
|
|
@@ -40,6 +41,7 @@ const { PHONE_REGEX, EMAIL_REGEX } = require('./systemEntities/regexps');
|
|
|
40
41
|
* @prop {'gpt'|string} [transcriptFlag]
|
|
41
42
|
* @prop {boolean} [transcriptAnonymize]
|
|
42
43
|
* @prop {Persona|string|null} [persona]
|
|
44
|
+
* @prop {LLMLogger} [logger]
|
|
43
45
|
*/
|
|
44
46
|
|
|
45
47
|
/**
|
|
@@ -48,6 +50,22 @@ const { PHONE_REGEX, EMAIL_REGEX } = require('./systemEntities/regexps');
|
|
|
48
50
|
* @prop {RegExp} regex
|
|
49
51
|
*/
|
|
50
52
|
|
|
53
|
+
/**
|
|
54
|
+
* @typedef {object} PromptInfo
|
|
55
|
+
* @prop {LLMMessage[]} prompt
|
|
56
|
+
* @prop {LLMMessage} result
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @callback LogPrompt
|
|
61
|
+
* @param {PromptInfo} info
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @typedef {object} LLMLogger
|
|
66
|
+
* @prop {LogPrompt} logPrompt
|
|
67
|
+
*/
|
|
68
|
+
|
|
51
69
|
/**
|
|
52
70
|
* @class LLM
|
|
53
71
|
*/
|
|
@@ -81,6 +99,9 @@ class LLM {
|
|
|
81
99
|
transcriptFlag: 'gpt',
|
|
82
100
|
transcriptLength: 5,
|
|
83
101
|
provider: null,
|
|
102
|
+
logger: {
|
|
103
|
+
logPrompt: () => {}
|
|
104
|
+
},
|
|
84
105
|
...rest
|
|
85
106
|
};
|
|
86
107
|
|
|
@@ -133,6 +154,17 @@ class LLM {
|
|
|
133
154
|
return result;
|
|
134
155
|
}
|
|
135
156
|
|
|
157
|
+
/**
|
|
158
|
+
*
|
|
159
|
+
* @param {LLMMessage[]} prompt
|
|
160
|
+
* @param {LLMMessage} result
|
|
161
|
+
*/
|
|
162
|
+
_logPrompt (prompt, result) {
|
|
163
|
+
this._configuration.logger.logPrompt({
|
|
164
|
+
prompt, result
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
136
168
|
/**
|
|
137
169
|
*
|
|
138
170
|
* @param {LLMMessage} result
|
package/src/LLMSession.js
CHANGED
|
@@ -6,19 +6,30 @@
|
|
|
6
6
|
const LLM = require('./LLM');
|
|
7
7
|
|
|
8
8
|
/** @typedef {import('./Responder').QuickReply} QuickReply */
|
|
9
|
+
/** @typedef {import('./LLM').LLMProviderOptions} LLMProviderOptions */
|
|
10
|
+
|
|
9
11
|
/** @typedef {'user'|'assistant'} LLMChatRole */
|
|
10
12
|
/** @typedef {'system'} LLMSystemRole */
|
|
11
|
-
/** @typedef {
|
|
12
|
-
/** @typedef {
|
|
13
|
+
/** @typedef {'tool'} LLMToolRole */
|
|
14
|
+
/** @typedef {LLMChatRole|LLMSystemRole|LLMToolRole|string} LLMRole */
|
|
13
15
|
|
|
14
16
|
/** @typedef {'stop'|'length'|'tool_calls'|'content_filter'} LLMFinishReason */
|
|
15
17
|
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {object} ToolCall
|
|
20
|
+
* @prop {string} id
|
|
21
|
+
* @prop {string} name
|
|
22
|
+
* @prop {string} args - JSON string
|
|
23
|
+
*/
|
|
24
|
+
|
|
16
25
|
/**
|
|
17
26
|
* @template {LLMRole} [R=LLMRole]
|
|
18
27
|
* @typedef {object} LLMMessage
|
|
19
28
|
* @prop {R} role
|
|
20
29
|
* @prop {string} content
|
|
30
|
+
* @prop {string} [toolCallId]
|
|
21
31
|
* @prop {LLMFinishReason} [finishReason]
|
|
32
|
+
* @prop {ToolCall[]} [toolCalls]
|
|
22
33
|
*/
|
|
23
34
|
|
|
24
35
|
/**
|
|
@@ -80,11 +91,13 @@ class LLMSession {
|
|
|
80
91
|
|
|
81
92
|
const promptRegex = /\$\{prompt\(\)\}/g;
|
|
82
93
|
|
|
94
|
+
const last = sysMessages.length - 1;
|
|
95
|
+
|
|
83
96
|
const content = sysMessages.reduce((reduced, current, i) => {
|
|
84
97
|
if (i === 0) {
|
|
85
98
|
return current.content || '';
|
|
86
99
|
}
|
|
87
|
-
if (!reduced.match(promptRegex)) {
|
|
100
|
+
if (last === i && !reduced.match(promptRegex)) {
|
|
88
101
|
return `${reduced}\n\n${current.content}`;
|
|
89
102
|
}
|
|
90
103
|
return reduced.replace(promptRegex, current.content).trim();
|
package/src/ReturnSender.js
CHANGED
|
@@ -11,7 +11,9 @@ const extractText = require('./transcript/extractText');
|
|
|
11
11
|
/** @typedef {import('./Request')} Request */
|
|
12
12
|
/** @typedef {import('./Responder')} Responder */
|
|
13
13
|
/** @typedef {import('./Processor').TrackingObject} TrackingObject */
|
|
14
|
-
/** @typedef {import('./
|
|
14
|
+
/** @typedef {import('./LLMSession').LLMMessage} LLMMessage */
|
|
15
|
+
/** @typedef {import('./LLM').LLMLogger} LLMLogger */
|
|
16
|
+
/** @typedef {import('./LLM').PromptInfo} PromptInfo */
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
19
|
* @callback GetInteractions
|
|
@@ -68,6 +70,10 @@ const extractText = require('./transcript/extractText');
|
|
|
68
70
|
* @returns {string} - filtered text
|
|
69
71
|
*/
|
|
70
72
|
|
|
73
|
+
/**
|
|
74
|
+
* @class ReturnSender
|
|
75
|
+
* @implements {LLMLogger}
|
|
76
|
+
*/
|
|
71
77
|
class ReturnSender {
|
|
72
78
|
|
|
73
79
|
/**
|
|
@@ -155,6 +161,9 @@ class ReturnSender {
|
|
|
155
161
|
events: []
|
|
156
162
|
};
|
|
157
163
|
|
|
164
|
+
/** @type {PromptInfo[]} */
|
|
165
|
+
this._prompts = [];
|
|
166
|
+
|
|
158
167
|
this._responseTexts = [];
|
|
159
168
|
|
|
160
169
|
this._intentsAndEntities = [];
|
|
@@ -185,6 +194,14 @@ class ReturnSender {
|
|
|
185
194
|
}
|
|
186
195
|
}
|
|
187
196
|
|
|
197
|
+
/**
|
|
198
|
+
*
|
|
199
|
+
* @param {PromptInfo} promptInfo
|
|
200
|
+
*/
|
|
201
|
+
logPrompt (promptInfo) {
|
|
202
|
+
this._prompts.push(promptInfo);
|
|
203
|
+
}
|
|
204
|
+
|
|
188
205
|
/**
|
|
189
206
|
*
|
|
190
207
|
* @param {DeferOperation|Promise} operation
|
|
@@ -651,7 +668,8 @@ class ReturnSender {
|
|
|
651
668
|
_createTracking (req = null, res = null) {
|
|
652
669
|
const payload = {};
|
|
653
670
|
const meta = {
|
|
654
|
-
actions: this._visitedInteractions.slice()
|
|
671
|
+
actions: this._visitedInteractions.slice(),
|
|
672
|
+
prompts: this._prompts
|
|
655
673
|
};
|
|
656
674
|
|
|
657
675
|
if (req) {
|
|
@@ -678,7 +696,8 @@ class ReturnSender {
|
|
|
678
696
|
*/
|
|
679
697
|
_createMeta (req = null, res = null) { // eslint-disable-line no-unused-vars
|
|
680
698
|
const meta = {
|
|
681
|
-
visitedInteractions: this._visitedInteractions.slice()
|
|
699
|
+
visitedInteractions: this._visitedInteractions.slice(),
|
|
700
|
+
prompts: this._prompts
|
|
682
701
|
};
|
|
683
702
|
|
|
684
703
|
if (req) {
|
package/src/graphApi/schema.gql
CHANGED
|
@@ -95,6 +95,25 @@ type AiAction {
|
|
|
95
95
|
winner: Boolean!
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
+
type ToolCall {
|
|
99
|
+
id: String
|
|
100
|
+
name: String
|
|
101
|
+
args: String
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
type LLMMessage {
|
|
105
|
+
role: String!
|
|
106
|
+
content: String
|
|
107
|
+
finishReason: String
|
|
108
|
+
toolCallId: String
|
|
109
|
+
toolCalls: [ToolCall!]
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
type PromptInfo {
|
|
113
|
+
prompt: [LLMMessage!]!
|
|
114
|
+
result: LLMMessage!
|
|
115
|
+
}
|
|
116
|
+
|
|
98
117
|
type UserInteraction {
|
|
99
118
|
senderId: String!
|
|
100
119
|
pageId: String!
|
|
@@ -117,6 +136,7 @@ type UserInteraction {
|
|
|
117
136
|
request: Any!
|
|
118
137
|
responses: [Any]!
|
|
119
138
|
visitedInteractions: [String]
|
|
139
|
+
prompts: [PromptInfo!]
|
|
120
140
|
|
|
121
141
|
err: String
|
|
122
142
|
}
|