@tiledesk/tiledesk-tybot-connector 0.2.91 → 0.2.93-rc1
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/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,13 @@
|
|
|
5
5
|
available on:
|
|
6
6
|
▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
|
|
7
7
|
|
|
8
|
+
|
|
9
|
+
# v0.2.93-rc1
|
|
10
|
+
- Set specific system_context for each AI smodels
|
|
11
|
+
|
|
12
|
+
# v0.2.92
|
|
13
|
+
- Improves GPTTask action: added support for history
|
|
14
|
+
|
|
8
15
|
# v0.2.91
|
|
9
16
|
- Added voice flow attributes: dnis, callId, ani
|
|
10
17
|
|
|
@@ -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
|
@@ -62,7 +62,15 @@ class DirAskGPTV2 {
|
|
|
62
62
|
let temperature;
|
|
63
63
|
let max_tokens;
|
|
64
64
|
let top_k;
|
|
65
|
-
let default_context = "You are an helpful assistant for question-answering tasks.\nUse ONLY the following pieces of retrieved context to answer the question.\nIf you don't know the answer, just say that you don't know.\nIf none of the retrieved context answer the question, add this word to the end <NOANS>\n\n{context}";
|
|
65
|
+
//let default_context = "You are an helpful assistant for question-answering tasks.\nUse ONLY the following pieces of retrieved context to answer the question.\nIf you don't know the answer, just say that you don't know.\nIf none of the retrieved context answer the question, add this word to the end <NOANS>\n\n{context}";
|
|
66
|
+
|
|
67
|
+
let contexts = {
|
|
68
|
+
"gpt-3.5-turbo": "You are an helpful assistant for question-answering tasks.\nUse ONLY the pieces of retrieved context delimited by #### to answer the question.\nIf you don't know the answer, just say that you don't know.\nIf and only if none of the retrieved context is useful for your task, add this word to the end <NOANS>\n\n####{context}####",
|
|
69
|
+
"gpt-4": "You are an helpful assistant for question-answering tasks.\nUse ONLY the pieces of retrieved context delimited by #### to answer the question.\nIf you don't know the answer, just say that you don't know.\nIf and only if none of the retrieved context is useful for your task, add this word to the end <NOANS>\n\n####{context}####",
|
|
70
|
+
"gpt-4-turbo-preview": "You are an helpful assistant for question-answering tasks.\nUse ONLY the pieces of retrieved context delimited by #### to answer the question.\nIf you don't know the answer, just say that you don't know.\nIf the context does not contain sufficient information to generate an accurate and informative answer, return <NOANS>\n\n####{context}####",
|
|
71
|
+
"gpt-4o": "You are an helpful assistant for question-answering tasks.\nUse ONLY the pieces of retrieved context delimited by #### to answer the question.\nIf you don't know the answer, just say that you don't know.\nIf the context does not contain sufficient information to generate an accurate and informative answer, return <NOANS>\n\n####{context}####",
|
|
72
|
+
"gpt-4o-mini": "You are an helpful assistant for question-answering tasks.\nUse ONLY the pieces of retrieved context delimited by #### to answer the question.\nIf you don't know the answer, just say that you don't know.\nIf the context does not contain sufficient information to generate an accurate and informative answer, return <NOANS>\n\n####{context}####"
|
|
73
|
+
}
|
|
66
74
|
|
|
67
75
|
let source = null;
|
|
68
76
|
|
|
@@ -165,9 +173,9 @@ class DirAskGPTV2 {
|
|
|
165
173
|
|
|
166
174
|
if (!action.advancedPrompt) {
|
|
167
175
|
if (filled_context) {
|
|
168
|
-
json.system_context = filled_context + "\n" +
|
|
176
|
+
json.system_context = filled_context + "\n" + contexts[model];
|
|
169
177
|
} else {
|
|
170
|
-
json.system_context =
|
|
178
|
+
json.system_context = contexts[model];
|
|
171
179
|
}
|
|
172
180
|
} else {
|
|
173
181
|
json.system_context = filled_context;
|
|
@@ -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;
|