Upload folder using huggingface_hub
Browse files- static/javascript/rag_cleaner.js +100 -46
- static/javascript/rag_mgr.js +3 -6
- static/javascript/rag_prompts.js +230 -86
- static/javascript/rag_rqs.js +1 -1
- static/js/ragrqs.min.js +90 -92
static/javascript/rag_cleaner.js
CHANGED
@@ -1,71 +1,125 @@
|
|
1 |
/** @format */
|
2 |
function removeTag(txt) {
|
3 |
-
txt = txt.replace(/<<</g, "").replace(/>>>/g, "");
|
4 |
txt = txt.replace(/<</g, "").replace(/>>/g, "");
|
5 |
return txt;
|
6 |
}
|
7 |
-
function uniteBrokenWords(txt) {
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
function cleanDoc(
|
14 |
try {
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
} catch (e) {
|
43 |
-
|
44 |
-
|
45 |
}
|
46 |
}
|
47 |
|
48 |
-
|
|
|
|
|
49 |
try {
|
|
|
50 |
// Rimuove caratteri non stampabili specifici
|
51 |
const charsRm = /[\u00AD\u200B\u200C\u200D\u2060\uFEFF]/g;
|
52 |
-
|
53 |
// Sostituisce spazi non standard e altri caratteri con uno spazio
|
54 |
const charsSrp = /[\u00A0\u2000-\u200A\u202F\u205F\u3000\t\r\f\v]/g;
|
55 |
-
|
56 |
// Mantieni le sequenze di escape comuni
|
57 |
-
|
58 |
// Mantieni le sequenze Unicode
|
59 |
-
|
60 |
// Mantieni i backslash nei path di file
|
61 |
-
|
62 |
// Rimuovi tutti gli altri backslash
|
63 |
-
|
64 |
// Sostituisce le sequenze di più di due newline con due newline
|
65 |
-
|
66 |
// unifica spazi multipli
|
67 |
-
|
68 |
-
return
|
69 |
} catch (e) {
|
70 |
console.error(e);
|
71 |
return `Errore di codifica nella risposta\n${e}`;
|
|
|
1 |
/** @format */
|
2 |
function removeTag(txt) {
|
3 |
+
txt = txt.replace(/<<</g, " ").replace(/>>>/g, " ");
|
4 |
txt = txt.replace(/<</g, "").replace(/>>/g, "");
|
5 |
return txt;
|
6 |
}
|
7 |
+
// function uniteBrokenWords(txt) {
|
8 |
+
// const regex = /-\n/g;
|
9 |
+
// const unitedText = txt.replace(regex, "");
|
10 |
+
// return unitedText;
|
11 |
+
// }
|
12 |
+
|
13 |
+
// function cleanDoc(txt) {
|
14 |
+
// try {
|
15 |
+
// txt = removeTag(txt);
|
16 |
+
// //unisce le parole spezzate a di fine riga
|
17 |
+
// txt = txt.replace(/-\n/g, "");
|
18 |
+
// // Rimuove caratteri non stampabili specifici
|
19 |
+
// const charsRm = /[\u00AD\u200B\u200C\u200D\u2060\uFEFF]/g;
|
20 |
+
// txt = txt.replace(charsRm, "");
|
21 |
+
// // Sostituisce spazi non standard e altri caratteri con uno spazio
|
22 |
+
// const charsSrp = /[\u00A0\u2000-\u200A\u202F\u205F\u3000\t\r\f\v]/g;
|
23 |
+
// txt = txt.replace(charsSrp, " ");
|
24 |
+
// // Mantieni le sequenze di escape comuni
|
25 |
+
// txt = txt.replace(/\\([nrtfb])/g, "$1");
|
26 |
+
// // Mantieni le sequenze Unicode
|
27 |
+
// txt = txt.replace(/\\(u[0-9a-fA-F]{4}|x[0-9a-fA-F]{2})/g, "$1");
|
28 |
+
// // Mantieni i backslash nei path di file
|
29 |
+
// txt = txt.replace(/\\([a-zA-Z]:\\|\\\\[a-zA-Z0-9_]+\\)/g, "\\\\$1");
|
30 |
+
// // Rimuovi tutti gli altri backslash
|
31 |
+
// txt = txt.replace(/\\/g, "");
|
32 |
+
// // Uniforma i caratteri di quotazione
|
33 |
+
// txt = txt.replace(/“/g, '"').replace(/”/g, '"');
|
34 |
+
// // Rimuove spazi prima della punteggiatura
|
35 |
+
// txt = txt.replace(/ +([.,;:!?])/g, "$1");
|
36 |
+
// // Rimuove linee vuote multiple
|
37 |
+
// txt = txt.replace(/\n\s*\n/g, "\n\n");
|
38 |
+
// txt = txt.replace(/\n{3,}/g, "\n\n");
|
39 |
+
// // Rimuove spazi multipli
|
40 |
+
// txt = txt.replace(/ +/g, " ");
|
41 |
+
// return txt.trim();
|
42 |
+
// } catch (e) {
|
43 |
+
// console.error(e);
|
44 |
+
// return "Errore di codifica del documento";
|
45 |
+
// }
|
46 |
+
// }
|
47 |
|
48 |
+
function cleanDoc(s) {
|
49 |
try {
|
50 |
+
s = removeTag(s);
|
51 |
+
|
52 |
+
// Unisce le parole divise dal trattino a fine riga
|
53 |
+
s = s.replace(/(\w+)-\s*\n(\w+)/g, '$1$2');
|
54 |
+
|
55 |
+
// Rimuove caratteri non stampabili specifici
|
56 |
+
const charsRm = /[\u00AD\u200B\u200C\u200D\u2060\uFEFF\u0008]/g;
|
57 |
+
s = s.replace(charsRm, '');
|
58 |
+
|
59 |
+
// Sostituisce spazi non standard e altri caratteri con uno spazio
|
60 |
+
const charsSrp = /[\u00A0\u2000-\u200A\u202F\u205F\u3000\t\r\f\v]/g;
|
61 |
+
s = s.replace(charsSrp, ' ');
|
62 |
+
|
63 |
+
// Mantieni le sequenze di escape comuni
|
64 |
+
s = s.replace(/\\([nrtfb])/g, '$1');
|
65 |
+
|
66 |
+
// Mantieni le sequenze Unicode
|
67 |
+
s = s.replace(/\\(u[0-9a-fA-F]{4}|x[0-9a-fA-F]{2})/g, '$1');
|
68 |
+
|
69 |
+
// Mantieni i backslash nei path di file
|
70 |
+
s = s.replace(/\\([a-zA-Z]:\\|\\\\[a-zA-Z0-9_]+\\)/g, '\\$1');
|
71 |
+
|
72 |
+
// Rimuovi tutti gli altri backslash
|
73 |
+
s = s.replace(/\\/g, '');
|
74 |
+
|
75 |
+
// Uniforma i caratteri di quotazione
|
76 |
+
s = s.replace('“', '"').replace('”', '"');
|
77 |
+
|
78 |
+
// Rimpiazza newline
|
79 |
+
s = s.replace(/\n/g, ' ');
|
80 |
+
|
81 |
+
// Rimuove spazi prima della punteggiatura
|
82 |
+
s = s.replace(/ +([.,;:!?])/g, '$1');
|
83 |
+
|
84 |
+
// Divide il testo in frasi
|
85 |
+
const sentences = s.split(/(?<=[.?!])\s+/);
|
86 |
+
const minLen = 5;
|
87 |
+
s = sentences.filter(sentence => sentence.trim().length >= minLen).map(sentence => sentence.trim()).join('\n');
|
88 |
+
|
89 |
+
// Rimuove spazi multipli
|
90 |
+
s = s.replace(/ +/g, ' ');
|
91 |
+
|
92 |
+
return s.trim();
|
93 |
} catch (e) {
|
94 |
+
console.error(e);
|
95 |
+
return "Errore di codifica del documento";
|
96 |
}
|
97 |
}
|
98 |
|
99 |
+
|
100 |
+
|
101 |
+
function cleanResponse(s) {
|
102 |
try {
|
103 |
+
s=removeTag(s);
|
104 |
// Rimuove caratteri non stampabili specifici
|
105 |
const charsRm = /[\u00AD\u200B\u200C\u200D\u2060\uFEFF]/g;
|
106 |
+
s = s.replace(charsRm, "");
|
107 |
// Sostituisce spazi non standard e altri caratteri con uno spazio
|
108 |
const charsSrp = /[\u00A0\u2000-\u200A\u202F\u205F\u3000\t\r\f\v]/g;
|
109 |
+
s = s.replace(charsSrp, " ");
|
110 |
// Mantieni le sequenze di escape comuni
|
111 |
+
s = s.replace(/\\([nrtfb])/g, "$1");
|
112 |
// Mantieni le sequenze Unicode
|
113 |
+
s = s.replace(/\\(u[0-9a-fA-F]{4}|x[0-9a-fA-F]{2})/g, "$1");
|
114 |
// Mantieni i backslash nei path di file
|
115 |
+
s = s.replace(/\\([a-zA-Z]:\\|\\\\[a-zA-Z0-9_]+\\)/g, "\\\\$1");
|
116 |
// Rimuovi tutti gli altri backslash
|
117 |
+
s = s.replace(/\\/g, "");
|
118 |
// Sostituisce le sequenze di più di due newline con due newline
|
119 |
+
s = s.replace(/\n{3,}/g, "\n\n");
|
120 |
// unifica spazi multipli
|
121 |
+
s = s.replace(/ +/g, " ");
|
122 |
+
return s.trim();
|
123 |
} catch (e) {
|
124 |
console.error(e);
|
125 |
return `Errore di codifica nella risposta\n${e}`;
|
static/javascript/rag_mgr.js
CHANGED
@@ -178,8 +178,7 @@ const Rag = {
|
|
178 |
continue;
|
179 |
} else if (ei.errorType === TIMEOUT_ERROR) {
|
180 |
UaLog.log(`Error timeout Doc`);
|
181 |
-
wait(5);
|
182 |
-
// UaLog.log(`Error timeout Doc 2`);
|
183 |
continue;
|
184 |
} else {
|
185 |
throw err;
|
@@ -214,8 +213,7 @@ const Rag = {
|
|
214 |
continue;
|
215 |
} else if (ei.errorType === TIMEOUT_ERROR) {
|
216 |
UaLog.log(`Error timeout build Context`);
|
217 |
-
wait(5);
|
218 |
-
// UaLog.log(`Error timeout build Context 2`);
|
219 |
continue;
|
220 |
} else {
|
221 |
throw err;
|
@@ -256,8 +254,7 @@ const Rag = {
|
|
256 |
continue;
|
257 |
} else if (ei.errorType === TIMEOUT_ERROR) {
|
258 |
UaLog.log(`Error timeout with Context`);
|
259 |
-
wait(5);
|
260 |
-
// UaLog.log(`Error timeout with Context 2`);
|
261 |
continue;
|
262 |
} else {
|
263 |
throw err;
|
|
|
178 |
continue;
|
179 |
} else if (ei.errorType === TIMEOUT_ERROR) {
|
180 |
UaLog.log(`Error timeout Doc`);
|
181 |
+
// wait(5);
|
|
|
182 |
continue;
|
183 |
} else {
|
184 |
throw err;
|
|
|
213 |
continue;
|
214 |
} else if (ei.errorType === TIMEOUT_ERROR) {
|
215 |
UaLog.log(`Error timeout build Context`);
|
216 |
+
// wait(5);
|
|
|
217 |
continue;
|
218 |
} else {
|
219 |
throw err;
|
|
|
254 |
continue;
|
255 |
} else if (ei.errorType === TIMEOUT_ERROR) {
|
256 |
UaLog.log(`Error timeout with Context`);
|
257 |
+
// wait(5);
|
|
|
258 |
continue;
|
259 |
} else {
|
260 |
throw err;
|
static/javascript/rag_prompts.js
CHANGED
@@ -2,108 +2,252 @@
|
|
2 |
|
3 |
"use strict";
|
4 |
|
5 |
-
function promptDoc(documento, domanda, docName) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
return `
|
7 |
-
|
8 |
|
9 |
-
|
10 |
|
11 |
-
|
12 |
-
1.
|
13 |
-
2.
|
14 |
-
3.
|
15 |
-
4.
|
16 |
-
5.
|
17 |
-
6. Prepara una risposta chiara e dettagliata.
|
18 |
-
7. Inizia con una breve introduzione, sviluppa l'analisi, esponi le inferenze e concludi con una sintesi.
|
19 |
-
8. Mantieni un tono oggettivo e uno stile fluido e coerente.
|
20 |
-
|
21 |
-
DOCUMENTO:
|
22 |
-
<<<INIZIO_DOCUMENTO>>>
|
23 |
-
${documento}
|
24 |
-
<<<FINE_DOCUMENTO>>>
|
25 |
-
|
26 |
-
DOMANDA:
|
27 |
-
${domanda}
|
28 |
-
|
29 |
-
OUTPUT_FORMAT:
|
30 |
-
La risposta dovrà essere strutturata nel seguente modo:
|
31 |
-
- Introduzione:
|
32 |
-
- Concetti chiave:
|
33 |
-
- Citazioni:
|
34 |
-
- Inferenze:
|
35 |
-
- Dettagli rilevanti:
|
36 |
-
- Sintesi:
|
37 |
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
`;
|
40 |
}
|
41 |
|
42 |
-
function promptBuildContext(informazioni, domanda) {
|
43 |
return `
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
1.
|
50 |
-
2.
|
51 |
-
3.
|
52 |
-
4.
|
53 |
-
5.
|
54 |
-
6.
|
55 |
-
7.
|
56 |
-
8.
|
57 |
-
9.
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
INFORAZIONI:
|
62 |
<<<INIZIO_INFORMAZIONI>>>
|
63 |
${informazioni}
|
64 |
<<<FINE_INFORMAZIONI>>>
|
65 |
|
66 |
-
|
67 |
-
|
|
|
|
|
|
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
- Citazioni:
|
74 |
-
- Inferenze:
|
75 |
-
- Connessioni fra contenuti:
|
76 |
-
- Dettagli rilevanti:
|
77 |
-
- Sintesi:
|
78 |
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
`;
|
81 |
}
|
82 |
|
83 |
function promptWithContext(contesto, domanda) {
|
84 |
return `
|
85 |
-
SYSTEM: Sei un sistema AI specializzato nell'analisi
|
86 |
|
87 |
-
TASK: Elabora la risposta alla domanda sulla base del contesto fornito.
|
88 |
|
89 |
INSTRUCTIONS:
|
90 |
-
1. Analizza attentamente il contesto
|
91 |
-
2. Estrai i concetti chiave e
|
92 |
-
3.
|
93 |
-
4.
|
94 |
-
5.
|
95 |
-
6.
|
|
|
|
|
96 |
|
97 |
CONTESTO:
|
98 |
<<<INIZIO_CONTESTO>>>
|
99 |
${contesto}
|
100 |
<<<FINE_CONTESTO>>>
|
101 |
|
102 |
-
DOMANDA:
|
103 |
-
${domanda}
|
104 |
|
105 |
-
OUTPUT_FORMAT:
|
106 |
-
Rispondi con un testo piano suddiviso in paragrafi.Evita di usare etichette, elenchi o marcatori speciali.
|
107 |
|
108 |
RESPONSE:
|
109 |
`;
|
@@ -113,14 +257,14 @@ function promptThread(contesto, conversazione, richiesta) {
|
|
113 |
return `
|
114 |
SYSTEM: Sei un assistente AI versatile progettato per gestire conversazioni dinamiche e adattarti a varie richieste. Rispondi sempre in italiano.
|
115 |
|
116 |
-
TASK: Elabora la risposta alla richiesta sulla base del contesto fornito e della conversazione.
|
117 |
|
118 |
INSTRUCTIONS:
|
119 |
-
1. Analizza attentamente il contesto, la conversazione precedente e la richiesta
|
120 |
2. Interpreta l'intento dell'utente senza limitarti a categorie predefinite.
|
121 |
3. Adatta la tua risposta in base all'intento percepito, sia esso una domanda, una richiesta di azione, un'istruzione specifica o altro.
|
122 |
4. Mantieni una stretta coerenza con il contesto della conversazione.
|
123 |
-
5. Basa la tua risposta
|
124 |
6. Evita divagazioni o argomentazioni non direttamente pertinenti alla richiesta o al contesto.
|
125 |
7. Fai riferimento a informazioni precedenti quando sono pertinenti, citando specificamente la fonte.
|
126 |
8. Se l'intento non è chiaro, chiedi gentilmente chiarimenti invece di fare supposizioni.
|
@@ -136,11 +280,9 @@ ${contesto}
|
|
136 |
${conversazione}
|
137 |
<<<FINE_CONVERSAZIONE>>>
|
138 |
|
139 |
-
RICHIESTA:
|
140 |
-
${richiesta}
|
141 |
|
142 |
-
OUTPUT_FORMAT:
|
143 |
-
Rispondi con un testo piano suddiviso in paragrafi.Evita di usare etichette, elenchi o marcatori speciali.
|
144 |
|
145 |
RESPONSE:
|
146 |
`;
|
@@ -205,14 +347,15 @@ function getPayloadDoc(prompt) {
|
|
205 |
parameters: {
|
206 |
task: "text2text-generation",
|
207 |
max_new_tokens: 1024,
|
|
|
208 |
num_return_sequences: 1,
|
209 |
temperature: 0.2,
|
210 |
top_p: 0.85,
|
211 |
top_k: 30,
|
212 |
do_sample: false,
|
213 |
-
no_repeat_ngram_size:
|
214 |
num_beams: 4,
|
215 |
-
repetition_penalty: 1.
|
216 |
return_full_text: false,
|
217 |
details: false,
|
218 |
max_time: 90.0,
|
@@ -231,15 +374,16 @@ function getPayloadBuildContext(prompt) {
|
|
231 |
inputs: prompt,
|
232 |
parameters: {
|
233 |
task: "text2text-generation",
|
234 |
-
max_new_tokens:
|
|
|
235 |
num_return_sequences: 1,
|
236 |
-
temperature: 0.2
|
237 |
top_p: 0.85,
|
238 |
top_k: 30,
|
239 |
do_sample: false,
|
240 |
no_repeat_ngram_size: 4,
|
241 |
-
num_beams:
|
242 |
-
repetition_penalty: 1.
|
243 |
return_full_text: false,
|
244 |
details: false,
|
245 |
max_time: 180.0,
|
|
|
2 |
|
3 |
"use strict";
|
4 |
|
5 |
+
// function promptDoc(documento, domanda, docName) {
|
6 |
+
// return `
|
7 |
+
// SYSTEM: Sei un assistente AI specializzato nell'analisi di documenti. Rispondi ESCLUSIVAMENTE in italiano. Non usare altre lingue in nessuna parte della risposta.
|
8 |
+
|
9 |
+
// TASK: Analizza il documento ${docName} ed estrai le informazioni rilevanti per rispondere alla domanda fornita.
|
10 |
+
|
11 |
+
// INSTRUCTIONS:
|
12 |
+
// 1. Identifica la tipologia e lo scopo del documento (es. articolo scientifico, racconto, saggio, documento tecnico) e adatta l'analisi di conseguenza.
|
13 |
+
// 2. Analizza attentamente il documento fornito e identifica le informazioni pertinenti alla domanda.
|
14 |
+
// 3. Estrai i concetti chiave e fai inferenze ragionevoli.
|
15 |
+
// 4. Focalizzati sull'estrazione di concetti chiave e inferenze rilevanti per la domanda.
|
16 |
+
// 5. Seleziona citazioni specifiche direttamente collegate alla domanda.
|
17 |
+
// 6. Prepara una risposta chiara e dettagliata.
|
18 |
+
// 7. Inizia con una breve introduzione, sviluppa l'analisi, esponi le inferenze e concludi con una sintesi.
|
19 |
+
// 8. Mantieni un tono oggettivo e uno stile fluido e coerente.
|
20 |
+
|
21 |
+
// DOCUMENTO:
|
22 |
+
// <<<INIZIO_DOCUMENTO>>>
|
23 |
+
// ${documento}
|
24 |
+
// <<<FINE_DOCUMENTO>>>
|
25 |
+
|
26 |
+
// DOMANDA:
|
27 |
+
// ${domanda}
|
28 |
+
|
29 |
+
// OUTPUT_FORMAT:
|
30 |
+
// La risposta dovrà essere strutturata nel seguente modo:
|
31 |
+
// - Introduzione:
|
32 |
+
// - Concetti chiave:
|
33 |
+
// - Citazioni:
|
34 |
+
// - Inferenze:
|
35 |
+
// - Dettagli rilevanti:
|
36 |
+
// - Sintesi:
|
37 |
+
|
38 |
+
// RESPONSE:
|
39 |
+
// `;
|
40 |
+
// }
|
41 |
+
|
42 |
+
// function promptBuildContext(informazioni, domanda) {
|
43 |
+
// return `
|
44 |
+
// SYSTEM: Sei un assitente AI specializzato nella riorganizzazione di informazioni come contesto nelle interrogazioni ad un LLM. Rispondi ESCLUSIVAMENTE in italiano. Non usare altre lingue in nessuna parte della risposta.
|
45 |
+
|
46 |
+
// TASK: Analizza e riorganizza le informazioi rilevanti per rispondere alla domada fornite seguendo le istruzioni.
|
47 |
+
|
48 |
+
// INSTRUCTIONS:
|
49 |
+
// 1. Analizza attentamente le informazioi e identifica i temi e i concetti simili.
|
50 |
+
// 2. Estrai i concetti chiave e fai inferenze ragionevoli.
|
51 |
+
// 3. Organizza le informazioni in una struttura logica e coerente.
|
52 |
+
// 4. Includi una breve introduzione che presenti i temi principali.
|
53 |
+
// 5. Sviluppa l'analisi raggruppando le informazioni per argomenti correlati.
|
54 |
+
// 6. Presenta le inferenze e le connessioni tra i diversi concetti.
|
55 |
+
// 7. Includi, se rilevanti, dettagli come nomi propri, termini tecnici, date o luoghi che contribuiscono alla precisione del contesto.
|
56 |
+
// 8. Concludi con una sintesi che riassuma i punti chiave e la struttura logica.
|
57 |
+
// 9. Evidenzia le connessioni tra contenuti estratti da fonti diverse.
|
58 |
+
// 10. Effettua un controllo finale per assicurarti che tutte le informazioni chiave siano state incluse.
|
59 |
+
// 11. Mantieni uno stile fluido e coerente.
|
60 |
+
|
61 |
+
// INFORAZIONI:
|
62 |
+
// <<<INIZIO_INFORMAZIONI>>>
|
63 |
+
// ${informazioni}
|
64 |
+
// <<<FINE_INFORMAZIONI>>>
|
65 |
+
|
66 |
+
// DOMANDA:
|
67 |
+
// ${domanda}
|
68 |
+
|
69 |
+
// OUTPUT_FORMAT:
|
70 |
+
// La risposta dovrà essere strutturata nel seguente modo:
|
71 |
+
// - Introduzione:
|
72 |
+
// - Concetti chiave:
|
73 |
+
// - Citazioni:
|
74 |
+
// - Inferenze:
|
75 |
+
// - Connessioni fra contenuti:
|
76 |
+
// - Dettagli rilevanti:
|
77 |
+
// - Sintesi:
|
78 |
+
|
79 |
+
// RESPONSE:
|
80 |
+
// `;
|
81 |
+
// }
|
82 |
+
|
83 |
+
// function promptWithContext(contesto, domanda) {
|
84 |
+
// return `
|
85 |
+
// SYSTEM: Sei un sistema AI specializzato nell'analisi semantica di informazioni estratte da documenti. Rispondi sempre ed esclusivamente in italiano.
|
86 |
+
|
87 |
+
// TASK: Elabora la risposta alla domanda sulla base del contesto fornito.
|
88 |
+
|
89 |
+
// INSTRUCTIONS:
|
90 |
+
// 1. Analizza attentamente il contesto e identifica le informazioni pertinenti alla domanda.
|
91 |
+
// 2. Estrai i concetti chiave e fai inferenze ragionevoli.
|
92 |
+
// 3. Prepara una risposta chiara e dettagliata utilizzandoo al meglio il contesto.
|
93 |
+
// 4. Inizia con una breve introduzione, sviluppa l'analisi, elabora le inferenze e concludi con una sintesi.
|
94 |
+
// 5. Se la domanda richiede di citare le fonti, fai riferimento al documento fornito distinguendolo chiaramente da eventuali altre fonti citate all'interno del contesto stesso.
|
95 |
+
// 6. Mantieni un tono oggettivo e uno stile fluido e coerente.
|
96 |
+
|
97 |
+
// CONTESTO:
|
98 |
+
// <<<INIZIO_CONTESTO>>>
|
99 |
+
// ${contesto}
|
100 |
+
// <<<FINE_CONTESTO>>>
|
101 |
+
|
102 |
+
// DOMANDA:
|
103 |
+
// ${domanda}
|
104 |
+
|
105 |
+
// OUTPUT_FORMAT:
|
106 |
+
// Rispondi con un testo piano suddiviso in paragrafi.Evita di usare etichette, elenchi o marcatori speciali.
|
107 |
+
|
108 |
+
// RESPONSE:
|
109 |
+
// `;
|
110 |
+
// }
|
111 |
+
|
112 |
+
// function promptThread(contesto, conversazione, richiesta) {
|
113 |
+
// return `
|
114 |
+
// SYSTEM: Sei un assistente AI versatile progettato per gestire conversazioni dinamiche e adattarti a varie richieste. Rispondi sempre in italiano.
|
115 |
+
|
116 |
+
// TASK: Elabora la risposta alla richiesta sulla base del contesto fornito e della conversazione.
|
117 |
+
|
118 |
+
// INSTRUCTIONS:
|
119 |
+
// 1. Analizza attentamente il contesto, la conversazione precedente e la richiesta attuale.
|
120 |
+
// 2. Interpreta l'intento dell'utente senza limitarti a categorie predefinite.
|
121 |
+
// 3. Adatta la tua risposta in base all'intento percepito, sia esso una domanda, una richiesta di azione, un'istruzione specifica o altro.
|
122 |
+
// 4. Mantieni una stretta coerenza con il contesto della conversazione.
|
123 |
+
// 5. Basa la tua risposta principalmente sulle informazioni fornite nel contesto e nella conversazione.
|
124 |
+
// 6. Evita divagazioni o argomentazioni non direttamente pertinenti alla richiesta o al contesto.
|
125 |
+
// 7. Fai riferimento a informazioni precedenti quando sono pertinenti, citando specificamente la fonte.
|
126 |
+
// 8. Se l'intento non è chiaro, chiedi gentilmente chiarimenti invece di fare supposizioni.
|
127 |
+
// 9. Sii flessibile: se la richiesta implica un'azione specifica, adattati di conseguenza.
|
128 |
+
// 10. Se è necessario integrare con conoscenze generali, specifica chiaramente quando lo stai facendo.
|
129 |
+
|
130 |
+
// CONTESTO:
|
131 |
+
// <<<BEGIN_CONTESTO>>>
|
132 |
+
// ${contesto}
|
133 |
+
// <<<END_CONTESTO>>>
|
134 |
+
|
135 |
+
// <<<INIZIO_CONVERSAZIONE>>>
|
136 |
+
// ${conversazione}
|
137 |
+
// <<<FINE_CONVERSAZIONE>>>
|
138 |
+
|
139 |
+
// RICHIESTA:
|
140 |
+
// ${richiesta}
|
141 |
+
|
142 |
+
// OUTPUT_FORMAT:
|
143 |
+
// Rispondi con un testo piano suddiviso in paragrafi.Evita di usare etichette, elenchi o marcatori speciali.
|
144 |
+
|
145 |
+
// RESPONSE:
|
146 |
+
// `;
|
147 |
+
// }
|
148 |
+
/////////////////
|
149 |
+
function promptDoc(testo, domanda, docName) {
|
150 |
return `
|
151 |
+
RUOLO: Sei un assistente AI specializzato nell'analisi documentale e nell'estrazione mirata di informazioni. Rispondi esclusivamente in italiano.
|
152 |
|
153 |
+
COMPITO: Analizza l'estratto del documento "${docName}" e identifica le informazioni rilevanti per rispondere alla domanda: "${domanda}".
|
154 |
|
155 |
+
ISTRUZIONI:
|
156 |
+
1. Esamina il testo e identifica le informazioni utili per costruire un contesto relativo alla domanda.
|
157 |
+
2. Per ogni informazione rilevante, fornisci una breve descrizione.
|
158 |
+
3. Elenca i punti chiave pertinenti per ogni informazione.
|
159 |
+
4. Riporta elementi specifici (dati, citazioni, eventi) se utili per il contesto.
|
160 |
+
5. Struttura la risposta secondo il formato di output specificato.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
|
162 |
+
TESTO DA ANALIZZARE:
|
163 |
+
<<<INIZIO_TESTO>>>
|
164 |
+
${testo}
|
165 |
+
<<<FINE_TESTO>>>
|
166 |
+
|
167 |
+
FORMATO DI OUTPUT:
|
168 |
+
- Informazione 1:
|
169 |
+
Descrizione:
|
170 |
+
Punti chiave:
|
171 |
+
Elementi specifici:
|
172 |
+
|
173 |
+
- Informazione 2:
|
174 |
+
Descrizione:
|
175 |
+
Punti chiave:
|
176 |
+
Elementi specifici:
|
177 |
+
|
178 |
+
(Ripeti il formato per ogni informazione identificata)
|
179 |
+
|
180 |
+
RISPOSTA:
|
181 |
`;
|
182 |
}
|
183 |
|
184 |
+
function promptBuildContext(informazioni, domanda = "") {
|
185 |
return `
|
186 |
+
RUOLO: Sei un assistente AI esperto nella sintesi e nell'organizzazione mirata di informazioni. Rispondi sempre ed esclusivamente in italiano.
|
187 |
+
|
188 |
+
COMPITO: Organizza e sintetizza le informazioni estratte da frammenti di testo di un documento, creando un contesto utile per rispondere alla domanda: "${domanda}".
|
189 |
+
|
190 |
+
ISTRUZIONI:
|
191 |
+
1. Esamina tutte le informazioni fornite.
|
192 |
+
2. Seleziona e raggruppa le informazioni pertinenti alla domanda.
|
193 |
+
3. Per ogni gruppo di informazioni rilevanti, genera una descrizione concisa.
|
194 |
+
4. Elenca i punti chiave essenziali per comprendere il contesto.
|
195 |
+
5. Riporta elementi specifici (dati, citazioni, eventi) se utili.
|
196 |
+
6. Elimina le informazioni ridondanti, mantenendo solo la versione più completa.
|
197 |
+
7. Elabora inferenze logiche basate sulle informazioni, se rilevanti per il contesto.
|
198 |
+
8. Genera una sintesi finale del contesto.
|
199 |
+
9. Struttura la risposta secondo il formato di output specificato.
|
200 |
+
|
201 |
+
INFORMAZIONI:
|
|
|
|
|
202 |
<<<INIZIO_INFORMAZIONI>>>
|
203 |
${informazioni}
|
204 |
<<<FINE_INFORMAZIONI>>>
|
205 |
|
206 |
+
FORMATO DI OUTPUT:
|
207 |
+
- Informazioni 1:
|
208 |
+
Descrizione:
|
209 |
+
Punti chiave:
|
210 |
+
Elementi rilevanti:
|
211 |
|
212 |
+
- Informazioni 2:
|
213 |
+
Descrizione:
|
214 |
+
Punti chiave:
|
215 |
+
Elementi rilevanti:
|
|
|
|
|
|
|
|
|
|
|
216 |
|
217 |
+
(Ripeti il formato per ogni gruppo di informazioni
|
218 |
+
|
219 |
+
- Inferenze Logiche:
|
220 |
+
|
221 |
+
- Sintesi Finale:
|
222 |
+
|
223 |
+
RISPOSTA:
|
224 |
`;
|
225 |
}
|
226 |
|
227 |
function promptWithContext(contesto, domanda) {
|
228 |
return `
|
229 |
+
SYSTEM: Sei un sistema AI specializzato nell'analisi di informazioni estratte da documenti.
|
230 |
|
231 |
+
TASK: Elabora la risposta alla domanda "${domanda}" sulla base del contesto fornito.
|
232 |
|
233 |
INSTRUCTIONS:
|
234 |
+
1. Analizza attentamente il contesto fornito, identificando le informazioni pertinenti alla domanda: "${domanda}".
|
235 |
+
2. Estrai i concetti chiave e formula inferenze ragionevoli basate sulle informazioni disponibili.
|
236 |
+
3. Inizia la risposta con una breve introduzione che presenta l'argomento e il contesto.
|
237 |
+
4. Procedi con un'analisi dettagliata delle informazioni rilevanti trovate nel contesto.
|
238 |
+
5. Concludi con una sintesi che riassume i punti chiave e fornisce una conclusione generale.
|
239 |
+
6. Se richiesto, cita le fonti facendo riferimento al "documento fornito" per il contesto dato, distinguendolo chiaramente da eventuali altre fonti citate all'interno del contesto stesso.
|
240 |
+
7. Mantieni uno stile di scrittura fluido durante tutta la risposta.
|
241 |
+
8. Assicurati che la risposta sia completa e risponda direttamente alla domanda posta.
|
242 |
|
243 |
CONTESTO:
|
244 |
<<<INIZIO_CONTESTO>>>
|
245 |
${contesto}
|
246 |
<<<FINE_CONTESTO>>>
|
247 |
|
248 |
+
DOMANDA: ${domanda}
|
|
|
249 |
|
250 |
+
OUTPUT_FORMAT: Fornisci la risposta in testo semplice e lineare suddiviso in paragrafi.
|
|
|
251 |
|
252 |
RESPONSE:
|
253 |
`;
|
|
|
257 |
return `
|
258 |
SYSTEM: Sei un assistente AI versatile progettato per gestire conversazioni dinamiche e adattarti a varie richieste. Rispondi sempre in italiano.
|
259 |
|
260 |
+
TASK: Elabora la risposta alla richiesta "${richiesta}" sulla base del contesto fornito e della conversazione.
|
261 |
|
262 |
INSTRUCTIONS:
|
263 |
+
1. Analizza attentamente il contesto, la conversazione precedente e la richiesta: "${richiesta}".
|
264 |
2. Interpreta l'intento dell'utente senza limitarti a categorie predefinite.
|
265 |
3. Adatta la tua risposta in base all'intento percepito, sia esso una domanda, una richiesta di azione, un'istruzione specifica o altro.
|
266 |
4. Mantieni una stretta coerenza con il contesto della conversazione.
|
267 |
+
5. Basa la tua risposta sulle informazioni fornite nel contesto e nella conversazione.
|
268 |
6. Evita divagazioni o argomentazioni non direttamente pertinenti alla richiesta o al contesto.
|
269 |
7. Fai riferimento a informazioni precedenti quando sono pertinenti, citando specificamente la fonte.
|
270 |
8. Se l'intento non è chiaro, chiedi gentilmente chiarimenti invece di fare supposizioni.
|
|
|
280 |
${conversazione}
|
281 |
<<<FINE_CONVERSAZIONE>>>
|
282 |
|
283 |
+
RICHIESTA: ${richiesta}
|
|
|
284 |
|
285 |
+
OUTPUT_FORMAT: Fornisci la risposta in testo semplice e lineare suddiviso in paragrafi.
|
|
|
286 |
|
287 |
RESPONSE:
|
288 |
`;
|
|
|
347 |
parameters: {
|
348 |
task: "text2text-generation",
|
349 |
max_new_tokens: 1024,
|
350 |
+
min_length:200,
|
351 |
num_return_sequences: 1,
|
352 |
temperature: 0.2,
|
353 |
top_p: 0.85,
|
354 |
top_k: 30,
|
355 |
do_sample: false,
|
356 |
+
no_repeat_ngram_size: 3,
|
357 |
num_beams: 4,
|
358 |
+
repetition_penalty: 1.5,
|
359 |
return_full_text: false,
|
360 |
details: false,
|
361 |
max_time: 90.0,
|
|
|
374 |
inputs: prompt,
|
375 |
parameters: {
|
376 |
task: "text2text-generation",
|
377 |
+
max_new_tokens: 5000,
|
378 |
+
min_length:400,
|
379 |
num_return_sequences: 1,
|
380 |
+
temperature: 0.7,//0.2
|
381 |
top_p: 0.85,
|
382 |
top_k: 30,
|
383 |
do_sample: false,
|
384 |
no_repeat_ngram_size: 4,
|
385 |
+
num_beams: 6,
|
386 |
+
repetition_penalty: 1.4,
|
387 |
return_full_text: false,
|
388 |
details: false,
|
389 |
max_time: 180.0,
|
static/javascript/rag_rqs.js
CHANGED
@@ -19,7 +19,7 @@
|
|
19 |
*/
|
20 |
|
21 |
"use strict";
|
22 |
-
const VERS = "0.1.
|
23 |
|
24 |
var xlog = console.log;
|
25 |
var xerror = console.error;
|
|
|
19 |
*/
|
20 |
|
21 |
"use strict";
|
22 |
+
const VERS = "0.1.50 (14-09-2024)";
|
23 |
|
24 |
var xlog = console.log;
|
25 |
var xerror = console.error;
|
static/js/ragrqs.min.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
-
function removeTag(a){a=a.replace(/<<</g,"").replace(/>>>/g,"");return a=a.replace(/<</g,"").replace(/>>/g,"")}
|
2 |
-
function cleanDoc(a){try{return a=removeTag(a),a=a.replace(
|
3 |
-
"\n
|
4 |
-
function cleanResponse(a){try{return a=a.replace(/[\u00AD\u200B\u200C\u200D\u2060\uFEFF]/g,""),a=a.replace(/[\u00A0\u2000-\u200A\u202F\u205F\u3000\t\r\f\v]/g," "),a=a.replace(/\\([nrtfb])/g,"$1"),a=a.replace(/\\(u[0-9a-fA-F]{4}|x[0-9a-fA-F]{2})/g,"$1"),a=a.replace(/\\([a-zA-Z]:\\|\\\\[a-zA-Z0-9_]+\\)/g,"\\\\$1"),a=a.replace(/\\/g,""),a=a.replace(/\n{3,}/g,"\n\n"),a=a.replace(/ +/g," "),a.trim()}catch(b){return console.error(b),`Errore di codifica nella risposta\n${b}`}}
|
5 |
function cleanOut(a){return a=a.replace(/\n{3,}/g,"\n\n")};const ID_RESPONSES="id_responses",ID_DOC_NAMES="id_doc_names",ID_DOCS="id_docs;",ID_RAG="id_rag",ID_THREAD="id_thread",UaDb={create(a,b){localStorage.getItem(a)?xerror(`ID ${a} already exists.`):localStorage.setItem(a,b)},read(a){const b=localStorage.getItem(a);return null===b?(xlog(`UaDb.read ${a} not found.`),""):b},update(a,b){localStorage.getItem(a)?localStorage.setItem(a,b):xlog(`UaDb.update ${a} not found.`)},delete(a){localStorage.getItem(a)?localStorage.removeItem(a):xerror(`ID ${a} not found.`)},
|
6 |
save(a,b){localStorage.setItem(a,b)},getAllIds(){const a=[];for(let b=0;b<localStorage.length;b++)a.push(localStorage.key(b));return a},saveArray(a,b){b=JSON.stringify(b);UaDb.save(a,b)},readArray(a){a=UaDb.read(a);return 0==a.trim().length?[]:JSON.parse(a)},saveJson(a,b){b=JSON.stringify(b);UaDb.save(a,b)},readJson(a){return(a=UaDb.read(a))?JSON.parse(a):{}}},DataMgr={docs:[],doc_names:[],linkToName(a){a=a.split("/");return a[a.length-1]},async loadDoc(a){this.readDbDocNames();try{const b=await requestGet(a),
|
7 |
c=cleanDoc(b),d=this.linkToName(a);if(this.doc_names.includes(d))alert(`Il docuento ${d} \u00e8 gi\u00e0 caricato`);else return this.doc_names.push(d),this.docs.push(c),this.saveDbDocs(),c}catch(b){alert("loadDoc()\n"+b+"\n"+a)}},addDoc(a,b){b=cleanDoc(b);this.docs.push(b);this.doc_names.push(a);this.saveDbDocs()},saveDbDocs(){UaDb.saveArray(ID_DOC_NAMES,this.doc_names);UaDb.saveArray(ID_DOCS,this.docs)},readDbDocs(){this.docs=UaDb.readArray(ID_DOCS)},readDbDocNames(){this.doc_names=UaDb.readArray(ID_DOC_NAMES)},
|
@@ -35,119 +35,119 @@ const MAX_PROMPT_LENGTH=81920,PROMPT_DECR=2048,TIMEOUT=6E4;function wait(a){retu
|
|
35 |
const truncInput=(a,b)=>a.substring(0,a.length-b),setMaxLen=a=>a.substring(0,MAX_PROMPT_LENGTH-1E3),getPartSize=(a,b,c)=>{c=MAX_PROMPT_LENGTH-c;a.length+b.length<c?c=a.length:(a=a.indexOf(".",c),a=(-1!=a?a:c)+1,a>c+100&&(a=c),c=a);return c},getPartDoc=(a,b)=>{const c=a.substring(0,b);a=a.substring(b).trim();return[c,a]},ragLog=(a,b,c,d)=>{const e=MAX_PROMPT_LENGTH;d=d.reduce((f,g)=>f+g.length,0);xlog(`${a} mx:${e} lft:${b} rgt:${c} arr:${d}`);a=formatRow([a,b,c,d],[8,-7,-7,-7]);UaLog.log(a)},Rag=
|
36 |
{ragContext:"",ragQuery:"",ragAnswer:"",answers:[],docContextLst:[],prompts:[],doc:"",doc_part:"",init(){this.readRespsFromDb();this.readFromDb()},returnOk(){return 10<this.ragContext.length},saveToDb(){UaDb.saveJson(ID_RAG,{context:this.ragContext,ragquery:this.ragQuery,raganswer:this.ragAnswer});UaDb.saveArray(ID_THREAD,ThreadMgr.rows)},readFromDb(){const a=UaDb.readJson(ID_RAG);this.ragContext=a.context||"";this.ragQuery=a.ragquery||"";this.ragAnswer=a.raganswer||"";ThreadMgr.rows=UaDb.readArray(ID_THREAD)},
|
37 |
saveRespToDb(){UaDb.saveArray(ID_RESPONSES,this.answers)},readRespsFromDb(){this.answers=UaDb.readArray(ID_RESPONSES)},async requestDocsRAG(a){DataMgr.deleteJsonDati();DataMgr.readDbDocNames();DataMgr.readDbDocs();this.ragQuery=a;this.saveToDb();var b=0;try{var c=1;for(let e=0;e<DataMgr.docs.length;e++){let f=DataMgr.docs[e];if(""==f.trim())continue;const g=DataMgr.doc_names[e],k=f.length;xlog(`${g} (${k}) `);UaLog.log(`${g} (${k}) `);++b;var d=1;let h=0,l="",t="",u="",m="",v=[];for(;;){let r=getPartSize(f,
|
38 |
-
promptDoc("",a,""),h);if(10>r)break;[t,u]=getPartDoc(f,r);ragLog(`${c}) ${b},${d}`,t.length,u.length,this.answers);l=promptDoc(t,a,g);const p=getPayloadDoc(l);try{if(m=await HfRequest.post(p,TIMEOUT),!m)return""}catch(n){console.error("RR1)\n",n);const w=getErrorInfo(n);if(w.errorType===ERROR_TOKENS){UaLog.log(`Error tokens Doc ${l.length}`);h+=PROMPT_DECR;continue}else if(w.errorType===TIMEOUT_ERROR){UaLog.log("Error timeout Doc");
|
39 |
-
this.answers.push(`DOCUMENTO : ${g}_${d}\n${m}`)}const x=v.length;let q=v.join("\n\n");for(d="";;){l=promptBuildContext(q,this.ragQuery);const r=getPayloadBuildContext(l);try{if(d=await HfRequest.post(r,TIMEOUT),!d)return""}catch(p){console.error("RR2)",p);const n=getErrorInfo(p);if(n.errorType===ERROR_TOKENS){UaLog.log(`Error tokens build Context ${l.length}`);q=truncInput(q,PROMPT_DECR);q=setMaxLen(q);continue}else if(n.errorType===TIMEOUT_ERROR){UaLog.log("Error timeout build Context");
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
b
|
44 |
TIMEOUT_ERROR){UaLog.log("Error timeout Thread");continue}else throw g;}break}b=cleanResponse(b);ThreadMgr.add(a,b);b=ThreadMgr.getThread();UaLog.log(`Conversazione (${c.length})`)}catch(d){throw console.error(d),b=`${d}`,d;}finally{return b}}},LLM="## Assistant:",USER="## User:",ThreadMgr={rows:[],init(){this.rows=[];Rag.ragAnswer?this.add(Rag.ragQuery,Rag.ragAnswer):this.add("","")},add(a,b){this.rows.push([a,b]);UaDb.saveArray(ID_THREAD,ThreadMgr.rows)},getThread(){const a=[];for(const b of this.rows)a.push(`${USER}\n${b[0]}\n${LLM}\n${b[1]}\n`);
|
45 |
return a.join("\n\n")},isFirst(){return 2>this.rows.length}};function promptDoc(a,b,c){return`
|
46 |
-
|
47 |
|
48 |
-
|
49 |
|
50 |
-
|
51 |
-
1.
|
52 |
-
2.
|
53 |
-
3.
|
54 |
-
4.
|
55 |
-
5.
|
56 |
-
6. Prepara una risposta chiara e dettagliata.
|
57 |
-
7. Inizia con una breve introduzione, sviluppa l'analisi, esponi le inferenze e concludi con una sintesi.
|
58 |
-
8. Mantieni un tono oggettivo e uno stile fluido e coerente.
|
59 |
-
|
60 |
-
DOCUMENTO:
|
61 |
-
<<<INIZIO_DOCUMENTO>>>
|
62 |
-
${a}
|
63 |
-
<<<FINE_DOCUMENTO>>>
|
64 |
-
|
65 |
-
DOMANDA:
|
66 |
-
${b}
|
67 |
-
|
68 |
-
OUTPUT_FORMAT:
|
69 |
-
La risposta dovr\u00e0 essere strutturata nel seguente modo:
|
70 |
-
- Introduzione:
|
71 |
-
- Concetti chiave:
|
72 |
-
- Citazioni:
|
73 |
-
- Inferenze:
|
74 |
-
- Dettagli rilevanti:
|
75 |
-
- Sintesi:
|
76 |
-
|
77 |
-
RESPONSE:
|
78 |
-
`}function promptBuildContext(a,b){return`
|
79 |
-
SYSTEM: Sei un assitente AI specializzato nella riorganizzazione di informazioni come contesto nelle interrogazioni ad un LLM. Rispondi ESCLUSIVAMENTE in italiano. Non usare altre lingue in nessuna parte della risposta.
|
80 |
-
|
81 |
-
TASK: Analizza e riorganizza le informazioi rilevanti per rispondere alla domada fornite seguendo le istruzioni.
|
82 |
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
<<<INIZIO_INFORMAZIONI>>>
|
98 |
${a}
|
99 |
<<<FINE_INFORMAZIONI>>>
|
100 |
|
101 |
-
|
102 |
-
|
|
|
|
|
|
|
103 |
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
- Citazioni:
|
109 |
-
- Inferenze:
|
110 |
-
- Connessioni fra contenuti:
|
111 |
-
- Dettagli rilevanti:
|
112 |
-
- Sintesi:
|
113 |
|
114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
`}function promptWithContext(a,b){return`
|
116 |
-
SYSTEM: Sei un sistema AI specializzato nell'analisi
|
117 |
|
118 |
-
TASK: Elabora la risposta alla domanda sulla base del contesto fornito.
|
119 |
|
120 |
INSTRUCTIONS:
|
121 |
-
1. Analizza attentamente il contesto
|
122 |
-
2. Estrai i concetti chiave e
|
123 |
-
3.
|
124 |
-
4.
|
125 |
-
5.
|
126 |
-
6.
|
|
|
|
|
127 |
|
128 |
CONTESTO:
|
129 |
<<<INIZIO_CONTESTO>>>
|
130 |
${a}
|
131 |
<<<FINE_CONTESTO>>>
|
132 |
|
133 |
-
DOMANDA:
|
134 |
-
${b}
|
135 |
|
136 |
-
OUTPUT_FORMAT:
|
137 |
-
Rispondi con un testo piano suddiviso in paragrafi.Evita di usare etichette, elenchi o marcatori speciali.
|
138 |
|
139 |
RESPONSE:
|
140 |
`}function promptThread(a,b,c){return`
|
141 |
SYSTEM: Sei un assistente AI versatile progettato per gestire conversazioni dinamiche e adattarti a varie richieste. Rispondi sempre in italiano.
|
142 |
|
143 |
-
TASK: Elabora la risposta alla richiesta sulla base del contesto fornito e della conversazione.
|
144 |
|
145 |
INSTRUCTIONS:
|
146 |
-
1. Analizza attentamente il contesto, la conversazione precedente e la richiesta
|
147 |
2. Interpreta l'intento dell'utente senza limitarti a categorie predefinite.
|
148 |
3. Adatta la tua risposta in base all'intento percepito, sia esso una domanda, una richiesta di azione, un'istruzione specifica o altro.
|
149 |
4. Mantieni una stretta coerenza con il contesto della conversazione.
|
150 |
-
5. Basa la tua risposta
|
151 |
6. Evita divagazioni o argomentazioni non direttamente pertinenti alla richiesta o al contesto.
|
152 |
7. Fai riferimento a informazioni precedenti quando sono pertinenti, citando specificamente la fonte.
|
153 |
8. Se l'intento non \u00e8 chiaro, chiedi gentilmente chiarimenti invece di fare supposizioni.
|
@@ -163,17 +163,15 @@ ${a}
|
|
163 |
${b}
|
164 |
<<<FINE_CONVERSAZIONE>>>
|
165 |
|
166 |
-
RICHIESTA:
|
167 |
-
${c}
|
168 |
|
169 |
-
OUTPUT_FORMAT:
|
170 |
-
Rispondi con un testo piano suddiviso in paragrafi.Evita di usare etichette, elenchi o marcatori speciali.
|
171 |
|
172 |
RESPONSE:
|
173 |
-
`}function getPayloadDoc(a){return{inputs:a,parameters:{task:"text2text-generation",max_new_tokens:1024,num_return_sequences:1,temperature:.2,top_p:.85,top_k:30,do_sample:!1,no_repeat_ngram_size:
|
174 |
-
function getPayloadBuildContext(a){return{inputs:a,parameters:{task:"text2text-generation",max_new_tokens:
|
175 |
function getPayloadWithContext(a){return{inputs:a,parameters:{task:"text2text-generation",max_new_tokens:2048,num_return_sequences:1,temperature:.3,top_p:.85,top_k:30,do_sample:!1,no_repeat_ngram_size:4,num_beams:5,repetition_penalty:1.4,return_full_text:!1,details:!1,max_time:120,seed:42},options:{use_cache:!1,wait_for_model:!0}}}
|
176 |
-
function getPayloadThread(a){return{inputs:a,parameters:{task:"text2text-generation",max_new_tokens:2048,num_return_sequences:1,temperature:.3,top_p:.85,top_k:30,do_sample:!1,no_repeat_ngram_size:4,num_beams:5,repetition_penalty:1.4,return_full_text:!1,details:!1,max_time:120,seed:42},options:{use_cache:!1,wait_for_model:!0}}};const VERS="0.1.
|
177 |
function openApp(){setTimeout(()=>{tm=umgm();wnds.init();Menu.init();TextInput.init();TextOutput.init();Rag.init();document.querySelector(".menu-btn").checked=!1;release();showHistory()},10)}function showHistory(){const a=ThreadMgr.getThread();setOutText(a)}function release(){document.querySelector(".release").innerHTML=VERS}const op0=async function(a){a=await requestGet("./help1.html");wnds.wdiv.show(a)};function showQuery(a){wnds.wpre.show(`\n${Rag.ragQuery}`)}
|
178 |
function showRagResponse(a){wnds.wpre.show(`\n${Rag.ragAnswer}`)}function showThread(a){a=ThreadMgr.getThread();wnds.wpre.show(a)}function elencoRisposte(a){a=[...Rag.answers];0==a.length&&(a=UaDb.readArray(ID_RESPONSES));0!=a.length&&(a=a.map((b,c)=>`\n[${c+1}]\n ${b.trim()}`).join("\n"),wnds.wpre.show(a))}function showContesto(a){wnds.wpre.show(`${Rag.ragContext}`)}
|
179 |
function elencoDati(a){var b=UaDb.getAllIds();a=[];for(var c of b)b=UaDb.read(c).length,a.push(`${c} (${b})`);c=a.join("\n ");wnds.wpre.show(c)}const showT=a=>{wnds.wpre.show(DataMgr.docs[a])};function elencoDocs(){DataMgr.readDbDocs();DataMgr.readDbDocNames();var a=DataMgr.doc_names,b=UaJtfh();let c=0;b.append("<ul>");for(const g of a){a=b;var d=a.append,e=g,f=c++;d.call(a,`
|
|
|
1 |
+
function removeTag(a){a=a.replace(/<<</g," ").replace(/>>>/g," ");return a=a.replace(/<</g,"").replace(/>>/g,"")}
|
2 |
+
function cleanDoc(a){try{return a=removeTag(a),a=a.replace(/(\w+)-\s*\n(\w+)/g,"$1$2"),a=a.replace(/[\u00AD\u200B\u200C\u200D\u2060\uFEFF\u0008]/g,""),a=a.replace(/[\u00A0\u2000-\u200A\u202F\u205F\u3000\t\r\f\v]/g," "),a=a.replace(/\\([nrtfb])/g,"$1"),a=a.replace(/\\(u[0-9a-fA-F]{4}|x[0-9a-fA-F]{2})/g,"$1"),a=a.replace(/\\([a-zA-Z]:\\|\\\\[a-zA-Z0-9_]+\\)/g,"\\$1"),a=a.replace(/\\/g,""),a=a.replace("\u201c",'"').replace("\u201d",'"'),a=a.replace(/\n/g," "),a=a.replace(/ +([.,;:!?])/g,"$1"),a=a.split(/(?<=[.?!])\s+/).filter(b=>
|
3 |
+
5<=b.trim().length).map(b=>b.trim()).join("\n"),a=a.replace(/ +/g," "),a.trim()}catch(b){return console.error(b),"Errore di codifica del documento"}}
|
4 |
+
function cleanResponse(a){try{return a=removeTag(a),a=a.replace(/[\u00AD\u200B\u200C\u200D\u2060\uFEFF]/g,""),a=a.replace(/[\u00A0\u2000-\u200A\u202F\u205F\u3000\t\r\f\v]/g," "),a=a.replace(/\\([nrtfb])/g,"$1"),a=a.replace(/\\(u[0-9a-fA-F]{4}|x[0-9a-fA-F]{2})/g,"$1"),a=a.replace(/\\([a-zA-Z]:\\|\\\\[a-zA-Z0-9_]+\\)/g,"\\\\$1"),a=a.replace(/\\/g,""),a=a.replace(/\n{3,}/g,"\n\n"),a=a.replace(/ +/g," "),a.trim()}catch(b){return console.error(b),`Errore di codifica nella risposta\n${b}`}}
|
5 |
function cleanOut(a){return a=a.replace(/\n{3,}/g,"\n\n")};const ID_RESPONSES="id_responses",ID_DOC_NAMES="id_doc_names",ID_DOCS="id_docs;",ID_RAG="id_rag",ID_THREAD="id_thread",UaDb={create(a,b){localStorage.getItem(a)?xerror(`ID ${a} already exists.`):localStorage.setItem(a,b)},read(a){const b=localStorage.getItem(a);return null===b?(xlog(`UaDb.read ${a} not found.`),""):b},update(a,b){localStorage.getItem(a)?localStorage.setItem(a,b):xlog(`UaDb.update ${a} not found.`)},delete(a){localStorage.getItem(a)?localStorage.removeItem(a):xerror(`ID ${a} not found.`)},
|
6 |
save(a,b){localStorage.setItem(a,b)},getAllIds(){const a=[];for(let b=0;b<localStorage.length;b++)a.push(localStorage.key(b));return a},saveArray(a,b){b=JSON.stringify(b);UaDb.save(a,b)},readArray(a){a=UaDb.read(a);return 0==a.trim().length?[]:JSON.parse(a)},saveJson(a,b){b=JSON.stringify(b);UaDb.save(a,b)},readJson(a){return(a=UaDb.read(a))?JSON.parse(a):{}}},DataMgr={docs:[],doc_names:[],linkToName(a){a=a.split("/");return a[a.length-1]},async loadDoc(a){this.readDbDocNames();try{const b=await requestGet(a),
|
7 |
c=cleanDoc(b),d=this.linkToName(a);if(this.doc_names.includes(d))alert(`Il docuento ${d} \u00e8 gi\u00e0 caricato`);else return this.doc_names.push(d),this.docs.push(c),this.saveDbDocs(),c}catch(b){alert("loadDoc()\n"+b+"\n"+a)}},addDoc(a,b){b=cleanDoc(b);this.docs.push(b);this.doc_names.push(a);this.saveDbDocs()},saveDbDocs(){UaDb.saveArray(ID_DOC_NAMES,this.doc_names);UaDb.saveArray(ID_DOCS,this.docs)},readDbDocs(){this.docs=UaDb.readArray(ID_DOCS)},readDbDocNames(){this.doc_names=UaDb.readArray(ID_DOC_NAMES)},
|
|
|
35 |
const truncInput=(a,b)=>a.substring(0,a.length-b),setMaxLen=a=>a.substring(0,MAX_PROMPT_LENGTH-1E3),getPartSize=(a,b,c)=>{c=MAX_PROMPT_LENGTH-c;a.length+b.length<c?c=a.length:(a=a.indexOf(".",c),a=(-1!=a?a:c)+1,a>c+100&&(a=c),c=a);return c},getPartDoc=(a,b)=>{const c=a.substring(0,b);a=a.substring(b).trim();return[c,a]},ragLog=(a,b,c,d)=>{const e=MAX_PROMPT_LENGTH;d=d.reduce((f,g)=>f+g.length,0);xlog(`${a} mx:${e} lft:${b} rgt:${c} arr:${d}`);a=formatRow([a,b,c,d],[8,-7,-7,-7]);UaLog.log(a)},Rag=
|
36 |
{ragContext:"",ragQuery:"",ragAnswer:"",answers:[],docContextLst:[],prompts:[],doc:"",doc_part:"",init(){this.readRespsFromDb();this.readFromDb()},returnOk(){return 10<this.ragContext.length},saveToDb(){UaDb.saveJson(ID_RAG,{context:this.ragContext,ragquery:this.ragQuery,raganswer:this.ragAnswer});UaDb.saveArray(ID_THREAD,ThreadMgr.rows)},readFromDb(){const a=UaDb.readJson(ID_RAG);this.ragContext=a.context||"";this.ragQuery=a.ragquery||"";this.ragAnswer=a.raganswer||"";ThreadMgr.rows=UaDb.readArray(ID_THREAD)},
|
37 |
saveRespToDb(){UaDb.saveArray(ID_RESPONSES,this.answers)},readRespsFromDb(){this.answers=UaDb.readArray(ID_RESPONSES)},async requestDocsRAG(a){DataMgr.deleteJsonDati();DataMgr.readDbDocNames();DataMgr.readDbDocs();this.ragQuery=a;this.saveToDb();var b=0;try{var c=1;for(let e=0;e<DataMgr.docs.length;e++){let f=DataMgr.docs[e];if(""==f.trim())continue;const g=DataMgr.doc_names[e],k=f.length;xlog(`${g} (${k}) `);UaLog.log(`${g} (${k}) `);++b;var d=1;let h=0,l="",t="",u="",m="",v=[];for(;;){let r=getPartSize(f,
|
38 |
+
promptDoc("",a,""),h);if(10>r)break;[t,u]=getPartDoc(f,r);ragLog(`${c}) ${b},${d}`,t.length,u.length,this.answers);l=promptDoc(t,a,g);const p=getPayloadDoc(l);try{if(m=await HfRequest.post(p,TIMEOUT),!m)return""}catch(n){console.error("RR1)\n",n);const w=getErrorInfo(n);if(w.errorType===ERROR_TOKENS){UaLog.log(`Error tokens Doc ${l.length}`);h+=PROMPT_DECR;continue}else if(w.errorType===TIMEOUT_ERROR){UaLog.log("Error timeout Doc");continue}else throw n;}d++;c++;f=u;m=cleanResponse(m);v.push(m);
|
39 |
+
this.answers.push(`DOCUMENTO : ${g}_${d}\n${m}`)}const x=v.length;let q=v.join("\n\n");for(d="";;){l=promptBuildContext(q,this.ragQuery);const r=getPayloadBuildContext(l);try{if(d=await HfRequest.post(r,TIMEOUT),!d)return""}catch(p){console.error("RR2)",p);const n=getErrorInfo(p);if(n.errorType===ERROR_TOKENS){UaLog.log(`Error tokens build Context ${l.length}`);q=truncInput(q,PROMPT_DECR);q=setMaxLen(q);continue}else if(n.errorType===TIMEOUT_ERROR){UaLog.log("Error timeout build Context");continue}else throw p;
|
40 |
+
}break}UaLog.log(`context ${x} => ${d.length}`);d=`\n### DOCUMENTO: ${g}\n ${d}`;this.docContextLst.push(d)}}catch(e){throw console.error(e),e;}this.ragContext=this.docContextLst.join("\n\n");this.saveToDb();b="";c=this.ragContext;try{for(;;){let e=promptWithContext(c,a);const f=getPayloadWithContext(e);try{if(b=await HfRequest.post(f,TIMEOUT),!b)return""}catch(g){console.error("RR3)",g);const k=getErrorInfo(g);if(k.errorType===ERROR_TOKENS){UaLog.log(`Error tokens with Context ${e.length}`);c=truncInput(c,
|
41 |
+
PROMPT_DECR);c=setMaxLen(c);continue}else if(k.errorType===TIMEOUT_ERROR){UaLog.log("Error timeout with Context");continue}else throw g;}break}this.ragAnswer=b=cleanResponse(b);this.saveRespToDb();ThreadMgr.init();this.saveToDb();UaLog.log(`Risposta (${this.ragAnswer.length})`)}catch(e){throw console.error(e),b=`${e}`,e;}finally{return b}},async requestContext(a){let b="";if(!this.ragContext&&!await confirm("Contesto vuoto. Vuoi continuare?"))return"";if(ThreadMgr.isFirst()){ThreadMgr.init();try{var c=
|
42 |
+
this.ragContext;let d=ThreadMgr.getThread();for(;;){prompt=promptThread(c,d,a);const e=getPayloadThread(prompt);try{if(b=await HfRequest.post(e,TIMEOUT),!b)return""}catch(f){console.error("RR4)",f);const g=getErrorInfo(f);if(g.errorType===ERROR_TOKENS){UaLog.log(`Error tokens Thread Init ${prompt.length}`);d=truncInput(d,PROMPT_DECR);c=setMaxLen(c);continue}else if(g.errorType===TIMEOUT_ERROR){UaLog.log("Error timeout Thread Init");continue}else throw f;}break}b=cleanResponse(b);ThreadMgr.add(a,b);
|
43 |
+
b=ThreadMgr.getThread();UaLog.log(`Inizio Conversazione (${prompt.length})`)}catch(d){throw console.error(d),b=`${d}`,d;}finally{return b}}else try{let d=this.ragContext,e=ThreadMgr.getThread();for(c="";;){c=promptThread(d,e,a);const f=getPayloadThread(c);try{if(b=await HfRequest.post(f,TIMEOUT),!b)return""}catch(g){console.error("RR5)",g);const k=getErrorInfo(g);if(k.errorType===ERROR_TOKENS){UaLog.log(`Error tokens Thread ${c.length}`);e=truncInput(e,PROMPT_DECR);continue}else if(k.errorType===
|
44 |
TIMEOUT_ERROR){UaLog.log("Error timeout Thread");continue}else throw g;}break}b=cleanResponse(b);ThreadMgr.add(a,b);b=ThreadMgr.getThread();UaLog.log(`Conversazione (${c.length})`)}catch(d){throw console.error(d),b=`${d}`,d;}finally{return b}}},LLM="## Assistant:",USER="## User:",ThreadMgr={rows:[],init(){this.rows=[];Rag.ragAnswer?this.add(Rag.ragQuery,Rag.ragAnswer):this.add("","")},add(a,b){this.rows.push([a,b]);UaDb.saveArray(ID_THREAD,ThreadMgr.rows)},getThread(){const a=[];for(const b of this.rows)a.push(`${USER}\n${b[0]}\n${LLM}\n${b[1]}\n`);
|
45 |
return a.join("\n\n")},isFirst(){return 2>this.rows.length}};function promptDoc(a,b,c){return`
|
46 |
+
RUOLO: Sei un assistente AI specializzato nell'analisi documentale e nell'estrazione mirata di informazioni. Rispondi esclusivamente in italiano.
|
47 |
|
48 |
+
COMPITO: Analizza l'estratto del documento "${c}" e identifica le informazioni rilevanti per rispondere alla domanda: "${b}".
|
49 |
|
50 |
+
ISTRUZIONI:
|
51 |
+
1. Esamina il testo e identifica le informazioni utili per costruire un contesto relativo alla domanda.
|
52 |
+
2. Per ogni informazione rilevante, fornisci una breve descrizione.
|
53 |
+
3. Elenca i punti chiave pertinenti per ogni informazione.
|
54 |
+
4. Riporta elementi specifici (dati, citazioni, eventi) se utili per il contesto.
|
55 |
+
5. Struttura la risposta secondo il formato di output specificato.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
+
TESTO DA ANALIZZARE:
|
58 |
+
<<<INIZIO_TESTO>>>
|
59 |
+
${a}
|
60 |
+
<<<FINE_TESTO>>>
|
61 |
+
|
62 |
+
FORMATO DI OUTPUT:
|
63 |
+
- Informazione 1:
|
64 |
+
Descrizione:
|
65 |
+
Punti chiave:
|
66 |
+
Elementi specifici:
|
67 |
+
|
68 |
+
- Informazione 2:
|
69 |
+
Descrizione:
|
70 |
+
Punti chiave:
|
71 |
+
Elementi specifici:
|
72 |
+
|
73 |
+
(Ripeti il formato per ogni informazione identificata)
|
74 |
+
|
75 |
+
RISPOSTA:
|
76 |
+
`}function promptBuildContext(a,b=""){return`
|
77 |
+
RUOLO: Sei un assistente AI esperto nella sintesi e nell'organizzazione mirata di informazioni. Rispondi sempre ed esclusivamente in italiano.
|
78 |
+
|
79 |
+
COMPITO: Organizza e sintetizza le informazioni estratte da frammenti di testo di un documento, creando un contesto utile per rispondere alla domanda: "${b}".
|
80 |
+
|
81 |
+
ISTRUZIONI:
|
82 |
+
1. Esamina tutte le informazioni fornite.
|
83 |
+
2. Seleziona e raggruppa le informazioni pertinenti alla domanda.
|
84 |
+
3. Per ogni gruppo di informazioni rilevanti, genera una descrizione concisa.
|
85 |
+
4. Elenca i punti chiave essenziali per comprendere il contesto.
|
86 |
+
5. Riporta elementi specifici (dati, citazioni, eventi) se utili.
|
87 |
+
6. Elimina le informazioni ridondanti, mantenendo solo la versione pi\u00f9 completa.
|
88 |
+
7. Elabora inferenze logiche basate sulle informazioni, se rilevanti per il contesto.
|
89 |
+
8. Genera una sintesi finale del contesto.
|
90 |
+
9. Struttura la risposta secondo il formato di output specificato.
|
91 |
+
|
92 |
+
INFORMAZIONI:
|
93 |
<<<INIZIO_INFORMAZIONI>>>
|
94 |
${a}
|
95 |
<<<FINE_INFORMAZIONI>>>
|
96 |
|
97 |
+
FORMATO DI OUTPUT:
|
98 |
+
- Informazioni 1:
|
99 |
+
Descrizione:
|
100 |
+
Punti chiave:
|
101 |
+
Elementi rilevanti:
|
102 |
|
103 |
+
- Informazioni 2:
|
104 |
+
Descrizione:
|
105 |
+
Punti chiave:
|
106 |
+
Elementi rilevanti:
|
|
|
|
|
|
|
|
|
|
|
107 |
|
108 |
+
(Ripeti il formato per ogni gruppo di informazioni
|
109 |
+
|
110 |
+
- Inferenze Logiche:
|
111 |
+
|
112 |
+
- Sintesi Finale:
|
113 |
+
|
114 |
+
RISPOSTA:
|
115 |
`}function promptWithContext(a,b){return`
|
116 |
+
SYSTEM: Sei un sistema AI specializzato nell'analisi di informazioni estratte da documenti.
|
117 |
|
118 |
+
TASK: Elabora la risposta alla domanda "${b}" sulla base del contesto fornito.
|
119 |
|
120 |
INSTRUCTIONS:
|
121 |
+
1. Analizza attentamente il contesto fornito, identificando le informazioni pertinenti alla domanda: "${b}".
|
122 |
+
2. Estrai i concetti chiave e formula inferenze ragionevoli basate sulle informazioni disponibili.
|
123 |
+
3. Inizia la risposta con una breve introduzione che presenta l'argomento e il contesto.
|
124 |
+
4. Procedi con un'analisi dettagliata delle informazioni rilevanti trovate nel contesto.
|
125 |
+
5. Concludi con una sintesi che riassume i punti chiave e fornisce una conclusione generale.
|
126 |
+
6. Se richiesto, cita le fonti facendo riferimento al "documento fornito" per il contesto dato, distinguendolo chiaramente da eventuali altre fonti citate all'interno del contesto stesso.
|
127 |
+
7. Mantieni uno stile di scrittura fluido durante tutta la risposta.
|
128 |
+
8. Assicurati che la risposta sia completa e risponda direttamente alla domanda posta.
|
129 |
|
130 |
CONTESTO:
|
131 |
<<<INIZIO_CONTESTO>>>
|
132 |
${a}
|
133 |
<<<FINE_CONTESTO>>>
|
134 |
|
135 |
+
DOMANDA: ${b}
|
|
|
136 |
|
137 |
+
OUTPUT_FORMAT: Fornisci la risposta in testo semplice e lineare suddiviso in paragrafi.
|
|
|
138 |
|
139 |
RESPONSE:
|
140 |
`}function promptThread(a,b,c){return`
|
141 |
SYSTEM: Sei un assistente AI versatile progettato per gestire conversazioni dinamiche e adattarti a varie richieste. Rispondi sempre in italiano.
|
142 |
|
143 |
+
TASK: Elabora la risposta alla richiesta "${c}" sulla base del contesto fornito e della conversazione.
|
144 |
|
145 |
INSTRUCTIONS:
|
146 |
+
1. Analizza attentamente il contesto, la conversazione precedente e la richiesta: "${c}".
|
147 |
2. Interpreta l'intento dell'utente senza limitarti a categorie predefinite.
|
148 |
3. Adatta la tua risposta in base all'intento percepito, sia esso una domanda, una richiesta di azione, un'istruzione specifica o altro.
|
149 |
4. Mantieni una stretta coerenza con il contesto della conversazione.
|
150 |
+
5. Basa la tua risposta sulle informazioni fornite nel contesto e nella conversazione.
|
151 |
6. Evita divagazioni o argomentazioni non direttamente pertinenti alla richiesta o al contesto.
|
152 |
7. Fai riferimento a informazioni precedenti quando sono pertinenti, citando specificamente la fonte.
|
153 |
8. Se l'intento non \u00e8 chiaro, chiedi gentilmente chiarimenti invece di fare supposizioni.
|
|
|
163 |
${b}
|
164 |
<<<FINE_CONVERSAZIONE>>>
|
165 |
|
166 |
+
RICHIESTA: ${c}
|
|
|
167 |
|
168 |
+
OUTPUT_FORMAT: Fornisci la risposta in testo semplice e lineare suddiviso in paragrafi.
|
|
|
169 |
|
170 |
RESPONSE:
|
171 |
+
`}function getPayloadDoc(a){return{inputs:a,parameters:{task:"text2text-generation",max_new_tokens:1024,min_length:200,num_return_sequences:1,temperature:.2,top_p:.85,top_k:30,do_sample:!1,no_repeat_ngram_size:3,num_beams:4,repetition_penalty:1.5,return_full_text:!1,details:!1,max_time:90,seed:42},options:{use_cache:!1,wait_for_model:!0}}}
|
172 |
+
function getPayloadBuildContext(a){return{inputs:a,parameters:{task:"text2text-generation",max_new_tokens:5E3,min_length:400,num_return_sequences:1,temperature:.7,top_p:.85,top_k:30,do_sample:!1,no_repeat_ngram_size:4,num_beams:6,repetition_penalty:1.4,return_full_text:!1,details:!1,max_time:180,seed:42},options:{use_cache:!1,wait_for_model:!0}}}
|
173 |
function getPayloadWithContext(a){return{inputs:a,parameters:{task:"text2text-generation",max_new_tokens:2048,num_return_sequences:1,temperature:.3,top_p:.85,top_k:30,do_sample:!1,no_repeat_ngram_size:4,num_beams:5,repetition_penalty:1.4,return_full_text:!1,details:!1,max_time:120,seed:42},options:{use_cache:!1,wait_for_model:!0}}}
|
174 |
+
function getPayloadThread(a){return{inputs:a,parameters:{task:"text2text-generation",max_new_tokens:2048,num_return_sequences:1,temperature:.3,top_p:.85,top_k:30,do_sample:!1,no_repeat_ngram_size:4,num_beams:5,repetition_penalty:1.4,return_full_text:!1,details:!1,max_time:120,seed:42},options:{use_cache:!1,wait_for_model:!0}}};const VERS="0.1.50 (14-09-2024)";var xlog=console.log,xerror=console.error;const cancelRequest=()=>{confirm("Confermi Cancellazione Richeista ?")&&(HfRequest.cancelRequest(),hideSpinner())},showSpinner=()=>{const a=document.getElementById("spinner");a.classList.add("show-spinner");a.addEventListener("click",cancelRequest)},hideSpinner=()=>{const a=document.getElementById("spinner");a.classList.remove("show-spinner");a.removeEventListener("click",cancelRequest)};var tm;
|
175 |
function openApp(){setTimeout(()=>{tm=umgm();wnds.init();Menu.init();TextInput.init();TextOutput.init();Rag.init();document.querySelector(".menu-btn").checked=!1;release();showHistory()},10)}function showHistory(){const a=ThreadMgr.getThread();setOutText(a)}function release(){document.querySelector(".release").innerHTML=VERS}const op0=async function(a){a=await requestGet("./help1.html");wnds.wdiv.show(a)};function showQuery(a){wnds.wpre.show(`\n${Rag.ragQuery}`)}
|
176 |
function showRagResponse(a){wnds.wpre.show(`\n${Rag.ragAnswer}`)}function showThread(a){a=ThreadMgr.getThread();wnds.wpre.show(a)}function elencoRisposte(a){a=[...Rag.answers];0==a.length&&(a=UaDb.readArray(ID_RESPONSES));0!=a.length&&(a=a.map((b,c)=>`\n[${c+1}]\n ${b.trim()}`).join("\n"),wnds.wpre.show(a))}function showContesto(a){wnds.wpre.show(`${Rag.ragContext}`)}
|
177 |
function elencoDati(a){var b=UaDb.getAllIds();a=[];for(var c of b)b=UaDb.read(c).length,a.push(`${c} (${b})`);c=a.join("\n ");wnds.wpre.show(c)}const showT=a=>{wnds.wpre.show(DataMgr.docs[a])};function elencoDocs(){DataMgr.readDbDocs();DataMgr.readDbDocNames();var a=DataMgr.doc_names,b=UaJtfh();let c=0;b.append("<ul>");for(const g of a){a=b;var d=a.append,e=g,f=c++;d.call(a,`
|