@tiledesk/tiledesk-tybot-connector 2.0.48 → 2.0.50
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 +2734 -0
- package/package.json +1 -1
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +20 -2
package/package.json
CHANGED
|
@@ -425,7 +425,11 @@ class DirAskGPTV2 {
|
|
|
425
425
|
return;
|
|
426
426
|
|
|
427
427
|
} else {
|
|
428
|
-
|
|
428
|
+
let json_sources;
|
|
429
|
+
if (citations) {
|
|
430
|
+
json_sources = this.normalizeCitationSources(resbody.citations);
|
|
431
|
+
}
|
|
432
|
+
await this.#assignAttributes(action, resbody.answer, resbody.source, resbody.content_chunks, json_sources);
|
|
429
433
|
let tokens = resbody.prompt_token_size;
|
|
430
434
|
if (publicKey === true && !chunks_only) {
|
|
431
435
|
|
|
@@ -532,10 +536,11 @@ class DirAskGPTV2 {
|
|
|
532
536
|
}
|
|
533
537
|
}
|
|
534
538
|
|
|
535
|
-
async #assignAttributes(action, answer, source, chunks) {
|
|
539
|
+
async #assignAttributes(action, answer, source, chunks, json_sources) {
|
|
536
540
|
winston.debug("DirAskGPTV2assignAttributes action: ", action)
|
|
537
541
|
winston.debug("DirAskGPTV2assignAttributes answer: ", answer)
|
|
538
542
|
winston.debug("DirAskGPTV2assignAttributes source: ", source)
|
|
543
|
+
|
|
539
544
|
if (this.context.tdcache) {
|
|
540
545
|
if (action.assignReplyTo && answer) {
|
|
541
546
|
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignReplyTo, answer);
|
|
@@ -546,6 +551,9 @@ class DirAskGPTV2 {
|
|
|
546
551
|
if (action.assignChunksTo && chunks) {
|
|
547
552
|
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignChunksTo, chunks);
|
|
548
553
|
}
|
|
554
|
+
if (action.assignJsonSourcesTo && json_sources) {
|
|
555
|
+
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignJsonSourcesTo, json_sources);
|
|
556
|
+
}
|
|
549
557
|
}
|
|
550
558
|
}
|
|
551
559
|
|
|
@@ -561,6 +569,16 @@ class DirAskGPTV2 {
|
|
|
561
569
|
})
|
|
562
570
|
}
|
|
563
571
|
|
|
572
|
+
normalizeCitationSources(citations) {
|
|
573
|
+
const uniqueMap = new Map();
|
|
574
|
+
for (const { source_id, ...source } of citations) {
|
|
575
|
+
if (!uniqueMap.has(source.source_name)) {
|
|
576
|
+
uniqueMap.set(source.source_name, source);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
return Array.from(uniqueMap.values());
|
|
580
|
+
}
|
|
581
|
+
|
|
564
582
|
/**
|
|
565
583
|
* Transforms the transcirpt array in a dictionary like '0': { "question": "xxx", "answer":"xxx"}
|
|
566
584
|
* merging consecutive messages with the same role in a single question or answer.
|