Upload folder using huggingface_hub
Browse files- static/javascript/rag_http.js +2 -0
- static/javascript/rag_rqs.js +25 -13
- static/javascript/rag_ui.js +28 -14
- static/js/ragrqs.min.js +11 -11
- static/ragrqs.html +1 -0
- static/ragrqs_.html +1 -0
static/javascript/rag_http.js
CHANGED
@@ -121,6 +121,7 @@ const HfRequest = {
|
|
121 |
throw error;
|
122 |
}
|
123 |
},
|
|
|
124 |
cancelRequest() {
|
125 |
if (this.controller) {
|
126 |
this.isCancelled = true;
|
@@ -164,3 +165,4 @@ function errorToText(err) {
|
|
164 |
return s;
|
165 |
}
|
166 |
}
|
|
|
|
121 |
throw error;
|
122 |
}
|
123 |
},
|
124 |
+
|
125 |
cancelRequest() {
|
126 |
if (this.controller) {
|
127 |
this.isCancelled = true;
|
|
|
165 |
return s;
|
166 |
}
|
167 |
}
|
168 |
+
|
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;
|
@@ -69,14 +69,28 @@ const hideSpinner = () => {
|
|
69 |
var tm;
|
70 |
|
71 |
function openApp() {
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
}
|
81 |
|
82 |
function release() {
|
@@ -120,7 +134,7 @@ function elencoRisposte(e) {
|
|
120 |
// x = subResponseDOcTag(x);
|
121 |
return `\n[${i + 1}]\n ${x.trim()}`;
|
122 |
})
|
123 |
-
.join("\n");
|
124 |
wnds.wpre.show(text);
|
125 |
}
|
126 |
|
@@ -155,7 +169,7 @@ function elencoDocs() {
|
|
155 |
DataMgr.readDbDocs();
|
156 |
DataMgr.readDbDocNames();
|
157 |
const arr = DataMgr.doc_names;
|
158 |
-
const fh = (x,i) => `
|
159 |
<li><a href="#" onCLick="showT(${i});">${i + 1}.${x}</a></li>
|
160 |
`;
|
161 |
const jfh = UaJtfh();
|
@@ -194,7 +208,6 @@ function calcQuery() {
|
|
194 |
wnds.wpre.show(s);
|
195 |
}
|
196 |
|
197 |
-
|
198 |
//cancella dati
|
199 |
function deleteDati(e) {
|
200 |
const ok = confirm("Confermi cancellazione dati?");
|
@@ -252,4 +265,3 @@ function showPrompts(e) {
|
|
252 |
.join("\n");
|
253 |
wnds.wpre.show(text);
|
254 |
}
|
255 |
-
|
|
|
19 |
*/
|
20 |
|
21 |
"use strict";
|
22 |
+
const VERS = "0.1.49 (27-08-2024)";
|
23 |
|
24 |
var xlog = console.log;
|
25 |
var xerror = console.error;
|
|
|
69 |
var tm;
|
70 |
|
71 |
function openApp() {
|
72 |
+
setTimeout(() => {
|
73 |
+
tm = umgm();
|
74 |
+
wnds.init();
|
75 |
+
Menu.init();
|
76 |
+
TextInput.init();
|
77 |
+
TextOutput.init();
|
78 |
+
Rag.init();
|
79 |
+
document.querySelector(".menu-btn").checked = false;
|
80 |
+
release();
|
81 |
+
showHistory();
|
82 |
+
}, 10);
|
83 |
+
}
|
84 |
+
|
85 |
+
// Visualizza la storia della conversazione
|
86 |
+
function showHistory() {
|
87 |
+
const txt = ThreadMgr.getThread();
|
88 |
+
setOutText(txt);
|
89 |
+
// const p = document.querySelector("#id-text-out .pre-text");
|
90 |
+
// p.textContent = txt;
|
91 |
+
// setTimeout(() => {
|
92 |
+
// p.scrollTop = p.scrollHeight;
|
93 |
+
// }, 0);
|
94 |
}
|
95 |
|
96 |
function release() {
|
|
|
134 |
// x = subResponseDOcTag(x);
|
135 |
return `\n[${i + 1}]\n ${x.trim()}`;
|
136 |
})
|
137 |
+
.join("\n");
|
138 |
wnds.wpre.show(text);
|
139 |
}
|
140 |
|
|
|
169 |
DataMgr.readDbDocs();
|
170 |
DataMgr.readDbDocNames();
|
171 |
const arr = DataMgr.doc_names;
|
172 |
+
const fh = (x, i) => `
|
173 |
<li><a href="#" onCLick="showT(${i});">${i + 1}.${x}</a></li>
|
174 |
`;
|
175 |
const jfh = UaJtfh();
|
|
|
208 |
wnds.wpre.show(s);
|
209 |
}
|
210 |
|
|
|
211 |
//cancella dati
|
212 |
function deleteDati(e) {
|
213 |
const ok = confirm("Confermi cancellazione dati?");
|
|
|
265 |
.join("\n");
|
266 |
wnds.wpre.show(text);
|
267 |
}
|
|
static/javascript/rag_ui.js
CHANGED
@@ -174,6 +174,27 @@ const Menu = {
|
|
174 |
},
|
175 |
};
|
176 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
const TextInput = {
|
178 |
wnd: null,
|
179 |
init() {
|
@@ -276,7 +297,9 @@ const TextInput = {
|
|
276 |
return;
|
277 |
}
|
278 |
showSpinner();
|
279 |
-
if (ThreadMgr.isFirst())
|
|
|
|
|
280 |
const query = this.inp.value.trim();
|
281 |
try {
|
282 |
let text = await Rag.requestContext(query);
|
@@ -304,14 +327,6 @@ const TextInput = {
|
|
304 |
},
|
305 |
};
|
306 |
|
307 |
-
const setOutText = (txt) => {
|
308 |
-
let out = document.getElementById("id-text-out");
|
309 |
-
const h = `<pre class="pre-text"></pre>`;
|
310 |
-
out.innerHTML = h;
|
311 |
-
const pre = out.querySelector(".pre-text");
|
312 |
-
pre.textContent = txt;
|
313 |
-
pre.scrollTop = pre.scrollHeight;
|
314 |
-
};
|
315 |
|
316 |
TextOutput = {
|
317 |
init() {
|
@@ -323,15 +338,14 @@ TextOutput = {
|
|
323 |
wndBtn.addEventListener("click", () => this.openWnd());
|
324 |
},
|
325 |
openWnd() {
|
326 |
-
const p = document.
|
327 |
const s = p.textContent;
|
328 |
wnds.wout.show(s);
|
329 |
},
|
330 |
async copy() {
|
331 |
-
const
|
332 |
-
const pre = e.querySelector("pre");
|
333 |
-
if (!pre) return;
|
334 |
const t = pre.textContent;
|
|
|
335 |
pre.classList.add("copied");
|
336 |
this.copyBtn.classList.add("copied");
|
337 |
try {
|
@@ -345,7 +359,7 @@ TextOutput = {
|
|
345 |
}, 5000);
|
346 |
},
|
347 |
clear() {
|
348 |
-
const out = document.
|
349 |
out.textContent = "";
|
350 |
},
|
351 |
};
|
|
|
174 |
},
|
175 |
};
|
176 |
|
177 |
+
const setOutText = (txt) => {
|
178 |
+
const p = document.querySelector("#id-text-out .pre-text");
|
179 |
+
p.textContent = txt;
|
180 |
+
p.scrollTop = p.scrollHeight;
|
181 |
+
};
|
182 |
+
|
183 |
+
// const setOutText2 = async (txt) => {
|
184 |
+
// const t = p.textContent;
|
185 |
+
// if (t.trim().length < 2) {
|
186 |
+
// p.textContent = txt;
|
187 |
+
// p.scrollTop = p.scrollHeight;
|
188 |
+
// return;
|
189 |
+
// }
|
190 |
+
// for (let i = 0; i < txt.length; i++) {
|
191 |
+
// p.textContent += txt[i];
|
192 |
+
// p.scrollTop = p.scrollHeight;
|
193 |
+
// await new Promise((resolve) => setTimeout(resolve, 2));
|
194 |
+
// }
|
195 |
+
// };
|
196 |
+
|
197 |
+
|
198 |
const TextInput = {
|
199 |
wnd: null,
|
200 |
init() {
|
|
|
297 |
return;
|
298 |
}
|
299 |
showSpinner();
|
300 |
+
if (ThreadMgr.isFirst()) {
|
301 |
+
setOutText("");
|
302 |
+
}
|
303 |
const query = this.inp.value.trim();
|
304 |
try {
|
305 |
let text = await Rag.requestContext(query);
|
|
|
327 |
},
|
328 |
};
|
329 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
330 |
|
331 |
TextOutput = {
|
332 |
init() {
|
|
|
338 |
wndBtn.addEventListener("click", () => this.openWnd());
|
339 |
},
|
340 |
openWnd() {
|
341 |
+
const p = document.querySelector("#id-text-out .pre-text");
|
342 |
const s = p.textContent;
|
343 |
wnds.wout.show(s);
|
344 |
},
|
345 |
async copy() {
|
346 |
+
const pre = document.querySelector("#id-text-out .pre-text");
|
|
|
|
|
347 |
const t = pre.textContent;
|
348 |
+
if (t.trim().length < 2) return;
|
349 |
pre.classList.add("copied");
|
350 |
this.copyBtn.classList.add("copied");
|
351 |
try {
|
|
|
359 |
}, 5000);
|
360 |
},
|
361 |
clear() {
|
362 |
+
const out = document.querySelector("#id-text-out .pre-text");
|
363 |
out.textContent = "";
|
364 |
},
|
365 |
};
|
static/js/ragrqs.min.js
CHANGED
@@ -176,10 +176,10 @@ RESPONSE:
|
|
176 |
`}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:4,num_beams:4,repetition_penalty:1.4,return_full_text:!1,details:!1,max_time:90,seed:42},options:{use_cache:!1,wait_for_model:!0}}}
|
177 |
function getPayloadBuildContext(a){return{inputs:a,parameters:{task:"text2text-generation",max_new_tokens:6E3,num_return_sequences:1,temperature:.2,top_p:.85,top_k:30,do_sample:!1,no_repeat_ngram_size:4,num_beams:4,repetition_penalty:1.2,return_full_text:!1,details:!1,max_time:180,seed:42},options:{use_cache:!1,wait_for_model:!0}}}
|
178 |
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}}}
|
179 |
-
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.
|
180 |
-
function openApp(){tm=umgm();wnds.init();Menu.init();TextInput.init();TextOutput.init();Rag.init();document.querySelector(".menu-btn").checked=!1;release()}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}`)}
|
181 |
-
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}`)}
|
182 |
-
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,`
|
183 |
<li><a href="#" onCLick="showT(${f});">${f+1}.${e}</a></li>
|
184 |
`)}b.append("</ul>");b=b.html();wnds.wdiv.show(`<br><br>${b}`)}function calcQuery(){DataMgr.readDbDocs();DataMgr.readDbDocNames();var a=[];let b=0,c=0;a.push("Documento Num.Parti");a.push("==================");for(const d of DataMgr.docs){const e=DataMgr.doc_names[c];c+=1;const f=Math.ceil(d.length/MAX_PROMPT_LENGTH);b+=f;a.push(`${e} [${f}]`)}a.push("==================");a.push(`Totale num. Parti: ${b}`);a=a.join("\n");wnds.wpre.show(a)}
|
185 |
function deleteDati(a){confirm("Confermi cancellazione dati?")&&(DataMgr.deleteJsonDati(),wnds.wdiv.close(),wnds.wpre.close(),TextOutput.clear())}function deleteSttorage(a){confirm("Confermi cancellazione documenti & dati?")&&(DataMgr.deleteJsonDati(),localStorage.clear(),wnds.wdiv.close(),wnds.wpre.close(),TextOutput.clear(),DataMgr.docs=[],DataMgr.doc_names=[])}async function help1(a){a=await requestGet("./data/help_test.html");wnds.wdiv.show(a)}
|
@@ -209,13 +209,13 @@ function loadTestoEsempio(a){DataMgr.loadDoc(`data/${a}`);wnds.wdiv.close()}asyn
|
|
209 |
</div>
|
210 |
`;this.w.drag();this.w.setZ(12);this.w.vw_vh().setXY(16.5,10,-1);this.w.setHtml(b);this.w.show();this.w.getElement().querySelector(".btn-copy").addEventListener("click",()=>this.copy())},close(){this.w.close()},async copy(){const b=this.w.getElement().querySelector(".div-text").textContent;try{await navigator.clipboard.writeText(b)}catch(c){console.error("Errore ",c)}}}),wnds={wdiv:null,wpre:null,wout:null,init(){this.wdiv=WndDiv("id_w0");this.wpre=WndPre("id_w1");this.wout=WndPre("id_out")},
|
211 |
closeAll(){UaWindowAdm.close("id_w0");UaWindowAdm.close("id_w1");UaWindowAdm.close("id_out")}},Menu={init(){const a=document.querySelector("#id-menu-btn");a.addEventListener("change",()=>{document.querySelector("body").classList.toggle("menu-open",a.checked)});const b=document.getElementById("id_log");UaLog.callHide=()=>{b.classList.contains("active")&&b.classList.remove("active")};UaLog.callShow=()=>{b.classList.contains("active")||b.classList.add("active")};UaLog.setXY(54,13).setZ(111).new();UaLog.log_show("")},
|
212 |
-
close(){const a=document.querySelector("#menu-toggle");document.querySelector("body").classList.remove("menu-open",a.checked);document.querySelector(".menu-btn").checked=!1},async help(){const a=await requestGet("./help0.html");wnds.wdiv.show(a)},upload(){RagUpload.open()},uploadDir(){RagUpload.openDir()},async load(){alert("load")},log(){UaLog.toggle()}},
|
213 |
-
("F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 Control Alt Shift Meta CapsLock Escape PrintScreen ScrollLock Pause Insert Delete Home End PageUp PageDown ArrowLeft ArrowRight ArrowUp ArrowDown".split(" ").includes(a.key)||a.ctrlKey||a.metaKey||a.preventDefault())});document.querySelector(".clear-button").addEventListener("click",()=>{this.inp.value="";this.inp.focus()});this.inp.addEventListener("keydown",
|
214 |
-
document.querySelector(".send2-input").addEventListener("click",()=>this.send2());document.querySelector(".clear-input").addEventListener("click",()=>this.clear())},handleEnter(a){"Enter"===a.key&&!a.shiftKey&&Rag.returnOk()&&(a.preventDefault(),this.send2())},async send(){if(this.inp.value){if(Rag.ragContext&&!confirm("Vuoi iniziare una nuova elabrazione ?"))return"";showSpinner();setOutText("");
|
215 |
-
"";UaLog.close()}catch(b){a=`send\n${b}`,console.error(a),alert(a),setOutText(a)}hideSpinner()}else alert("Ricorda di scrivere la Query ")},async send2(){if(this.inp.value){showSpinner();ThreadMgr.isFirst()&&setOutText("");var a=this.inp.value.trim();try{let b=await Rag.requestContext(a);if(""==b){hideSpinner();return}b=cleanOut(b);setOutText(b);this.inp.value=""}catch(b){a=`send2\n${b}`,
|
216 |
-
(
|
217 |
-
TextOutput={init(){this.copyBtn=document.querySelector(".copy-output");this.copyBtn.addEventListener("click",()=>this.copy());document.querySelector(".clear-output").addEventListener("click",()=>this.clear());document.querySelector(".wnd-output").addEventListener("click",()=>this.openWnd())},openWnd(){const a=document.
|
218 |
-
this.copyBtn.classList.add("copied");try{await navigator.clipboard.writeText(b)}catch(c){console.error("Errore ",c)}setTimeout(()=>{this.copyBtn.classList.remove("copied");a.classList.remove("copied")},5E3)}},clear(){document.
|
219 |
a.show()},async upload(){const a=document.getElementById("id_fileupload").files[0];if(a){var b=a.name;if(DataMgr.doc_names.includes(b))alert("Il file \u00e8 gi\u00e0 in archivio");else{var c=document.getElementById("result"),d=a.name.split(".").pop().toLowerCase();showSpinner();try{let e;if("pdf"===d){const f=new PdfHandler;await f.loadPdfJs();e=await f.extractTextFromPDF(a);f.cleanup()}else if("txt"===d)e=await readTextFile(a);else{alert("Formato file non supportato.");return}DataMgr.addDoc(b,e);
|
220 |
c.innerHTML=`<br><br> ${b}<br><br>caricato e salvato nella memoria locale`}catch(e){xerror("Error:",e),alert("Errore durante l'estrazione del testo dal file.")}finally{hideSpinner()}}}else alert("Nessun file selezionato.")},openDir(){const a=UaWindowAdm.create("id_upload");a.drag();a.setZ(12);a.vw_vh().setXY(16.5,10,-1);a.setHtml('\n <div class="window-text">\n <div class="btn-wrapper">\n <button class="btn-close" title="chiudi" onclick="UaWindowAdm.closeThis(this)">X</button>\n </div> \n <div class="upload"> \n <h4>Upload files Text / PDF</h4> \n <form id="uploadForm">\n <input id="id_fileupload" class="file" type="file" webkitdirectory mozdirectory msdirectory odirectory directory multiple />\n <button type="button" onclick="RagUpload.uploadDir();">Upload and Convert</button>\n </form>\n <div class="result" id="result"></div>\n </div>\n </div>\n ');
|
221 |
a.show()},async uploadDir(){var a=document.getElementById("id_fileupload").files;if(a&&0!=a.length){var b=[];showSpinner();try{for(const c of a){const d=c.name;UaLog.log_show(d);if(DataMgr.doc_names.includes(d)){UaLog.log_shw(d+" : \u00e8 gi\u00e0 in archivio");continue}const e=c.name.split(".").pop().toLowerCase();let f;if("pdf"===e){const g=new PdfHandler;await g.loadPdfJs();f=await g.extractTextFromPDF(c);g.cleanup()}else if("txt"===e)f=await readTextFile(c);else{alert("Formato file non supportato.");
|
|
|
176 |
`}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:4,num_beams:4,repetition_penalty:1.4,return_full_text:!1,details:!1,max_time:90,seed:42},options:{use_cache:!1,wait_for_model:!0}}}
|
177 |
function getPayloadBuildContext(a){return{inputs:a,parameters:{task:"text2text-generation",max_new_tokens:6E3,num_return_sequences:1,temperature:.2,top_p:.85,top_k:30,do_sample:!1,no_repeat_ngram_size:4,num_beams:4,repetition_penalty:1.2,return_full_text:!1,details:!1,max_time:180,seed:42},options:{use_cache:!1,wait_for_model:!0}}}
|
178 |
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}}}
|
179 |
+
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.49 (27-08-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;
|
180 |
+
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}`)}
|
181 |
+
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}`)}
|
182 |
+
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,`
|
183 |
<li><a href="#" onCLick="showT(${f});">${f+1}.${e}</a></li>
|
184 |
`)}b.append("</ul>");b=b.html();wnds.wdiv.show(`<br><br>${b}`)}function calcQuery(){DataMgr.readDbDocs();DataMgr.readDbDocNames();var a=[];let b=0,c=0;a.push("Documento Num.Parti");a.push("==================");for(const d of DataMgr.docs){const e=DataMgr.doc_names[c];c+=1;const f=Math.ceil(d.length/MAX_PROMPT_LENGTH);b+=f;a.push(`${e} [${f}]`)}a.push("==================");a.push(`Totale num. Parti: ${b}`);a=a.join("\n");wnds.wpre.show(a)}
|
185 |
function deleteDati(a){confirm("Confermi cancellazione dati?")&&(DataMgr.deleteJsonDati(),wnds.wdiv.close(),wnds.wpre.close(),TextOutput.clear())}function deleteSttorage(a){confirm("Confermi cancellazione documenti & dati?")&&(DataMgr.deleteJsonDati(),localStorage.clear(),wnds.wdiv.close(),wnds.wpre.close(),TextOutput.clear(),DataMgr.docs=[],DataMgr.doc_names=[])}async function help1(a){a=await requestGet("./data/help_test.html");wnds.wdiv.show(a)}
|
|
|
209 |
</div>
|
210 |
`;this.w.drag();this.w.setZ(12);this.w.vw_vh().setXY(16.5,10,-1);this.w.setHtml(b);this.w.show();this.w.getElement().querySelector(".btn-copy").addEventListener("click",()=>this.copy())},close(){this.w.close()},async copy(){const b=this.w.getElement().querySelector(".div-text").textContent;try{await navigator.clipboard.writeText(b)}catch(c){console.error("Errore ",c)}}}),wnds={wdiv:null,wpre:null,wout:null,init(){this.wdiv=WndDiv("id_w0");this.wpre=WndPre("id_w1");this.wout=WndPre("id_out")},
|
211 |
closeAll(){UaWindowAdm.close("id_w0");UaWindowAdm.close("id_w1");UaWindowAdm.close("id_out")}},Menu={init(){const a=document.querySelector("#id-menu-btn");a.addEventListener("change",()=>{document.querySelector("body").classList.toggle("menu-open",a.checked)});const b=document.getElementById("id_log");UaLog.callHide=()=>{b.classList.contains("active")&&b.classList.remove("active")};UaLog.callShow=()=>{b.classList.contains("active")||b.classList.add("active")};UaLog.setXY(54,13).setZ(111).new();UaLog.log_show("")},
|
212 |
+
close(){const a=document.querySelector("#menu-toggle");document.querySelector("body").classList.remove("menu-open",a.checked);document.querySelector(".menu-btn").checked=!1},async help(){const a=await requestGet("./help0.html");wnds.wdiv.show(a)},upload(){RagUpload.open()},uploadDir(){RagUpload.openDir()},async load(){alert("load")},log(){UaLog.toggle()}},setOutText=a=>{const b=document.querySelector("#id-text-out .pre-text");b.textContent=a;b.scrollTop=b.scrollHeight},TextInput={wnd:null,init(){this.inp=
|
213 |
+
document.querySelector(".text-input");document.addEventListener("keydown",a=>{document.activeElement!==this.inp&&("F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 Control Alt Shift Meta CapsLock Escape PrintScreen ScrollLock Pause Insert Delete Home End PageUp PageDown ArrowLeft ArrowRight ArrowUp ArrowDown".split(" ").includes(a.key)||a.ctrlKey||a.metaKey||a.preventDefault())});document.querySelector(".clear-button").addEventListener("click",()=>{this.inp.value="";this.inp.focus()});this.inp.addEventListener("keydown",
|
214 |
+
a=>this.handleEnter(a));document.querySelector(".send-input").addEventListener("click",()=>this.send());document.querySelector(".send2-input").addEventListener("click",()=>this.send2());document.querySelector(".clear-input").addEventListener("click",()=>this.clear())},handleEnter(a){"Enter"===a.key&&!a.shiftKey&&Rag.returnOk()&&(a.preventDefault(),this.send2())},async send(){if(this.inp.value){if(Rag.ragContext&&!confirm("Vuoi iniziare una nuova elabrazione ?"))return"";showSpinner();setOutText("");
|
215 |
+
var a=this.inp.value.trim();try{let b=await Rag.requestDocsRAG(a);b=cleanOut(b);setOutText(b);this.inp.value="";UaLog.close()}catch(b){a=`send\n${b}`,console.error(a),alert(a),setOutText(a)}hideSpinner()}else alert("Ricorda di scrivere la Query ")},async send2(){if(this.inp.value){showSpinner();ThreadMgr.isFirst()&&setOutText("");var a=this.inp.value.trim();try{let b=await Rag.requestContext(a);if(""==b){hideSpinner();return}b=cleanOut(b);setOutText(b);this.inp.value=""}catch(b){a=`send2\n${b}`,
|
216 |
+
console.error(a),alert(a),setOutText(a)}hideSpinner()}else alert("Ricorda di scrivere la Query ")},clear(){confirm("Confermi cancellazione conversazione? ")&&(this.inp.value="",setOutText(""),ThreadMgr.init())}};
|
217 |
+
TextOutput={init(){this.copyBtn=document.querySelector(".copy-output");this.copyBtn.addEventListener("click",()=>this.copy());document.querySelector(".clear-output").addEventListener("click",()=>this.clear());document.querySelector(".wnd-output").addEventListener("click",()=>this.openWnd())},openWnd(){const a=document.querySelector("#id-text-out .pre-text").textContent;wnds.wout.show(a)},async copy(){const a=document.querySelector("#id-text-out .pre-text"),b=a.textContent;if(!(2>b.trim().length)){a.classList.add("copied");
|
218 |
+
this.copyBtn.classList.add("copied");try{await navigator.clipboard.writeText(b)}catch(c){console.error("Errore ",c)}setTimeout(()=>{this.copyBtn.classList.remove("copied");a.classList.remove("copied")},5E3)}},clear(){document.querySelector("#id-text-out .pre-text").textContent=""}};const RagUpload={open(){const a=UaWindowAdm.create("id_upload");a.drag();a.setZ(12);a.vw_vh().setXY(16.5,10,-1);a.setHtml('\n <div class="window-text">\n <div class="btn-wrapper">\n <button class="btn-close" title="chiudi" onclick="UaWindowAdm.closeThis(this)">X</button>\n </div> \n <div class="upload"> \n <h4>Upload file Text / PDF</h4> \n <form id="uploadForm">\n <input class="file" type="file" id="id_fileupload" > \n <button type="button" onclick="RagUpload.upload();">Upload and Convert</button>\n </form>\n <div id="result" class="result"></div>\n </div>\n </div>\n ');
|
219 |
a.show()},async upload(){const a=document.getElementById("id_fileupload").files[0];if(a){var b=a.name;if(DataMgr.doc_names.includes(b))alert("Il file \u00e8 gi\u00e0 in archivio");else{var c=document.getElementById("result"),d=a.name.split(".").pop().toLowerCase();showSpinner();try{let e;if("pdf"===d){const f=new PdfHandler;await f.loadPdfJs();e=await f.extractTextFromPDF(a);f.cleanup()}else if("txt"===d)e=await readTextFile(a);else{alert("Formato file non supportato.");return}DataMgr.addDoc(b,e);
|
220 |
c.innerHTML=`<br><br> ${b}<br><br>caricato e salvato nella memoria locale`}catch(e){xerror("Error:",e),alert("Errore durante l'estrazione del testo dal file.")}finally{hideSpinner()}}}else alert("Nessun file selezionato.")},openDir(){const a=UaWindowAdm.create("id_upload");a.drag();a.setZ(12);a.vw_vh().setXY(16.5,10,-1);a.setHtml('\n <div class="window-text">\n <div class="btn-wrapper">\n <button class="btn-close" title="chiudi" onclick="UaWindowAdm.closeThis(this)">X</button>\n </div> \n <div class="upload"> \n <h4>Upload files Text / PDF</h4> \n <form id="uploadForm">\n <input id="id_fileupload" class="file" type="file" webkitdirectory mozdirectory msdirectory odirectory directory multiple />\n <button type="button" onclick="RagUpload.uploadDir();">Upload and Convert</button>\n </form>\n <div class="result" id="result"></div>\n </div>\n </div>\n ');
|
221 |
a.show()},async uploadDir(){var a=document.getElementById("id_fileupload").files;if(a&&0!=a.length){var b=[];showSpinner();try{for(const c of a){const d=c.name;UaLog.log_show(d);if(DataMgr.doc_names.includes(d)){UaLog.log_shw(d+" : \u00e8 gi\u00e0 in archivio");continue}const e=c.name.split(".").pop().toLowerCase();let f;if("pdf"===e){const g=new PdfHandler;await g.loadPdfJs();f=await g.extractTextFromPDF(c);g.cleanup()}else if("txt"===e)f=await readTextFile(c);else{alert("Formato file non supportato.");
|
static/ragrqs.html
CHANGED
@@ -74,6 +74,7 @@
|
|
74 |
<div class="output-wrapper">
|
75 |
|
76 |
<div class="text-out" id="id-text-out">
|
|
|
77 |
</div>
|
78 |
|
79 |
<div class="output-actions">
|
|
|
74 |
<div class="output-wrapper">
|
75 |
|
76 |
<div class="text-out" id="id-text-out">
|
77 |
+
<pre class="pre-text"></pre>
|
78 |
</div>
|
79 |
|
80 |
<div class="output-actions">
|
static/ragrqs_.html
CHANGED
@@ -85,6 +85,7 @@
|
|
85 |
<div class="output-wrapper">
|
86 |
|
87 |
<div class="text-out" id="id-text-out">
|
|
|
88 |
</div>
|
89 |
|
90 |
<div class="output-actions">
|
|
|
85 |
<div class="output-wrapper">
|
86 |
|
87 |
<div class="text-out" id="id-text-out">
|
88 |
+
<pre class="pre-text"></pre>
|
89 |
</div>
|
90 |
|
91 |
<div class="output-actions">
|