@tiledesk/tiledesk-tybot-connector 0.2.91 → 0.2.92
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.
|
@@ -435,15 +435,14 @@ class TiledeskChatbotUtil {
|
|
|
435
435
|
let fullName = message.senderFullname;
|
|
436
436
|
if (fullName.trim() === chatbot_name) {
|
|
437
437
|
fullName = "bot:" + fullName;
|
|
438
|
-
}
|
|
439
|
-
else {
|
|
438
|
+
} else {
|
|
440
439
|
fullName = "user:" + fullName;
|
|
441
440
|
}
|
|
442
441
|
return "<" + fullName + ">";
|
|
443
442
|
}
|
|
444
443
|
}
|
|
445
444
|
|
|
446
|
-
static transcriptJSON(transcript) {
|
|
445
|
+
static async transcriptJSON(transcript) {
|
|
447
446
|
const regexp = /(<.*>)/gm;
|
|
448
447
|
const parts = transcript.split(regexp);
|
|
449
448
|
// console.log("parts:", parts);
|
package/package.json
CHANGED
|
@@ -3,6 +3,8 @@ const { TiledeskChatbot } = require("../../models/TiledeskChatbot");
|
|
|
3
3
|
const { Filler } = require("../Filler");
|
|
4
4
|
let https = require("https");
|
|
5
5
|
const { DirIntent } = require("./DirIntent");
|
|
6
|
+
const { TiledeskChatbotConst } = require("../../models/TiledeskChatbotConst");
|
|
7
|
+
const { TiledeskChatbotUtil } = require("../../models/TiledeskChatbotUtil");
|
|
6
8
|
require('dotenv').config();
|
|
7
9
|
|
|
8
10
|
class DirGptTask {
|
|
@@ -12,6 +14,7 @@ class DirGptTask {
|
|
|
12
14
|
throw new Error('context object is mandatory');
|
|
13
15
|
}
|
|
14
16
|
this.context = context;
|
|
17
|
+
this.chatbot = this.context.chatbot;
|
|
15
18
|
this.tdcache = this.context.tdcache;
|
|
16
19
|
this.requestId = this.context.requestId;
|
|
17
20
|
this.intentDir = new DirIntent(context);
|
|
@@ -47,6 +50,7 @@ class DirGptTask {
|
|
|
47
50
|
let falseIntent = action.falseIntent;
|
|
48
51
|
let trueIntentAttributes = action.trueIntentAttributes;
|
|
49
52
|
let falseIntentAttributes = action.falseIntentAttributes;
|
|
53
|
+
let transcript;
|
|
50
54
|
|
|
51
55
|
if (this.log) {
|
|
52
56
|
console.log("DirGptTask trueIntent", trueIntent)
|
|
@@ -62,6 +66,7 @@ class DirGptTask {
|
|
|
62
66
|
if (!action.question || action.question === '') {
|
|
63
67
|
console.error("Error: DirGptTask question attribute is mandatory. Executing condition false...")
|
|
64
68
|
if (falseIntent) {
|
|
69
|
+
await this.chatbot.addParameter("flowError", "GPT Error: question attribute is undefined");
|
|
65
70
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
66
71
|
callback(true);
|
|
67
72
|
return;
|
|
@@ -92,6 +97,18 @@ class DirGptTask {
|
|
|
92
97
|
console.log("DirGptTask temperature: ", temperature);
|
|
93
98
|
}
|
|
94
99
|
|
|
100
|
+
if (action.history) {
|
|
101
|
+
let transcript_string = await TiledeskChatbot.getParameterStatic(
|
|
102
|
+
this.context.tdcache,
|
|
103
|
+
this.context.requestId,
|
|
104
|
+
TiledeskChatbotConst.REQ_TRANSCRIPT_KEY);
|
|
105
|
+
if (this.log) { console.log("DirGptTask transcript string: ", transcript_string) }
|
|
106
|
+
|
|
107
|
+
transcript = await TiledeskChatbotUtil.transcriptJSON(transcript_string);
|
|
108
|
+
if (this.log) { console.log("DirGptTask transcript: ", transcript) }
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
95
112
|
const server_base_url = process.env.API_ENDPOINT || process.env.API_URL;
|
|
96
113
|
const openai_url = process.env.OPENAI_ENDPOINT + "/chat/completions";
|
|
97
114
|
if (this.log) {
|
|
@@ -115,6 +132,7 @@ class DirGptTask {
|
|
|
115
132
|
console.error("DirGptTask gptkey is mandatory");
|
|
116
133
|
await this.#assignAttributes(action, answer);
|
|
117
134
|
if (falseIntent) {
|
|
135
|
+
await this.chatbot.addParameter("flowError", "GPT Error: gpt apikey is undefined");
|
|
118
136
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
119
137
|
callback(true);
|
|
120
138
|
return;
|
|
@@ -134,22 +152,34 @@ class DirGptTask {
|
|
|
134
152
|
|
|
135
153
|
let json = {
|
|
136
154
|
model: action.model,
|
|
137
|
-
messages: [
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
155
|
+
messages: [],
|
|
156
|
+
// messages: [
|
|
157
|
+
// {
|
|
158
|
+
// role: "user",
|
|
159
|
+
// content: filled_question
|
|
160
|
+
// }
|
|
161
|
+
// ],
|
|
143
162
|
max_tokens: action.max_tokens,
|
|
144
|
-
temperature: action.temperature
|
|
163
|
+
temperature: action.temperature,
|
|
145
164
|
}
|
|
146
165
|
|
|
147
|
-
let message = { role: "", content: "" };
|
|
148
166
|
if (action.context) {
|
|
149
|
-
message
|
|
150
|
-
message
|
|
151
|
-
json.messages.unshift(message);
|
|
167
|
+
let message = { role: "system", content: filled_context }
|
|
168
|
+
json.messages.push(message);
|
|
152
169
|
}
|
|
170
|
+
|
|
171
|
+
if (transcript) {
|
|
172
|
+
transcript.forEach(msg => {
|
|
173
|
+
if (!msg.content.startsWith('/')) {
|
|
174
|
+
let message = { role: msg.role, content: msg.content }
|
|
175
|
+
json.messages.push(message)
|
|
176
|
+
}
|
|
177
|
+
})
|
|
178
|
+
} else {
|
|
179
|
+
let message = { role: "user", content: filled_question };
|
|
180
|
+
json.messages.push(message);
|
|
181
|
+
}
|
|
182
|
+
|
|
153
183
|
if (this.log) { console.log("DirGptTask json: ", json) }
|
|
154
184
|
|
|
155
185
|
const HTTPREQUEST = {
|
|
@@ -167,10 +197,11 @@ class DirGptTask {
|
|
|
167
197
|
if (err) {
|
|
168
198
|
if (this.log) {
|
|
169
199
|
console.error("(httprequest) DirGptTask openai err:", err);
|
|
170
|
-
console.error("(httprequest) DirGptTask openai err:", err.response
|
|
200
|
+
console.error("(httprequest) DirGptTask openai err:", err.response?.data?.error?.message);
|
|
171
201
|
}
|
|
172
202
|
await this.#assignAttributes(action, answer);
|
|
173
203
|
if (falseIntent) {
|
|
204
|
+
await this.chatbot.addParameter("flowError", "GPT Error: " + err.response?.data?.error?.message);
|
|
174
205
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
175
206
|
callback(true);
|
|
176
207
|
return;
|