@tiledesk/tiledesk-tybot-connector 2.0.47 → 2.0.48
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/logs/app.log +1954 -0
- package/package.json +1 -1
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +47 -73
package/package.json
CHANGED
|
@@ -96,44 +96,26 @@ class DirAskGPTV2 {
|
|
|
96
96
|
callback();
|
|
97
97
|
return;
|
|
98
98
|
}
|
|
99
|
-
|
|
99
|
+
|
|
100
100
|
let trueIntent = action.trueIntent;
|
|
101
101
|
let falseIntent = action.falseIntent;
|
|
102
102
|
let trueIntentAttributes = action.trueIntentAttributes;
|
|
103
103
|
let falseIntentAttributes = action.falseIntentAttributes;
|
|
104
|
-
|
|
104
|
+
|
|
105
105
|
winston.debug("DirAskGPTV2 trueIntent", trueIntent)
|
|
106
106
|
winston.debug("DirAskGPTV2 falseIntent", falseIntent)
|
|
107
107
|
winston.debug("DirAskGPTV2 trueIntentAttributes", trueIntentAttributes)
|
|
108
108
|
winston.debug("DirAskGPTV2 falseIntentAttributes", falseIntentAttributes)
|
|
109
|
-
|
|
109
|
+
|
|
110
110
|
// default values
|
|
111
111
|
let answer = "No answers";
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
let temperature = 0.7;
|
|
116
|
-
let max_tokens = 256;
|
|
117
|
-
let top_k = 4;
|
|
118
|
-
let alpha;
|
|
119
|
-
let transcript;
|
|
120
|
-
let citations = false;
|
|
121
|
-
let chunks_only = false;
|
|
122
|
-
let engine;
|
|
123
|
-
let embedding;
|
|
124
|
-
let reranking;
|
|
125
|
-
let reranking_multiplier;
|
|
126
|
-
let skip_unanswered = false;
|
|
127
|
-
let source = null;
|
|
128
|
-
|
|
129
|
-
if (!action.llm) {
|
|
130
|
-
action.llm = "openai";
|
|
131
|
-
}
|
|
132
|
-
|
|
112
|
+
action.llm ??= "openai";
|
|
113
|
+
action.model ??= "gpt-4o";
|
|
114
|
+
|
|
133
115
|
await this.checkMandatoryParameters(action).catch( async (missing_param) => {
|
|
134
116
|
this.logger.error(`[Ask Knowledge Base] missing attribute '${missing_param}'`);
|
|
135
117
|
await this.chatbot.addParameter("flowError", `AskKnowledgeBase Error: '${missing_param}' attribute is undefined`);
|
|
136
|
-
await this.#assignAttributes(action, answer
|
|
118
|
+
await this.#assignAttributes(action, answer);
|
|
137
119
|
if (falseIntent) {
|
|
138
120
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
139
121
|
callback(true);
|
|
@@ -143,52 +125,35 @@ class DirAskGPTV2 {
|
|
|
143
125
|
return Promise.reject();
|
|
144
126
|
})
|
|
145
127
|
|
|
146
|
-
|
|
147
|
-
namespace =
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
max_tokens = action.max_tokens;
|
|
163
|
-
}
|
|
164
|
-
if (action.alpha) {
|
|
165
|
-
alpha = action.alpha;
|
|
166
|
-
}
|
|
167
|
-
if (action.citations) {
|
|
168
|
-
citations = action.citations;
|
|
169
|
-
}
|
|
170
|
-
if (action.chunks_only) {
|
|
171
|
-
chunks_only = action.chunks_only;
|
|
172
|
-
}
|
|
173
|
-
if (action.reranking) {
|
|
174
|
-
reranking = action.reranking;
|
|
175
|
-
}
|
|
176
|
-
if (action.reranking_multiplier) {
|
|
177
|
-
reranking_multiplier = action.reranking_multiplier;
|
|
178
|
-
}
|
|
179
|
-
if (action.skip_unanswered) {
|
|
180
|
-
skip_unanswered = action.skip_unanswered;
|
|
181
|
-
}
|
|
128
|
+
let {
|
|
129
|
+
namespace = this.context.projectId,
|
|
130
|
+
llm,
|
|
131
|
+
model,
|
|
132
|
+
temperature = 0.7,
|
|
133
|
+
max_tokens = 2048,
|
|
134
|
+
top_k = 4,
|
|
135
|
+
alpha = 0.5,
|
|
136
|
+
citations = false,
|
|
137
|
+
chunks_only = false,
|
|
138
|
+
reranking = false,
|
|
139
|
+
reranking_multiplier = 3,
|
|
140
|
+
skip_unanswered = false,
|
|
141
|
+
use_hyde = false,
|
|
142
|
+
use_cache = false,
|
|
143
|
+
} = action;
|
|
182
144
|
|
|
145
|
+
let transcript;
|
|
146
|
+
|
|
183
147
|
let requestVariables = null;
|
|
184
148
|
requestVariables =
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
149
|
+
await TiledeskChatbot.allParametersStatic(
|
|
150
|
+
this.tdcache, this.requestId
|
|
151
|
+
);
|
|
152
|
+
|
|
189
153
|
const filler = new Filler();
|
|
190
154
|
const filled_question = filler.fill(action.question, requestVariables);
|
|
191
155
|
const filled_context = filler.fill(action.context, requestVariables)
|
|
156
|
+
|
|
192
157
|
|
|
193
158
|
if (action.history) {
|
|
194
159
|
this.logger.native("[Ask Knowledge Base] use chat transcript")
|
|
@@ -207,9 +172,10 @@ class DirAskGPTV2 {
|
|
|
207
172
|
winston.verbose("DirAskGPT transcript_string is undefined. Skip JSON translation for chat history")
|
|
208
173
|
}
|
|
209
174
|
}
|
|
210
|
-
|
|
211
|
-
let key;
|
|
175
|
+
|
|
212
176
|
let publicKey = false;
|
|
177
|
+
let embedding;
|
|
178
|
+
let engine;
|
|
213
179
|
|
|
214
180
|
try {
|
|
215
181
|
model = await aiController.resolveLLMConfig(this.projectId, llm, model, this.token);
|
|
@@ -281,7 +247,7 @@ class DirAskGPTV2 {
|
|
|
281
247
|
}
|
|
282
248
|
|
|
283
249
|
let ns;
|
|
284
|
-
|
|
250
|
+
|
|
285
251
|
if (action.namespaceAsName) {
|
|
286
252
|
// Namespace could be an attribute
|
|
287
253
|
const filled_namespace = filler.fill(action.namespace, requestVariables)
|
|
@@ -306,7 +272,7 @@ class DirAskGPTV2 {
|
|
|
306
272
|
callback();
|
|
307
273
|
return;
|
|
308
274
|
}
|
|
309
|
-
|
|
275
|
+
|
|
310
276
|
if (ns.engine) {
|
|
311
277
|
engine = ns.engine;
|
|
312
278
|
} else {
|
|
@@ -338,7 +304,7 @@ class DirAskGPTV2 {
|
|
|
338
304
|
if (chunks_only) {
|
|
339
305
|
json.chunks_only = chunks_only;
|
|
340
306
|
}
|
|
341
|
-
|
|
307
|
+
|
|
342
308
|
if (ns.hybrid === true) {
|
|
343
309
|
json.search_type = 'hybrid';
|
|
344
310
|
json.alpha = alpha;
|
|
@@ -399,6 +365,14 @@ class DirAskGPTV2 {
|
|
|
399
365
|
json.tags = action.tags;
|
|
400
366
|
}
|
|
401
367
|
|
|
368
|
+
if (use_hyde) {
|
|
369
|
+
json.use_hyde = use_hyde;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
if (use_cache) {
|
|
373
|
+
json.use_cache = use_cache;
|
|
374
|
+
}
|
|
375
|
+
|
|
402
376
|
winston.debug("DirAskGPTV2 json:", json);
|
|
403
377
|
|
|
404
378
|
let kb_endpoint = process.env.KB_ENDPOINT_QA;
|
|
@@ -427,7 +401,7 @@ class DirAskGPTV2 {
|
|
|
427
401
|
data: err.response?.data,
|
|
428
402
|
});
|
|
429
403
|
this.logger.error(`[Ask Knowledge Base] Error getting answer`);
|
|
430
|
-
await this.#assignAttributes(action, answer
|
|
404
|
+
await this.#assignAttributes(action, answer);
|
|
431
405
|
if (callback) {
|
|
432
406
|
if (falseIntent) {
|
|
433
407
|
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
@@ -488,14 +462,14 @@ class DirAskGPTV2 {
|
|
|
488
462
|
}
|
|
489
463
|
} else {
|
|
490
464
|
winston.info("DirAskGPTV2 resbody else case: ", resbody);
|
|
491
|
-
await this.#assignAttributes(action, answer
|
|
465
|
+
await this.#assignAttributes(action, answer);
|
|
492
466
|
if (!skip_unanswered) {
|
|
493
|
-
// console.log("this.context", JSON.stringify(this.context, null, 2));
|
|
494
467
|
const data = {
|
|
495
468
|
namespace: json.namespace,
|
|
496
469
|
question: json.question,
|
|
497
470
|
request_id: this.requestId
|
|
498
471
|
}
|
|
472
|
+
|
|
499
473
|
kbService.addUnansweredQuestion(this.projectId, data, this.token).catch((err) => {
|
|
500
474
|
winston.error("DirAskGPTV2 - Error adding unanswered question: ", {
|
|
501
475
|
status: err.response?.status,
|