gmaterni commited on
Commit
98b4260
1 Parent(s): 669d0be

Upload folder using huggingface_hub

Browse files
static/css/ragrqs.min.css CHANGED
@@ -1 +1 @@
1
- /*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */html{line-height:1.15;background:#1a1a1a}details,main{display:block}h1{font-size:2em;margin:.67em 0}hr{box-sizing:content-box;height:0;overflow:visible}code,kbd,pre,samp{font-family:monospace,monospace;font-size:1em}a{background-color:transparent}abbr[title]{border-bottom:none;text-decoration:underline;text-decoration:underline dotted}b,strong{font-weight:bolder}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}img{border-style:none}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;line-height:1.15;margin:0}button,input{overflow:visible}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner,button::-moz-focus-inner{border-style:none;padding:0}[type=button]:-moz-focusring,[type=reset]:-moz-focusring,[type=submit]:-moz-focusring,button:-moz-focusring{outline:ButtonText dotted 1px}fieldset{padding:.35em .75em .625em}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal}progress{vertical-align:baseline}textarea{overflow:auto}[type=checkbox],[type=radio]{box-sizing:border-box;padding:0}[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}[type=search]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}[hidden],template{display:none}a,body,button,div,html,input,label,li,p,span,table,td,ul{padding:0;margin:0;font-family:arial,verdana,Helvetica,sans-serif}.bb0{background:#daee59!important}.bb1{background:#5487fc!important}body{background:#1a1a1a;box-sizing:border-box;min-height:100vh;height:100vh;position:relative;padding:0;margin:0;overflow:hidden;font-family:arial,verdana,Helvetica,sans-serif;font-weight:400}.spinner{z-index:1000;position:absolute;top:70vh;left:50vw;transform:translate(-50%,-50%);cursor:pointer;display:none;align-items:center}.spinner .pulse-icon{width:20px;height:20px;background-color:#ff8c00;border-radius:50%;animation:1.5s ease-in-out infinite pulse}.spinner .stop-message{margin-left:15px;background-color:inherit;color:#8f8a8a;padding:8px 15px;border-radius:10px;font-size:22px;font-weight:700;opacity:1;transition:opacity .3s}.spinner:hover .stop-message{color:#fff;background:#595959;opacity:1}@keyframes pulse{0%{transform:scale(.6);box-shadow:0 0 0 0 rgba(255,140,0,.7)}70%{transform:scale(1.4);box-shadow:0 0 0 20px rgba(255,140,0,0)}100%{transform:scale(.6);box-shadow:0 0 0 0 rgba(255,140,0,0)}}.show-spinner{display:flex}.upload{background-color:#1e1e1e;padding:0 2em 2em;margin:0;border-radius:4px;box-shadow:0 2px 4px rgba(0,0,0,.5);text-align:center}.upload h4{color:#fff;margin-bottom:1em}.upload form{display:flex;flex-direction:column;align-items:center}.upload form .file{background-color:#121212;border:1px solid #515151;color:#fff;padding:.5em;margin-bottom:1em;border-radius:4px;width:100%;box-sizing:border-box}.upload form .file::file-selector-button{background-color:#0a5f4e;color:#fff;border:none;padding:.5em 1em;border-radius:4px;cursor:pointer}.upload form .file::file-selector-button:hover{background-color:#053128}.upload form button{background-color:#0a5f4e;color:#fff;border:none;padding:.5em 1em;border-radius:4px;cursor:pointer;width:100%;box-sizing:border-box}.upload form button:hover{background-color:#053128}.upload .result{width:100%;background:#000;color:#fff;font-size:15px;font-weight:400;text-align:left}div.container{background:#1a1a1a;box-sizing:border-box;position:relative;top:5vh;left:0;height:95vh;margin:0;padding:0;transition:margin-left .5s;display:flex;flex-direction:column;justify-content:flex-start;align-items:stretch;flex-wrap:nowrap;overflow-y:auto;overflow-x:auto}div.container div.item{box-sizing:border-box;min-height:50px;margin:0;padding:0}div.container div.item1{flex:5;padding:.5vh .5vw 10vh}div.container div.item1 .output-wrapper{background-color:#1a1a1a;border-radius:20px;position:relative;bottom:0;right:0;left:0;width:100%;height:100%;display:flex;flex-direction:row;align-items:flex-start}div.container div.item1 .output-wrapper .text-out{flex:1;box-sizing:border-box;background:#000;color:#fff;border:none;padding:2px;min-width:50vw;height:100%;border-radius:10px;overflow-y:auto;outline:0;box-shadow:0 0 0 2px #4d4d4d}div.container div.item1 .output-wrapper .text-out:hover{box-shadow:0 0 0 2px #17d2ad}div.container div.item1 .output-wrapper .text-out .pre-text{white-space:pre-wrap;word-wrap:break-word;font-family:arial,verdana,Helvetica,sans-serif;font-size:20px;line-height:1.6;padding:2px;margin:0;height:100%;box-sizing:border-box;overflow-y:scroll;scroll-behavior:smooth}div.container div.item1 .output-wrapper .text-out .pre-text.copied{background-color:#0d0d0d;color:#61eed2}div.container div.item1 .output-wrapper .text-out .div-text{white-space:pre-wrap;word-wrap:break-word;font-family:arial,verdana,Helvetica,sans-serif;font-size:20px;line-height:1.6;padding:2px;margin:0;height:100%;box-sizing:border-box;overflow-y:scroll}div.container div.item1 .output-wrapper .text-out.copied{background-color:#0d0d0d;color:#61eed2}div.container div.item1 .output-actions{display:flex;flex-direction:column;align-items:flex-end;margin-left:.5vw;margin-right:.5vw}div.container div.item1 .output-actions .clear-output,div.container div.item1 .output-actions .copy-output,div.container div.item1 .output-actions .wnd-output{box-sizing:border-box;background-color:#333;color:#fff;border:none;padding:10px;cursor:pointer;border-radius:50%;width:40px;height:40px;display:flex;align-items:center;margin-bottom:5px}div.container div.item1 .output-actions .clear-output:hover,div.container div.item1 .output-actions .copy-output:hover,div.container div.item1 .output-actions .wnd-output:hover{background-color:#595959}div.container div.item1 .output-actions .copy-output{transition:background-color .3s,transform .3s}div.container div.item1 .output-actions .copy-output.copied{background:#33e9c5;transform:scale(1.2)}div.container div.item1 .output-actions .copy-output .copy-icon{fill:#FFFFFF;width:24px;height:24px}div.container div.item1 .output-actions .copy-output .copy-icon:hover{fill:#33e9c5}div.container div.item1 .output-actions .clear-output,div.container div.item1 .output-actions .wnd-output{transition:background-color .3s,transform .3s}div.container div.item1 .output-actions .clear-output .icon,div.container div.item1 .output-actions .wnd-output .icon{fill:#FFFFFF;width:24px;height:24px}div.container div.item1 .output-actions .clear-output .icon:hover,div.container div.item1 .output-actions .wnd-output .icon:hover{fill:#33e9c5}:hover{outline:0;caret-color:transparent}textarea:focus{caret-color:auto}div.item2{flex:2;padding:0 .5vw}div.item2 .input-wrapper{background-color:#1a1a1a;border-radius:20px;position:relative;bottom:2vh;right:0;left:0;width:100%;height:100%;display:flex;flex-direction:row;align-items:flex-start}div.item2 .input-wrapper:focus-within .clear-button{display:block}div.item2 .input-wrapper .text-input{flex:1;font-size:20px;font-family:arial,verdana,Helvetica,sans-serif;resize:none;box-sizing:border-box;background:#000;color:#fff;border:none;padding:2px 40px 2px 2px;height:100%;margin-left:5px;border-radius:10px;overflow-y:auto;outline:0;box-shadow:0 0 0 2px #4d4d4d}div.item2 .input-wrapper .text-input:hover{box-shadow:0 0 0 2px #17d2ad}div.item2 .input-wrapper .text-input:focus{box-shadow:0 0 0 2px #ff4500}div.item2 .input-wrapper .clear-button{position:absolute;right:60px;top:19vh;padding:5px;border-radius:50%;background:#333;border:none;font-size:20px;cursor:pointer;color:#ccc;display:none}div.item2 .input-wrapper .clear-button:hover{font-weight:700;background:#595959;color:#fff}div.item2 .input-wrapper .input-actions{display:flex;flex-direction:column;margin-left:.5vw;margin-right:.5vw}div.item2 .input-wrapper .input-actions .clear-input,div.item2 .input-wrapper .input-actions .send-input,div.item2 .input-wrapper .input-actions .send2-input{box-sizing:border-box;background-color:#333;color:#fff;border:none;padding:10px;cursor:pointer;border-radius:50%;width:40px;height:40px;margin-bottom:5px;transition:background-color .3s}div.item2 .input-wrapper .input-actions .send-input{background:#992900}div.item2 .input-wrapper .input-actions .send-input:hover{background:#ff4500}div.item2 .input-wrapper .input-actions .send2-input{background:#0d7661}div.item2 .input-wrapper .input-actions .send2-input:hover{background:#14bb9a}div.item2 .input-wrapper .input-actions .clear-input{background:#333;color:#e6e6e6}div.item2 .input-wrapper .input-actions .clear-input:hover{background:#595959;color:#33e9c5}.menu-open .container{margin-left:16vw}.menu-open .menu-box{left:0!important}div.menu-h{background-color:#1a1a1a;position:fixed;top:0;left:0;width:100vw;height:4.5vh;padding:0;margin:0;outline:0;box-shadow:0 0 0 2px #4d4d4d;z-index:100}div.menu-h .release{background:inherit;color:#ff6a33;font-weight:700;margin-left:50vw;margin-top:.5vh}div.menu-h .menu-btn{appearance:none}div.menu-h .menu-btn:checked+.menu-icon{border:1px solid #333}div.menu-h .menu-btn:checked+.menu-icon .nav-icon{transform:rotate(45deg)}div.menu-h .menu-btn:checked+.menu-icon .nav-icon::before{top:0}div.menu-h .menu-btn:checked+.menu-icon .nav-icon::after{top:0;transform:rotate(90deg)}div.menu-h .menu-icon{box-sizing:border-box;background-color:inherit;display:block;position:absolute;margin-left:2vw;top:0;left:0;width:4vw;height:4.5vh;cursor:pointer;padding:2px;z-index:1}div.menu-h .menu-icon:hover .nav-icon,div.menu-h .menu-icon:hover .nav-icon::after,div.menu-h .menu-icon:hover .nav-icon::before{background-color:#33e9c5}div.menu-h .menu-icon .nav-icon{background-color:#aea7a7;display:block;position:absolute;top:14px;left:0;width:25px;height:2px;transition-duration:.25s}div.menu-h .menu-icon .nav-icon::after,div.menu-h .menu-icon .nav-icon::before{content:"";position:absolute;left:0;background-color:inherit;width:inherit;height:inherit}div.menu-h .menu-icon .nav-icon::before{top:-8px}div.menu-h .menu-icon .nav-icon::after{top:8px}div.menu-h .head-wrapper{position:absolute;top:0;left:5vw;height:4vh;padding:0;margin:0;display:inline-flex;flex-direction:row;flex-wrap:nowrap;align-items:center;justify-content:flex-start}div.menu-h .head-wrapper .help,div.menu-h .head-wrapper .log,div.menu-h .head-wrapper .upload,div.menu-h .head-wrapper .upload-dir{margin-top:2px;margin-left:30px;margin-right:0;padding:5px 5px 0;border:none;cursor:pointer;border-radius:20%;font-size:20px;color:#fff;background:#333;max-height:4vh}div.menu-h .head-wrapper .help:hover,div.menu-h .head-wrapper .log:hover,div.menu-h .head-wrapper .upload-dir:hover,div.menu-h .head-wrapper .upload:hover{background:#595959}div.menu-h .upload,div.menu-h .upload-dir{transition:background-color .3s,transform .3s}div.menu-h .upload .icon,div.menu-h .upload-dir .icon{fill:#FFFFFF;width:24px;height:24px}div.menu-h .upload .icon:hover,div.menu-h .upload-dir .icon:hover{fill:#33e9c5}div.menu-h .log{font-size:14px!important;font-weight:400!important;background:#992900!important}div.menu-h .log:hover{background:#cc3700!important}div.menu-h .log.active{background:#0d7661!important}div.menu-h .log.active:hover{background:#12a487!important}div.menu-h div.menu-box{position:fixed;top:5vh;left:-2000px;height:95vh;width:16vw;transition:left .3s ease-out;padding:1vh 0 0 .5vw;z-index:101;background:#0d0d0d;box-sizing:border-box;outline:0;box-shadow:0 0 0 2px #4d4d4d;display:flex;flex-direction:column;flex-wrap:nowrap;justify-content:flex-start;align-items:stretch;overflow-y:auto;overflow-x:auto}div.menu-h div.menu-box ul{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;border-top:1px solid #333}div.menu-h div.menu-box ul li{border-left:1px solid #333;border-right:1px solid #333;border-bottom:1px solid #333}div.menu-h div.menu-box ul li a{color:#fff;font-size:14px;font-family:arial,verdana,Helvetica,sans-serif;font-weight:400;display:block;margin:0;padding:2px 2px 2px 0;text-align:left;text-decoration:none}div.menu-h div.menu-box ul li:hover{text-decoration:underline;background-color:#333;color:#33e9c5}div.menu-h div.menu-box ul a.delete{text-align:center;font-weight:700;font-style:italic;color:#000;background:#b3a80b}div.menu-h div.menu-box ul a.help{text-align:center;font-weight:700;font-style:italic;color:#000;background:#cc3700}div.menu-h div.menu-box ul li.show{background:#000;color:#fff;width:100%;text-align:center;box-sizing:border-box}div.menu-h div.menu-box ul li.show:hover{text-decoration:none}.window-text{position:relative;top:0;left:0;background:#1a1a1a;color:#fff;border:none;padding:0 2px 2px;width:78vw;height:80vh;border-radius:10px;box-sizing:border-box;outline:0;box-shadow:0 0 0 2px #b3a80b;overflow-y:auto}.window-text pre.pre-text{color:#f8f292;white-space:pre-wrap;word-wrap:break-word;font-family:Georigia,"Ties New Roman",serif;font-size:18px;line-height:1.6;padding:2px;margin:0;text-align:left}.window-text div.text{font-size:18px;font-weight:400;padding-left:10px;padding-right:10px;margin:0}.window-text div.text pre{white-space:pre-wrap;word-wrap:break-word;font-family:arial,verdana,Helvetica,sans-serif;font-size:18px;line-height:1.3;padding:0 5px;margin:0;text-align:left}.window-text div.text .center{text-align:center;font-size:18px;font-weight:700;text-decoration:underline;font-style:italic;color:#e3d50e}.window-text div.text div{font-family:arial,verdana,Helvetica,sans-serif;font-size:18px;font-weight:700;padding-top:0;padding-bottom:0}.window-text div.text div a{background:#000;color:#fff;font-weight:400}.window-text div.text div a:hover{background:#333;color:#fff}.window-text div.text p{font-size:18px;font-weight:400;font-family:arial,verdana,Helvetica,sans-serif;text-align:justify;padding-bottom:9px;padding-right:0;padding-left:10px}.btn-wrapper{width:100%;height:2vw;position:sticky;top:0;padding:0;background:#262626}.btn-wrapper .btn-copy{position:absolute;top:1px;right:5vw;box-sizing:border-box;background:inherit;color:#fff;border:none;cursor:pointer;width:30px;margin:0;padding:0;transition:background-color .3s}.btn-wrapper .btn-copy:hover{background-color:#595959}.btn-wrapper .btn-copy .copy-icon{fill:#e6e6e6;width:20px;height:20px}.btn-wrapper .btn-copy .copy-icon:hover{fill:#33e9c5;background:#404040}.btn-wrapper .btn-close{position:absolute;top:0;right:2vw;margin:0;background-color:transparent;border:none;color:#e6e6e6;font-size:22px;font-weight:700;cursor:pointer;outline:0}.btn-wrapper .btn-close:hover{color:#33e9c5;background:#404040}.msg{box-sizing:border-box;position:fixed;width:300px;height:100px;top:50%;left:50%;transform:translate(-50%,-50%);background-color:#222;color:#ffeb3b;border:2px solid #ffeb3b;border-radius:15px;display:flex;align-items:center;justify-content:center;font-family:Arial,sans-serif;font-size:24px;font-weight:700;text-align:center;z-index:1000;box-shadow:0 4px 8px rgba(0,0,0,.2)}.alert,.confirm{background-color:#303030!important;color:#fff;padding:20px;border-radius:4px;box-shadow:0 2px 4px #00000033!important}.alert .button,.confirm .button{background-color:#37474f!important;color:#fff;border:none;padding:10px 20px;border-radius:4px;cursor:pointer;margin-top:20px}.alert .button:hover,.confirm .button:hover{background-color:#222c31}
 
1
+ /*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */html{line-height:1.15;background:#1a1a1a}details,main{display:block}h1{font-size:2em;margin:.67em 0}hr{box-sizing:content-box;height:0;overflow:visible}code,kbd,pre,samp{font-family:monospace,monospace;font-size:1em}a{background-color:transparent}abbr[title]{border-bottom:none;text-decoration:underline;text-decoration:underline dotted}b,strong{font-weight:bolder}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}img{border-style:none}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;line-height:1.15;margin:0}button,input{overflow:visible}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner,button::-moz-focus-inner{border-style:none;padding:0}[type=button]:-moz-focusring,[type=reset]:-moz-focusring,[type=submit]:-moz-focusring,button:-moz-focusring{outline:ButtonText dotted 1px}fieldset{padding:.35em .75em .625em}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal}progress{vertical-align:baseline}textarea{overflow:auto}[type=checkbox],[type=radio]{box-sizing:border-box;padding:0}[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}[type=search]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}[hidden],template{display:none}a,body,button,div,html,input,label,li,p,span,table,td,ul{padding:0;margin:0;font-family:arial,verdana,Helvetica,sans-serif}.bb0{background:#daee59!important}.bb1{background:#5487fc!important}body{background:#1a1a1a;box-sizing:border-box;min-height:100vh;height:100vh;position:relative;padding:0;margin:0;overflow:hidden;font-family:arial,verdana,Helvetica,sans-serif;font-weight:400}.spinner{z-index:1000;position:absolute;top:70vh;left:50vw;transform:translate(-50%,-50%);cursor:pointer;display:none;align-items:center}.spinner .pulse-icon{width:20px;height:20px;background-color:#ff8c00;border-radius:50%;animation:1.5s ease-in-out infinite pulse}.spinner .stop-message{margin-left:15px;background-color:inherit;color:#8f8a8a;padding:8px 15px;border-radius:10px;font-size:22px;font-weight:700;opacity:1;transition:opacity .3s}.spinner:hover .stop-message{color:#fff;background:#595959;opacity:1}@keyframes pulse{0%{transform:scale(.6);box-shadow:0 0 0 0 rgba(255,140,0,.7)}70%{transform:scale(1.4);box-shadow:0 0 0 20px rgba(255,140,0,0)}100%{transform:scale(.6);box-shadow:0 0 0 0 rgba(255,140,0,0)}}.show-spinner{display:flex}.upload{background-color:#1e1e1e;padding:0 2em 2em;margin:0;border-radius:4px;box-shadow:0 2px 4px rgba(0,0,0,.5);text-align:center}.upload h4{color:#fff;margin-bottom:1em}.upload form{display:flex;flex-direction:column;align-items:center}.upload form .file{background-color:#121212;border:1px solid #515151;color:#fff;padding:.5em;margin-bottom:1em;border-radius:4px;width:100%;box-sizing:border-box}.upload form .file::file-selector-button{background-color:#0a5f4e;color:#fff;border:none;padding:.5em 1em;border-radius:4px;cursor:pointer}.upload form .file::file-selector-button:hover{background-color:#053128}.upload form button{background-color:#0a5f4e;color:#fff;border:none;padding:.5em 1em;border-radius:4px;cursor:pointer;width:100%;box-sizing:border-box}.upload form button:hover{background-color:#053128}.upload .result{width:100%;background:#000;color:#fff;font-size:15px;font-weight:400;text-align:left}div.container{background:#1a1a1a;box-sizing:border-box;position:relative;top:5vh;left:0;height:95vh;margin:0;padding:0;transition:margin-left .5s;display:flex;flex-direction:column;justify-content:flex-start;align-items:stretch;flex-wrap:nowrap;overflow-y:auto;overflow-x:auto}div.container div.item{box-sizing:border-box;min-height:50px;margin:0;padding:0}div.container div.item1{flex:5;padding:.5vh .5vw 10vh}div.container div.item1 .output-wrapper{background-color:#1a1a1a;border-radius:20px;position:relative;bottom:0;right:0;left:0;width:100%;height:100%;display:flex;flex-direction:row;align-items:flex-start}div.container div.item1 .output-wrapper .text-out{flex:1;box-sizing:border-box;background:#000;color:#fff;border:none;padding:2px;min-width:50vw;height:100%;border-radius:10px;overflow-y:auto;outline:0;box-shadow:0 0 0 2px #4d4d4d}div.container div.item1 .output-wrapper .text-out:hover{box-shadow:0 0 0 2px #17d2ad}div.container div.item1 .output-wrapper .text-out .pre-text{white-space:pre-wrap;word-wrap:break-word;font-family:arial,verdana,Helvetica,sans-serif;font-size:20px;line-height:1.6;padding:2px;margin:0;height:100%;box-sizing:border-box;overflow-y:scroll;scroll-behavior:smooth}div.container div.item1 .output-wrapper .text-out .pre-text.copied{background-color:#0d0d0d;color:#61eed2}div.container div.item1 .output-wrapper .text-out .div-text{white-space:pre-wrap;word-wrap:break-word;font-family:arial,verdana,Helvetica,sans-serif;font-size:20px;line-height:1.6;padding:2px;margin:0;height:100%;box-sizing:border-box;overflow-y:scroll}div.container div.item1 .output-wrapper .text-out.copied{background-color:#0d0d0d;color:#61eed2}div.container div.item1 .output-actions{display:flex;flex-direction:column;align-items:flex-end;margin-left:.5vw;margin-right:.5vw}div.container div.item1 .output-actions .clear-output,div.container div.item1 .output-actions .copy-output,div.container div.item1 .output-actions .wnd-output{box-sizing:border-box;background-color:#333;color:#fff;border:none;padding:10px;cursor:pointer;border-radius:50%;width:40px;height:40px;display:flex;align-items:center;margin-bottom:5px}div.container div.item1 .output-actions .clear-output:hover,div.container div.item1 .output-actions .copy-output:hover,div.container div.item1 .output-actions .wnd-output:hover{background-color:#595959}div.container div.item1 .output-actions .copy-output{transition:background-color .3s,transform .3s}div.container div.item1 .output-actions .copy-output.copied{background:#33e9c5;transform:scale(1.2)}div.container div.item1 .output-actions .copy-output .copy-icon{fill:#ffffff;width:24px;height:24px}div.container div.item1 .output-actions .copy-output .copy-icon:hover{fill:#33e9c5}div.container div.item1 .output-actions .clear-output,div.container div.item1 .output-actions .wnd-output{transition:background-color .3s,transform .3s}div.container div.item1 .output-actions .clear-output .icon,div.container div.item1 .output-actions .wnd-output .icon{fill:#ffffff;width:24px;height:24px}div.container div.item1 .output-actions .clear-output .icon:hover,div.container div.item1 .output-actions .wnd-output .icon:hover{fill:#33e9c5}:hover{outline:0;caret-color:transparent}textarea:focus{caret-color:auto}div.item2{flex:2;padding:0 .5vw}div.item2 .input-wrapper{background-color:#1a1a1a;border-radius:20px;position:relative;bottom:2vh;right:0;left:0;width:100%;height:100%;display:flex;flex-direction:row;align-items:flex-start}div.item2 .input-wrapper:focus-within .clear-button{display:block}div.item2 .input-wrapper .text-input{flex:1;font-size:20px;font-family:arial,verdana,Helvetica,sans-serif;resize:none;box-sizing:border-box;background:#000;color:#fff;border:none;padding:2px 40px 2px 2px;height:100%;margin-left:5px;border-radius:10px;overflow-y:auto;outline:0;box-shadow:0 0 0 2px #4d4d4d}div.item2 .input-wrapper .text-input:hover{box-shadow:0 0 0 2px #17d2ad}div.item2 .input-wrapper .text-input:focus{box-shadow:0 0 0 2px #ff4500}div.item2 .input-wrapper .clear-button{position:absolute;right:60px;top:19vh;padding:5px;border-radius:50%;background:#333;border:none;font-size:20px;cursor:pointer;color:#ccc;display:none}div.item2 .input-wrapper .clear-button:hover{font-weight:700;background:#595959;color:#fff}div.item2 .input-wrapper .input-actions{display:flex;flex-direction:column;margin-left:.5vw;margin-right:.5vw}div.item2 .input-wrapper .input-actions .clear-input,div.item2 .input-wrapper .input-actions .send-input,div.item2 .input-wrapper .input-actions .send2-input{box-sizing:border-box;background-color:#333;color:#fff;border:none;padding:10px;cursor:pointer;border-radius:50%;width:40px;height:40px;margin-bottom:5px;transition:background-color .3s}div.item2 .input-wrapper .input-actions .send-input{background:#992900}div.item2 .input-wrapper .input-actions .send-input:hover{background:#ff4500}div.item2 .input-wrapper .input-actions .send2-input{background:#0d7661}div.item2 .input-wrapper .input-actions .send2-input:hover{background:#14bb9a}div.item2 .input-wrapper .input-actions .clear-input{background:#333;color:#e6e6e6}div.item2 .input-wrapper .input-actions .clear-input:hover{background:#595959;color:#33e9c5}.menu-open .container{margin-left:16vw}.menu-open .menu-box{left:0!important}div.menu-h{background-color:#1a1a1a;position:fixed;top:0;left:0;width:100vw;height:4.5vh;padding:0;margin:0;outline:0;box-shadow:0 0 0 2px #4d4d4d;z-index:100}div.menu-h .release{background:inherit;color:#ff6a33;font-weight:700;margin-left:50vw;margin-top:.5vh}div.menu-h .menu-btn{appearance:none}div.menu-h .menu-btn:checked+.menu-icon{border:1px solid #333}div.menu-h .menu-btn:checked+.menu-icon .nav-icon{transform:rotate(45deg)}div.menu-h .menu-btn:checked+.menu-icon .nav-icon::before{top:0}div.menu-h .menu-btn:checked+.menu-icon .nav-icon::after{top:0;transform:rotate(90deg)}div.menu-h .menu-icon{box-sizing:border-box;background-color:inherit;display:block;position:absolute;margin-left:2vw;top:0;left:0;width:4vw;height:4.5vh;cursor:pointer;padding:2px;z-index:1}div.menu-h .menu-icon:hover .nav-icon,div.menu-h .menu-icon:hover .nav-icon::after,div.menu-h .menu-icon:hover .nav-icon::before{background-color:#33e9c5}div.menu-h .menu-icon .nav-icon{background-color:#aea7a7;display:block;position:absolute;top:14px;left:0;width:25px;height:2px;transition-duration:.25s}div.menu-h .menu-icon .nav-icon::after,div.menu-h .menu-icon .nav-icon::before{content:"";position:absolute;left:0;background-color:inherit;width:inherit;height:inherit}div.menu-h .menu-icon .nav-icon::before{top:-8px}div.menu-h .menu-icon .nav-icon::after{top:8px}div.menu-h .head-wrapper{position:absolute;top:0;left:5vw;height:4vh;padding:0;margin:0;display:inline-flex;flex-direction:row;flex-wrap:nowrap;align-items:center;justify-content:flex-start}div.menu-h .head-wrapper .help,div.menu-h .head-wrapper .log,div.menu-h .head-wrapper .upload,div.menu-h .head-wrapper .upload-dir{margin-top:2px;margin-left:30px;margin-right:0;padding:5px 5px 0;border:none;cursor:pointer;border-radius:20%;font-size:20px;color:#fff;background:#333;max-height:4vh}div.menu-h .head-wrapper .help:hover,div.menu-h .head-wrapper .log:hover,div.menu-h .head-wrapper .upload-dir:hover,div.menu-h .head-wrapper .upload:hover{background:#595959}div.menu-h .upload,div.menu-h .upload-dir{transition:background-color .3s,transform .3s}div.menu-h .upload .icon,div.menu-h .upload-dir .icon{fill:#ffffff;width:24px;height:24px}div.menu-h .upload .icon:hover,div.menu-h .upload-dir .icon:hover{fill:#33e9c5}div.menu-h .log{font-size:14px!important;font-weight:400!important;background:#992900!important}div.menu-h .log:hover{background:#cc3700!important}div.menu-h .log.active{background:#0d7661!important}div.menu-h .log.active:hover{background:#12a487!important}div.menu-h div.menu-box{position:fixed;top:5vh;left:-2000px;height:95vh;width:16vw;transition:left .3s ease-out;padding:1vh 0 0 .5vw;z-index:101;background:#0d0d0d;box-sizing:border-box;outline:0;box-shadow:0 0 0 2px #4d4d4d;display:flex;flex-direction:column;flex-wrap:nowrap;justify-content:flex-start;align-items:stretch;overflow-y:auto;overflow-x:auto}div.menu-h div.menu-box ul{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;border-top:1px solid #333}div.menu-h div.menu-box ul li{border-left:1px solid #333;border-right:1px solid #333;border-bottom:1px solid #333}div.menu-h div.menu-box ul li a{color:#fff;font-size:14px;font-family:arial,verdana,Helvetica,sans-serif;font-weight:400;display:block;margin:0;padding:2px 2px 2px 0;text-align:left;text-decoration:none}div.menu-h div.menu-box ul li:hover{text-decoration:underline;background-color:#333;color:#33e9c5}div.menu-h div.menu-box ul a.delete{text-align:center;font-weight:700;font-style:italic;color:#000;background:#b3a80b}div.menu-h div.menu-box ul a.help{text-align:center;font-weight:700;font-style:italic;color:#000;background:#cc3700}div.menu-h div.menu-box ul li.show{background:#000;color:#fff;width:100%;text-align:center;box-sizing:border-box}div.menu-h div.menu-box ul li.show:hover{text-decoration:none}.window-text{position:relative;top:0;left:0;background:#1a1a1a;color:#fff;border:none;padding:0 2px 2px;width:78vw;height:80vh;border-radius:10px;box-sizing:border-box;outline:0;box-shadow:0 0 0 2px #b3a80b;overflow-y:auto}.window-text pre.pre-text{color:#f8f292;white-space:pre-wrap;word-wrap:break-word;font-family:Georigia,"Ties New Roman",serif;font-size:18px;line-height:1.6;padding:2px;margin:0;text-align:left}.window-text div.text{font-size:18px;font-weight:400;padding-left:10px;padding-right:10px;margin:0}.window-text div.text pre{white-space:pre-wrap;word-wrap:break-word;font-family:arial,verdana,Helvetica,sans-serif;font-size:18px;line-height:1.3;padding:0 5px;margin:0;text-align:left}.window-text div.text .center{text-align:center;font-size:18px;font-weight:700;text-decoration:underline;font-style:italic;color:#e3d50e}.window-text div.text .label{margin:5px 0 5px 10px;font-size:18px;font-weight:700;font-style:italic;color:#e3d50e}.window-text div.text div{font-family:arial,verdana,Helvetica,sans-serif;font-size:18px;font-weight:700;padding-top:0;padding-bottom:0}.window-text div.text div a{background:#000;color:#fff;font-weight:400}.window-text div.text div a:hover{background:#333;color:#fff}.window-text div.text p{font-size:18px;font-weight:400;font-family:arial,verdana,Helvetica,sans-serif;text-align:justify;padding-bottom:9px;padding-right:0;padding-left:10px}.btn-wrapper{width:100%;height:2vw;position:sticky;top:0;padding:0;background:#262626}.btn-wrapper .btn-copy{position:absolute;top:1px;right:5vw;box-sizing:border-box;background:inherit;color:#fff;border:none;cursor:pointer;width:30px;margin:0;padding:0;transition:background-color .3s}.btn-wrapper .btn-copy:hover{background-color:#595959}.btn-wrapper .btn-copy .copy-icon{fill:#e6e6e6;width:20px;height:20px}.btn-wrapper .btn-copy .copy-icon:hover{fill:#33e9c5;background:#404040}.btn-wrapper .btn-close{position:absolute;top:0;right:2vw;margin:0;background-color:transparent;border:none;color:#e6e6e6;font-size:22px;font-weight:700;cursor:pointer;outline:0}.btn-wrapper .btn-close:hover{color:#33e9c5;background:#404040}.msg{box-sizing:border-box;position:fixed;width:300px;height:100px;top:50%;left:50%;transform:translate(-50%,-50%);background-color:#222;color:#ffeb3b;border:2px solid #ffeb3b;border-radius:15px;display:flex;align-items:center;justify-content:center;font-family:Arial,sans-serif;font-size:24px;font-weight:700;text-align:center;z-index:1000;box-shadow:0 4px 8px rgba(0,0,0,.2)}.alert,.confirm{background-color:#303030!important;color:#fff;padding:20px;border-radius:4px;box-shadow:0 2px 4px #00000033!important}.alert .button,.confirm .button{background-color:#37474f!important;color:#fff;border:none;padding:10px 20px;border-radius:4px;cursor:pointer;margin-top:20px}.alert .button:hover,.confirm .button:hover{background-color:#222c31}
static/data/help_test.html CHANGED
@@ -1,17 +1,28 @@
1
  <div class="text">
2
  <br>
 
3
  <div><a href="#" onCLick="loadTestoEsempio('aaron_swartz.txt');">Aaron Swartz</a></div>
4
  <br>
5
  <div><a href="#" onCLick="loadTestoEsempio('roberto_busa.txt');">Roberto Busa</a></div>
6
  <br>
7
  <div><a href="#" onCLick="loadTestoEsempio('la_cattedrale_e_il_bazaar.txt');">La cattedrale e il Bazar</a></div>
8
  <br>
 
 
 
 
9
  <div><a href="#" onCLick="loadTestoEsempio('aristotele_detective.txt');">Aristotele Detective</a></div>
10
  <br>
11
- <div><a href="#" onCLick="loadTestoEsempio('montecristo.txt');">Montecristor</a></div>
 
 
12
  <br>
 
 
13
  <div><a href="#" onCLick="loadTestoEsempio('il_libro_rosso.txt');">Il libro rosso</a></div>
14
  <br>
 
 
15
  <div><a href="#" onCLick="loadTestoEsempio('lettere_musulmane.txt');">Lettere Mussulmane</a></div>
16
 
17
  <!--
 
1
  <div class="text">
2
  <br>
3
+ <p class="label">Software Open SOurce</p>
4
  <div><a href="#" onCLick="loadTestoEsempio('aaron_swartz.txt');">Aaron Swartz</a></div>
5
  <br>
6
  <div><a href="#" onCLick="loadTestoEsempio('roberto_busa.txt');">Roberto Busa</a></div>
7
  <br>
8
  <div><a href="#" onCLick="loadTestoEsempio('la_cattedrale_e_il_bazaar.txt');">La cattedrale e il Bazar</a></div>
9
  <br>
10
+
11
+ <p class="label">Ramanzi</p>
12
+ <div><a href="#" onCLick="loadTestoEsempio('i_promessi_sposi.txt');">I Promessi Sposi</a></div>
13
+ <br>
14
  <div><a href="#" onCLick="loadTestoEsempio('aristotele_detective.txt');">Aristotele Detective</a></div>
15
  <br>
16
+ <div><a href="#" onCLick="loadTestoEsempio('montecristo.txt');">Il Conte di Montecristo</a></div>
17
+ <br>
18
+ <div><a href="#" onCLick="loadTestoEsempio('il_segreto_di_pietramala.txt');">Il Segreto di Pietramala</a></div>
19
  <br>
20
+
21
+ <p class="label">Psicologia Junghiana</p>
22
  <div><a href="#" onCLick="loadTestoEsempio('il_libro_rosso.txt');">Il libro rosso</a></div>
23
  <br>
24
+
25
+ <p class="label">Alchimia</p>
26
  <div><a href="#" onCLick="loadTestoEsempio('lettere_musulmane.txt');">Lettere Mussulmane</a></div>
27
 
28
  <!--
static/data/i_promessi_sposi.txt ADDED
The diff for this file is too large to render. See raw diff
 
static/data/il_mistero_delle_cattedrali.txt ADDED
The diff for this file is too large to render. See raw diff
 
static/data/il_segreto_di_pietramala.txt ADDED
The diff for this file is too large to render. See raw diff
 
static/javascript/rag_cleaner.js CHANGED
@@ -1,81 +1,160 @@
1
  /** @format */
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  const removeChars = (txt) => {
4
- const charsRm = /[\u00AD\u200B\u200C\u200D\u2060\uFEFF]/g;
5
- txt = txt.replace(charsRm, "");
6
- txt = Array.from(txt)
7
- .filter((ch) => !/^C/.test(ch.codePointAt(0)))
8
- .join("");
9
  return txt;
10
- };
11
 
12
  const replaceChars = (txt) => {
13
- const charsSrp = /[\u00A0\u2000-\u200A\u202F\u205F\u3000\t\r\f\v]/g;
14
- txt = txt.replace(charsSrp, " ");
15
- txt = txt.replace(/ +/g, " ");
16
- return txt.trim();
17
- };
18
-
19
- const removeTag = (txt) => {
20
- txt = txt.replace(/<<<|>>>|<<|>>/g, "");
21
  return txt;
22
- };
 
 
 
 
 
 
23
 
24
  function cleanDoc(txt) {
25
  try {
26
- txt = removeTag(txt);
27
- txt = removeChars(txt);
28
- txt = replaceChars(txt);
29
- txt = txt.replace(/\n/g, " ");
30
- txt = txt.replace(/\t/g, " ");
31
- txt = txt.replace(/ +/g, " ");
32
- txt = txt.replace(/\n\s*\n/g, "\n");
33
- txt = txt.replace(/[“”]/g, '"');
34
- txt = txt.replace(/[‘’]/g, "'");
35
- txt = txt.replace(/[«»„“]/g, '"');
36
- txt = txt.replace(/[–—]/g, "-");
37
- txt = txt.replace(/\\[nrt]/g, "");
38
- txt = txt.replace(/[^\w\sàèéìòùÀÈÉÌÒÙáéíóúÁÉÍÓÚäëïöüÄËÏÖÜâêîôûÂÊÎÔÛçÇñÑ.,;:!?'"()-]/g, "");
39
- return txt.trim();
 
 
 
 
 
 
 
 
 
 
 
40
  } catch (e) {
41
- xerror(e);
42
- return "Errore di codifica nel documento";
43
  }
44
  }
45
 
46
  function cleanResponse(txt) {
47
  try {
48
- txt = removeChars(txt);
49
- txt = replaceChars(txt);
50
- txt = txt.replace(/\t/g, " ");
51
- txt = txt.replace(/ +/g, " ");
52
- txt = txt.replace(/\n\s*\n/g, "\n");
53
- txt = txt.replace(/[“”]/g, '"');
54
- txt = txt.replace(/[‘’]/g, "'");
55
- txt = txt.replace(/[«»„“]/g, '"');
56
- txt = txt.replace(/[–—]/g, "-");
57
- txt = txt.replace(/\\[nrt]/g, "");
58
- txt = txt.replace(/[^\w\sàèéìòùÀÈÉÌÒÙáéíóúÁÉÍÓÚäëïöüÄËÏÖÜâêîôûÂÊÎÔÛçÇñÑ.,;:!?'"()-]/g, "");
59
- return txt.trim();
 
 
 
 
 
 
 
 
 
 
60
  } catch (e) {
61
- xerror(e);
62
- return "Errore di codifica nela risposta";
63
  }
64
  }
65
 
 
66
  function cleanOutput(txt) {
67
  try {
68
  txt = removeChars(txt);
69
  txt = replaceChars(txt);
70
  txt = txt.replace(/\t/g, " ");
71
- txt = txt.replace(/ +/g, " ");
72
  txt = txt.replace(/\n\s*\n/g, "\n");
73
- txt = txt.replace(/[“”]/g, '"');
74
- txt = txt.replace(/[‘’]/g, "'");
75
- txt = txt.replace(/[«»„“]/g, '"');
76
- txt = txt.replace(/[–—]/g, "-");
77
- txt = txt.replace(/\\[nrt]/g, "");
 
78
  txt = txt.replace(/[^\w\sàèéìòùÀÈÉÌÒÙáéíóúÁÉÍÓÚäëïöüÄËÏÖÜâêîôûÂÊÎÔÛçÇñÑ.,;:!?'"()-]/g, "");
 
79
  return txt.trim();
80
  } catch (e) {
81
  xerror(e);
 
1
  /** @format */
2
 
3
+ // const removeChars = (txt) => {
4
+ // const charsRm = /[\u00AD\u200B\u200C\u200D\u2060\uFEFF]/g;
5
+ // txt = txt.replace(charsRm, "");
6
+ // return txt;
7
+ // };
8
+
9
+ // const replaceChars = (txt) => {
10
+ // const charsSrp = /[\u00A0\u2000-\u200A\u202F\u205F\u3000\t\r\f\v]/g;
11
+ // txt = txt.replace(charsSrp, " ");
12
+ // txt = txt.replace(/ +/g, " ");
13
+ // return txt.trim();
14
+ // };
15
+
16
+ // const removeTag = (txt) => {
17
+ // txt = txt.replace(/<<<|>>>|<<|>>/g, "");
18
+ // return txt;
19
+ // };
20
+
21
+ // function cleanDoc(txt) {
22
+ // try {
23
+ // txt = removeTag(txt);
24
+ // txt = removeChars(txt);
25
+ // txt = replaceChars(txt);
26
+ // txt = txt.replace(/\n/g, " ");
27
+ // txt = txt.replace(/\t/g, " ");
28
+ // txt = txt.replace(/ +/g, " ");
29
+ // txt = txt.replace(/\n\s*\n/g, "\n");
30
+ // txt = txt.replace(/[“”]/g, '"');
31
+ // txt = txt.replace(/[‘’]/g, "'");
32
+ // txt = txt.replace(/[«»„“]/g, '"');
33
+ // txt = txt.replace(/[–—]/g, "-");
34
+ // txt = txt.replace(/\\[nrt]/g, "");
35
+ // txt = txt.replace(/[^\w\sàèéìòùÀÈÉÌÒÙáéíóúÁÉÍÓÚäëïöüÄËÏÖÜâêîôûÂÊÎÔÛçÇñÑ.,;:!?'"()-]/g, "");
36
+ // return txt.trim();
37
+ // } catch (e) {
38
+ // xerror(e);
39
+ // return "Errore di codifica nel documento";
40
+ // }
41
+ // }
42
+
43
+ // function cleanResponse(txt) {
44
+ // try {
45
+ // txt = removeChars(txt);
46
+ // txt = replaceChars(txt);
47
+ // txt = txt.replace(/\t/g, " ");
48
+ // txt = txt.replace(/ +/g, " ");
49
+ // txt = txt.replace(/\n\s*\n/g, "\n");
50
+ // txt = txt.replace(/[“”]/g, '"');
51
+ // txt = txt.replace(/[‘’]/g, "'");
52
+ // txt = txt.replace(/[«»„“]/g, '"');
53
+ // txt = txt.replace(/[–—]/g, "-");
54
+ // txt = txt.replace(/\\[nrt]/g, "");
55
+ // txt = txt.replace(/[^\w\sàèéìòùÀÈÉÌÒÙáéíóúÁÉÍÓÚäëïöüÄËÏÖÜâêîôûÂÊÎÔÛçÇñÑ.,;:!?'"()-]/g, "");
56
+ // return txt.trim();
57
+ // } catch (e) {
58
+ // xerror(e);
59
+ // return "Errore di codifica nela risposta";
60
+ // }
61
+ // ////////////////////////////////
62
  const removeChars = (txt) => {
63
+ const chars_rm = /[\u00AD\u200B\u200C\u200D\u2060\uFEFF]/g;
64
+ txt = txt.replace(chars_rm, '');
 
 
 
65
  return txt;
66
+ }
67
 
68
  const replaceChars = (txt) => {
69
+ const chars_srp = /[\u00A0\u2000-\u200A\u202F\u205F\u3000\t\r\f\v]/g;
70
+ txt = txt.replace(chars_srp, ' ');
 
 
 
 
 
 
71
  return txt;
72
+ }
73
+
74
+ const removeTag = (txt) => {
75
+ txt = txt.replace(/<<</g, '').replace(/>>>/g, '');
76
+ txt = txt.replace(/<</g, '').replace(/>>/g, '');
77
+ return txt;
78
+ }
79
 
80
  function cleanDoc(txt) {
81
  try {
82
+ txt = removeTag(txt);
83
+ txt = removeChars(txt);
84
+ txt = replaceChars(txt);
85
+ // Removes multiple empty lines
86
+ txt = txt.replace(/\n\s*\n/g, '\n');
87
+ // Removes visible escape characters like \n, \r, \t
88
+ txt = txt.replace(/\t/g, ' ');
89
+ txt = txt.replace(/\r/g, ' ');
90
+ txt = txt.replace(/\n/g, ' ');
91
+
92
+ // Uniforms quotation characters
93
+ txt = txt.replace(/“/g, '"');
94
+ txt = txt.replace(/”/g, '"');
95
+
96
+ // Replaces long dashes with normal dashes
97
+ // txt = txt.replace(/–/g, '-');
98
+ // txt = txt.replace(/—/g, '-');
99
+
100
+ // Removes uncommon special characters while keeping accented characters and punctuation
101
+ txt = txt.replace(/[^\w\sàèéìòùÀÈÉÌÒÙáéíóúÁÉÍÓÚäëïöüÄËÏÖÜâêîôûÂÊÎÔÛçÇñÑ.,;:!?'"()-]/g, '');
102
+ // Removes spaces before punctuation
103
+ txt = txt.replace(/ +([.,;:!?])/g, '$1');
104
+ // Removes multiple spaces
105
+ txt = txt.replace(/ +/g, ' ');
106
+ return txt.trim();
107
  } catch (e) {
108
+ xerror(e);
109
+ return "Errore di codifica nella risposta";
110
  }
111
  }
112
 
113
  function cleanResponse(txt) {
114
  try {
115
+ txt = removeChars(txt);
116
+ txt = replaceChars(txt);
117
+ // Removes multiple empty lines
118
+ txt = txt.replace(/\n\s*\n/g, '\n');
119
+
120
+ // Removes visible escape characters like \n, \r, \t
121
+ txt = txt.replace(/\t/g, ' ');
122
+ txt = txt.replace(/\r/g, ' ');
123
+ txt = txt.replace(/\n/g, ' '); //TODO
124
+
125
+ // Replaces long dashes with normal dashes
126
+ // txt = txt.replace(/–/g, '-');
127
+ // txt = txt.replace(/—/g, '-');
128
+
129
+ // Removes uncommon special characters while keeping accented characters and punctuation
130
+ txt = txt.replace(/[^\w\sàèéìòùÀÈÉÌÒÙáéíóúÁÉÍÓÚäëïöüÄËÏÖÜâêîôûÂÊÎÔÛçÇñÑ.,;:!?'"()-]/g, '');
131
+
132
+ // Removes spaces before punctuation
133
+ txt = txt.replace(/ +([.,;:!?])/g, '$1');
134
+ // Removes multiple spaces
135
+ txt = txt.replace(/ +/g, ' ');
136
+ return txt.trim();
137
  } catch (e) {
138
+ console.error(e);
139
+ return "Errore di codifica nella risposta";
140
  }
141
  }
142
 
143
+ //////////////////////////////////
144
  function cleanOutput(txt) {
145
  try {
146
  txt = removeChars(txt);
147
  txt = replaceChars(txt);
148
  txt = txt.replace(/\t/g, " ");
 
149
  txt = txt.replace(/\n\s*\n/g, "\n");
150
+ // txt = txt.replace(/[“”]/g, '"');
151
+ // txt = txt.replace(/[‘’]/g, "'");
152
+ // txt = txt.replace(/[«»„“]/g, '"');
153
+ // txt = txt.replace(/[–—]/g, "-");
154
+ txt = txt.replace(/\r/g, " ");
155
+ // txt = txt.replace(/\n/g, " ");//TODO
156
  txt = txt.replace(/[^\w\sàèéìòùÀÈÉÌÒÙáéíóúÁÉÍÓÚäëïöüÄËÏÖÜâêîôûÂÊÎÔÛçÇñÑ.,;:!?'"()-]/g, "");
157
+ txt = txt.replace(/ +/g, " ");
158
  return txt.trim();
159
  } catch (e) {
160
  xerror(e);
static/javascript/rag_data_mgr.js CHANGED
@@ -1,6 +1,13 @@
1
  /** @format */
2
 
3
  "use strict";
 
 
 
 
 
 
 
4
  const UaDb = {
5
  create(id, data) {
6
  if (localStorage.getItem(id)) {
@@ -48,7 +55,7 @@ const UaDb = {
48
  readArray(id) {
49
  const str = UaDb.read(id);
50
  if (str.trim().length == 0) return [];
51
- const arr=JSON.parse(str);
52
  return arr;
53
  },
54
  saveJson(id, js) {
@@ -90,19 +97,19 @@ const DataMgr = {
90
  this.saveDbDocs();
91
  },
92
  saveDbDocs() {
93
- UaDb.saveArray("id_doc_names", this.doc_names);
94
- UaDb.saveArray("id_docs", this.docs);
95
  },
96
  readDbDocs() {
97
- this.docs = UaDb.readArray("id_docs");
98
  },
99
  readDbDocNames() {
100
- this.doc_names = UaDb.readArray("id_doc_names");
101
  },
102
  deleteJsonDati() {
103
  const ids = UaDb.getAllIds();
104
  for (const id of ids) {
105
- if (["id_docs", "id_doc_names"].includes(id)) continue;
106
  UaDb.delete(id);
107
  }
108
  Rag.ragQuery = "";
 
1
  /** @format */
2
 
3
  "use strict";
4
+ const ID_RESPONSES = "id_responses";
5
+ const ID_DOC_NAMES = "id_doc_names";
6
+ const ID_DOCS = "id_docs;";
7
+ const ID_RAG = "id_rag";
8
+ const ID_THREAD="id_thread";
9
+
10
+
11
  const UaDb = {
12
  create(id, data) {
13
  if (localStorage.getItem(id)) {
 
55
  readArray(id) {
56
  const str = UaDb.read(id);
57
  if (str.trim().length == 0) return [];
58
+ const arr = JSON.parse(str);
59
  return arr;
60
  },
61
  saveJson(id, js) {
 
97
  this.saveDbDocs();
98
  },
99
  saveDbDocs() {
100
+ UaDb.saveArray(ID_DOC_NAMES, this.doc_names);
101
+ UaDb.saveArray(ID_DOCS, this.docs);
102
  },
103
  readDbDocs() {
104
+ this.docs = UaDb.readArray(ID_DOCS);
105
  },
106
  readDbDocNames() {
107
+ this.doc_names = UaDb.readArray(ID_DOC_NAMES);
108
  },
109
  deleteJsonDati() {
110
  const ids = UaDb.getAllIds();
111
  for (const id of ids) {
112
+ if ([ID_DOCS, ID_DOC_NAMES].includes(id)) continue;
113
  UaDb.delete(id);
114
  }
115
  Rag.ragQuery = "";
static/javascript/rag_http.js CHANGED
@@ -35,7 +35,7 @@ async function requestGet(url) {
35
  const text = new TextDecoder("utf-8").decode(arrayBuffer);
36
  return text;
37
  } catch (error) {
38
- xerror(error);
39
  let message;
40
  if (error.name === "AbortError") {
41
  message = "Request was aborted";
@@ -56,7 +56,7 @@ const HfRequest = {
56
  isCancelled: false,
57
  baseUrl: "https://api-inference.huggingface.co/models",
58
 
59
- async post(payload, timeout = 30000) {
60
  this.isCancelled = false;
61
  this.controller = new AbortController();
62
 
@@ -96,14 +96,12 @@ const HfRequest = {
96
  throw error;
97
  }
98
  },
99
-
100
  cancelRequest() {
101
  if (this.controller) {
102
  this.isCancelled = true;
103
  this.controller.abort();
104
  }
105
  },
106
-
107
  checkError(status, data) {
108
  let errorType;
109
  if (status >= 500) {
@@ -123,7 +121,6 @@ const HfRequest = {
123
  }
124
  return errorType;
125
  },
126
-
127
  isInvalidResponse(data) {
128
  if (!data || !Array.isArray(data) || data.length === 0) {
129
  return "INVALID_DATA";
@@ -133,7 +130,6 @@ const HfRequest = {
133
  }
134
  return null;
135
  },
136
-
137
  createErrorInfo(status, statusText, msg, errorType) {
138
  const err = {
139
  status: status,
@@ -144,84 +140,17 @@ const HfRequest = {
144
  return JSON.stringify(err);
145
  },
146
  };
147
- /////////////////////////
148
-
149
- // const HfError = class extends Error {
150
- // constructor(status, statusText, message, errorType) {
151
- // super(message);
152
- // this.name = "HfError";
153
- // this.status = status;
154
- // this.statusText = statusText;
155
- // this.errorType = errorType;
156
- // }
157
- // };
158
-
159
- // const HfRequest = {
160
- // controller: null,
161
- // isCancelled: false,
162
- // baseUrl: "https://api-inference.huggingface.co/models",
163
 
164
- // async post(payload, timeout = 30000) {
165
- // this.isCancelled = false;
166
- // this.controller = new AbortController();
167
-
168
- // try {
169
- // const timeoutId = setTimeout(() => this.controller.abort(), timeout);
170
- // const response = await fetch(`${this.baseUrl}/${model_name}`, {
171
- // method: "POST",
172
- // headers: {
173
- // Authorization: `Bearer ${HF_TOKEN}`,
174
- // "Content-Type": "application/json",
175
- // },
176
- // body: JSON.stringify(payload),
177
- // signal: this.controller.signal,
178
- // });
179
- // clearTimeout(timeoutId);
180
- // if (this.isCancelled) return null;
181
- // const data = await response.json();
182
- // if (!response.ok) {
183
- // throw this.createError(response, data);
184
- // }
185
- // if (!Array.isArray(data) || data.length === 0 || !data[0].generated_text) {
186
- // throw this.createError(response, data, "Risposta non valida", "INVALID_RESPONSE");
187
- // }
188
- // return data[0].generated_text.trim();
189
- // } catch (error) {
190
- // if (this.isCancelled) return null;
191
- // if (error.name === "AbortError") {
192
- // throw this.createError(null, null, "La richiesta è scaduta", "TIMEOUT_ERROR");
193
- // }
194
- // if (error instanceof HfError) throw error;
195
- // throw this.createError(null, null, error.message, "UNKNOWN_ERROR");
196
- // }
197
- // },
198
-
199
- // cancelRequest() {
200
- // if (this.controller) {
201
- // this.isCancelled = true;
202
- // this.controller.abort();
203
- // }
204
- // },
205
-
206
- // createError(response, data, customMessage, customErrorType) {
207
- // const status = response ? response.status : 0;
208
- // const statusText = response ? response.statusText : "Unknown Error";
209
- // const message = customMessage || (data && data.error) || "Errore sconosciuto";
210
- // let errorType = customErrorType;
211
-
212
- // if (!errorType) {
213
- // if (status >= 500) errorType = "SERVER_ERROR";
214
- // else if (status >= 400 && status < 500) {
215
- // if (data && data.error_type === "validation") {
216
- // errorType = data.error.includes("tokens") ? "ERROR_TOKENS" : "ERROR_VALIDATION";
217
- // } else {
218
- // errorType = "CLIENT_ERROR";
219
- // }
220
- // } else {
221
- // errorType = "UNKNOWN_ERROR";
222
- // }
223
- // }
224
 
225
- // return new HfError(status, statusText, message, errorType);
226
- // },
227
- // };
 
 
 
 
 
 
35
  const text = new TextDecoder("utf-8").decode(arrayBuffer);
36
  return text;
37
  } catch (error) {
38
+ console.error(error);
39
  let message;
40
  if (error.name === "AbortError") {
41
  message = "Request was aborted";
 
56
  isCancelled: false,
57
  baseUrl: "https://api-inference.huggingface.co/models",
58
 
59
+ async post(payload, timeout = 50000) {
60
  this.isCancelled = false;
61
  this.controller = new AbortController();
62
 
 
96
  throw error;
97
  }
98
  },
 
99
  cancelRequest() {
100
  if (this.controller) {
101
  this.isCancelled = true;
102
  this.controller.abort();
103
  }
104
  },
 
105
  checkError(status, data) {
106
  let errorType;
107
  if (status >= 500) {
 
121
  }
122
  return errorType;
123
  },
 
124
  isInvalidResponse(data) {
125
  if (!data || !Array.isArray(data) || data.length === 0) {
126
  return "INVALID_DATA";
 
130
  }
131
  return null;
132
  },
 
133
  createErrorInfo(status, statusText, msg, errorType) {
134
  const err = {
135
  status: status,
 
140
  return JSON.stringify(err);
141
  },
142
  };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
 
144
+ function errorInfo(err) {
145
+ const js = JSON.parse(err.message);
146
+ return js;
147
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
 
149
+ function errorToText(err) {
150
+ const j = JSON.parse(err.message);
151
+ return `Error:
152
+ Status: ${j.status}
153
+ Status Text: ${j.statusText}
154
+ Error Type: ${j.errorType}
155
+ Message: ${j.message}`;
156
+ }
static/javascript/rag_mgr.js CHANGED
@@ -18,7 +18,7 @@
18
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
  */
20
  "use strict";
21
- const MAX_PROMPT_LENGTH = 1024 * 85;
22
  // decremento dopo errore per tokens eccessivi
23
  const PROMPT_DECR = 1024 * 2;
24
 
@@ -43,21 +43,21 @@ const Rag = {
43
  ragquery: this.ragQuery,
44
  ragresponse: this.ragResponse,
45
  };
46
- UaDb.saveJson("id_rag", js);
47
- UaDb.saveArray("id_thread", ThreadMgr.rows);
48
  },
49
  readFromDb() {
50
- const js = UaDb.readJson("id_rag");
51
  this.ragContext = js.context || "";
52
  this.ragQuery = js.ragquery || "";
53
  this.ragResponse = js.ragresponse || "";
54
- ThreadMgr.rows = UaDb.readArray("id_thread");
55
  },
56
  saveRespToDb() {
57
- UaDb.saveArray("id_responses", this.responses);
58
  },
59
  readRespsFromDb() {
60
- this.responses = UaDb.readArray("id_responses");
61
  },
62
  addPrompt(p) {
63
  this.prompts.push(p);
@@ -109,21 +109,7 @@ const Rag = {
109
  pRgt = pRgt.substring(partSize).trim();
110
  return [pLft, pRgt];
111
  },
112
-
113
- errorInfo(err) {
114
- const js = JSON.parse(err.message);
115
- return js;
116
- },
117
- errorTotext(e) {
118
- const j = JSON.parse(e.message);
119
- return `Errore:
120
- Stato: ${j.status}
121
- Descrizione stato: ${j.statusText}
122
- Tipo di errore: ${j.errorType}
123
- Messaggio: ${j.message}`;
124
- },
125
-
126
- // documenti => risposte RAG => context
127
  async requestDocsRAG(query) {
128
  DataMgr.deleteJsonDati();
129
  DataMgr.readDbDocNames();
@@ -161,7 +147,7 @@ const Rag = {
161
  text = await HfRequest.post(payload);
162
  if (!text) return "";
163
  } catch (err) {
164
- const e = this.errorInfo(err);
165
  if (e.errorType === ERROR_TOKENS) {
166
  UaLog.log(`Error tokens.1 ${lft.length}`);
167
  xerror(`Error tokens. ${prompt.length}`);
@@ -169,13 +155,14 @@ const Rag = {
169
  continue;
170
  } else {
171
  xerror(err);
172
- const s = this.errorTotext(err);
173
  throw s;
174
  }
175
  }
176
 
177
  npart++;
178
  doc = rgt;
 
179
  const docText = `<<<${doc_name}>>>\n${text}`; //TODO
180
  this.responses.push(docText);
181
  // this.ragLog(`${doc_name} ${ndoc},${npart}`, lft.length, rgt.length);
@@ -201,8 +188,8 @@ const Rag = {
201
  text = await HfRequest.post(payload);
202
  if (!text) return "";
203
  } catch (err) {
204
- const e = this.errorInfo(err);
205
- const s = this.errorTotext(err);
206
  if (e.errorType === ERROR_TOKENS) {
207
  xerror(err);
208
  throw s;
@@ -252,7 +239,7 @@ const Rag = {
252
  text = await HfRequest.post(payload);
253
  if (!text) return "";
254
  } catch (err) {
255
- const e = this.errorInfo(err);
256
  if (e.errorType === ERROR_TOKENS) {
257
  UaLog.log(`Error tokens.4 ${prompt.length}`);
258
  xerror(err);
@@ -292,7 +279,7 @@ const Rag = {
292
  text = await HfRequest.post(payload);
293
  if (!text) return "";
294
  } catch (err) {
295
- const e = this.errorInfo(err);
296
  if (e.errorType === ERROR_TOKENS) {
297
  UaLog.log(`Error tokens.5 ${prompt.length}`);
298
  xerror(`Error tokens. ${prompt.length}`);
@@ -337,7 +324,7 @@ const ThreadMgr = {
337
  add(query, resp) {
338
  const row = [query, resp];
339
  this.rows.push(row);
340
- UaDb.saveArray("id_thread", ThreadMgr.rows);
341
  },
342
  getOutText() {
343
  const rows = [];
 
18
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
  */
20
  "use strict";
21
+ const MAX_PROMPT_LENGTH = 1024 * 80;
22
  // decremento dopo errore per tokens eccessivi
23
  const PROMPT_DECR = 1024 * 2;
24
 
 
43
  ragquery: this.ragQuery,
44
  ragresponse: this.ragResponse,
45
  };
46
+ UaDb.saveJson(ID_RAG, js);
47
+ UaDb.saveArray(ID_THREAD, ThreadMgr.rows);
48
  },
49
  readFromDb() {
50
+ const js = UaDb.readJson(ID_RAG);
51
  this.ragContext = js.context || "";
52
  this.ragQuery = js.ragquery || "";
53
  this.ragResponse = js.ragresponse || "";
54
+ ThreadMgr.rows = UaDb.readArray(ID_THREAD);
55
  },
56
  saveRespToDb() {
57
+ UaDb.saveArray(ID_RESPONSES, this.responses);
58
  },
59
  readRespsFromDb() {
60
+ this.responses = UaDb.readArray(ID_RESPONSES);
61
  },
62
  addPrompt(p) {
63
  this.prompts.push(p);
 
109
  pRgt = pRgt.substring(partSize).trim();
110
  return [pLft, pRgt];
111
  },
112
+ // documenti => risposte RAG => context
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  async requestDocsRAG(query) {
114
  DataMgr.deleteJsonDati();
115
  DataMgr.readDbDocNames();
 
147
  text = await HfRequest.post(payload);
148
  if (!text) return "";
149
  } catch (err) {
150
+ const e = errorInfo(err);
151
  if (e.errorType === ERROR_TOKENS) {
152
  UaLog.log(`Error tokens.1 ${lft.length}`);
153
  xerror(`Error tokens. ${prompt.length}`);
 
155
  continue;
156
  } else {
157
  xerror(err);
158
+ const s = errorToText(err);
159
  throw s;
160
  }
161
  }
162
 
163
  npart++;
164
  doc = rgt;
165
+ text = cleanResponse(text); //TODO
166
  const docText = `<<<${doc_name}>>>\n${text}`; //TODO
167
  this.responses.push(docText);
168
  // this.ragLog(`${doc_name} ${ndoc},${npart}`, lft.length, rgt.length);
 
188
  text = await HfRequest.post(payload);
189
  if (!text) return "";
190
  } catch (err) {
191
+ const e = errorInfo(err);
192
+ const s = errorToText(err);
193
  if (e.errorType === ERROR_TOKENS) {
194
  xerror(err);
195
  throw s;
 
239
  text = await HfRequest.post(payload);
240
  if (!text) return "";
241
  } catch (err) {
242
+ const e = errorInfo(err);
243
  if (e.errorType === ERROR_TOKENS) {
244
  UaLog.log(`Error tokens.4 ${prompt.length}`);
245
  xerror(err);
 
279
  text = await HfRequest.post(payload);
280
  if (!text) return "";
281
  } catch (err) {
282
+ const e = errorInfo(err);
283
  if (e.errorType === ERROR_TOKENS) {
284
  UaLog.log(`Error tokens.5 ${prompt.length}`);
285
  xerror(`Error tokens. ${prompt.length}`);
 
324
  add(query, resp) {
325
  const row = [query, resp];
326
  this.rows.push(row);
327
+ UaDb.saveArray(ID_THREAD, ThreadMgr.rows);
328
  },
329
  getOutText() {
330
  const rows = [];
static/javascript/rag_prompts.js CHANGED
@@ -8,16 +8,16 @@ SYSTEM:
8
  Sei un assistente AI specializzato nell'analisi di documenti. Rispondi sempre in italiano.
9
 
10
  TASK:
11
- Analizzare il documento ${docName} ed estrarre le informazioni rilevanti per rispondere alla domanda fornita.
12
 
13
  INSTRUCTIONS:
14
- 1. Analizza attentamente il documento.
15
- 2. Identifica le informazioni pertinenti alla domanda.
16
- 3. Estrai i concetti chiave e fai inferenze ragionevoli.
17
- 4. Organizza le informazioni in modo logico.
18
- 5. Prepara una risposta completa ma concisa.
19
- 6. Includi un'introduzione breve, sviluppa l'analisi, presenta le inferenze e concludi con una sintesi.
20
- 7. Cita il documento quando é utile per chiarire informazioni o inferenze.
21
  8. Mantieni un tono oggettivo e uno stile fluido e coerente.
22
 
23
  DOCUMENT:
@@ -29,13 +29,10 @@ QUESTION:
29
  ${domanda}
30
 
31
  OUTPUT_FORMAT:
32
- - Inizia la tua risposta direttamente con il contenuto, senza etichette o introduzioni.
33
- - Fornisci la tua risposta come testo continuo diviso in paragrafi.
34
- - Non usare elenchi puntati o numerati.
35
- - Evita qualsiasi tipo di etichetta o marcatori speciali.
36
 
37
  RESPONSE:
38
- `;
39
  }
40
 
41
  function promptWithContext(contesto, domanda) {
@@ -47,13 +44,13 @@ TASK:
47
  Elaborare la risposta alla domanda sulla base del contesto fornito.
48
 
49
  INSTRUCTIONS:
50
- 1. Analizza attentamente il contesto fornito.
51
- 2. Identifica le informazioni pertinenti alla domanda.
52
- 3. Estrai i concetti chiave e fai inferenze ragionevoli.
53
- 4. Prepara una risposta completa ma concisa.
54
- 5. Struttura la risposta in paragrafi logici.
55
- 6. Includi un'introduzione breve, sviluppa l'analisi, presenta le inferenze e concludi con una sintesi.
56
- 7. Se la domanda richiede di citare le fonti, fai riferimento al documento fornito distinguendolo chiaramente da eventuali altre fonti citate all'interno del documento stesso.
57
  8. Mantieni un tono oggettivo e uno stile fluido e coerente.
58
 
59
  CONTEXT:
@@ -65,21 +62,20 @@ QUESTION:
65
  ${domanda}
66
 
67
  OUTPUT_FORMAT:
68
- - Inizia la tua risposta direttamente con il contenuto, senza etichette o introduzioni.
69
- - Fornisci la tua risposta come testo continuo diviso in paragrafi.
70
- - Evita di usare elenchi puntati o numerati.
71
- - Evita qualsiasi tipo di etichetta o marcatori speciali.
72
 
73
  RESPONSE:
74
- `;
75
  }
76
 
77
-
78
  function promptThread(contesto, conversazione, richiesta) {
79
  return `
80
  SYSTEM:
81
  Sei un assistente AI versatile progettato per gestire conversazioni dinamiche e adattarti a varie richieste. Rispondi sempre in italiano.
82
 
 
 
 
83
  INSTRUCTIONS:
84
  1. Analizza attentamente il contesto, la conversazione precedente e la richiesta attuale.
85
  2. Interpreta l'intento dell'utente senza limitarti a categorie predefinite.
@@ -105,13 +101,10 @@ REQUEST:
105
  ${richiesta}
106
 
107
  OUTPUT_FORMAT:
108
- - Inizia la tua risposta direttamente con il contenuto, senza etichette o introduzioni.
109
- - Fornisci la tua risposta come testo continuo diviso in paragrafi.
110
- - Evita di usare elenchi puntati o numerati.
111
- - Evita qualsiasi tipo di etichetta o marcatori speciali.
112
 
113
  RESPONSE:
114
- `;
115
  }
116
 
117
  /*
@@ -175,12 +168,12 @@ function getPayloadDoc(prompt) {
175
  task: "text2text-generation",
176
  max_new_tokens: 1024,
177
  num_return_sequences: 1,
178
- temperature: 0.6,
179
  top_k: 50,
180
  top_p: 0.7,
181
- do_sample: true,
182
  no_repeat_ngram_size: 4,
183
- num_beams: 5,
184
  repetition_penalty: 1.4,
185
  return_full_text: false,
186
  details: false,
@@ -195,17 +188,18 @@ function getPayloadDoc(prompt) {
195
  return payload;
196
  }
197
 
 
198
  function getPayloadWithContext(prompt) {
199
  const payload = {
200
  inputs: prompt,
201
  parameters: {
202
- task: "text-generation",
203
- max_new_tokens: 1024,
204
  num_return_sequences: 1,
205
  temperature: 0.6,
206
  top_k: 50,
207
  top_p: 0.7,
208
- do_sample: true,
209
  no_repeat_ngram_size: 4,
210
  num_beams: 5,
211
  repetition_penalty: 1.4,
@@ -226,14 +220,14 @@ function getPayloadThread(prompt) {
226
  const payload = {
227
  inputs: prompt,
228
  parameters: {
229
- task: "text-generation",
230
- max_new_tokens: 1024,
231
  num_return_sequences: 1,
232
  temperature: 0.6,
233
  top_k: 50,
234
  top_p: 0.7,
235
- do_sample: true,
236
- no_repeat_ngram_size: 43,
237
  num_beams: 5,
238
  repetition_penalty: 1.4,
239
  return_full_text: false,
 
8
  Sei un assistente AI specializzato nell'analisi di documenti. Rispondi sempre in italiano.
9
 
10
  TASK:
11
+ Analizzare il documento ${docName} compreso fra <<<BEGIN_DOCUMENT>>> e <<<ED_DOCUENT>>> ed estrarre le informazioni rilevanti per rispondere alla domanda fornita.
12
 
13
  INSTRUCTIONS:
14
+ 1. Analizza attentamente il documento e identifica le informazioni pertinenti alla domanda.
15
+ 2. Estrai i concetti chiave e fai inferenze ragionevoli.
16
+ 3 Organizza le informazioni in modo logico.
17
+ 4. Prepara una risposta completa.
18
+ 5. Includi un'introduzione breve, sviluppa l'analisi, presenta le inferenze e concludi con una sintesi.
19
+ 6. Cita le fonti quando è utile per chiarire informazioni o inferenze.
20
+ 7. Assicurati che la risposta sia interamente in italiano, traduci in italiano se nel testo è usata un'altra lingua
21
  8. Mantieni un tono oggettivo e uno stile fluido e coerente.
22
 
23
  DOCUMENT:
 
29
  ${domanda}
30
 
31
  OUTPUT_FORMAT:
32
+ Rispondi con un testo continuo suddiviso in paragrafi. Inizia direttamente con il contenuto. Non usare etichette, introduzioni, elenchi o marcatori speciali.
 
 
 
33
 
34
  RESPONSE:
35
+ `;
36
  }
37
 
38
  function promptWithContext(contesto, domanda) {
 
44
  Elaborare la risposta alla domanda sulla base del contesto fornito.
45
 
46
  INSTRUCTIONS:
47
+ 1. Analizza attentamente il documento e identifica le informazioni pertinenti alla domanda.
48
+ 2. Estrai i concetti chiave e fai inferenze ragionevoli.
49
+ 3. Prepara una risposta chiara e completa.
50
+ 4. Struttura la risposta in paragrafi logici.
51
+ 5. Includi un'introduzione breve, sviluppa l'analisi, presenta le inferenze e concludi con una sintesi.
52
+ 6. Se la domanda richiede di citare le fonti, fai riferimento al documento fornito distinguendolo chiaramente da eventuali altre fonti citate all'interno del documento stesso.
53
+ 7. Assicurati che la risposta sia interamente in italiano, traduci in italiano se nel testo è usata un'altra lingua
54
  8. Mantieni un tono oggettivo e uno stile fluido e coerente.
55
 
56
  CONTEXT:
 
62
  ${domanda}
63
 
64
  OUTPUT_FORMAT:
65
+ Rispondi con un testo continuo suddiviso in paragrafi. Inizia direttamente con il contenuto. Non usare etichette, introduzioni, elenchi o marcatori speciali.
 
 
 
66
 
67
  RESPONSE:
68
+ `;
69
  }
70
 
 
71
  function promptThread(contesto, conversazione, richiesta) {
72
  return `
73
  SYSTEM:
74
  Sei un assistente AI versatile progettato per gestire conversazioni dinamiche e adattarti a varie richieste. Rispondi sempre in italiano.
75
 
76
+ TASK:
77
+ Elaborare la risposta alla domanda sulla base del contesto fornito e della conversazione.
78
+
79
  INSTRUCTIONS:
80
  1. Analizza attentamente il contesto, la conversazione precedente e la richiesta attuale.
81
  2. Interpreta l'intento dell'utente senza limitarti a categorie predefinite.
 
101
  ${richiesta}
102
 
103
  OUTPUT_FORMAT:
104
+ Rispondi con un testo continuo suddiviso in paragrafi. Inizia direttamente con il contenuto. Non usare etichette, introduzioni, elenchi o marcatori speciali.
 
 
 
105
 
106
  RESPONSE:
107
+ `;
108
  }
109
 
110
  /*
 
168
  task: "text2text-generation",
169
  max_new_tokens: 1024,
170
  num_return_sequences: 1,
171
+ temperature: 0.4,
172
  top_k: 50,
173
  top_p: 0.7,
174
+ do_sample: false,
175
  no_repeat_ngram_size: 4,
176
+ num_beams: 4,
177
  repetition_penalty: 1.4,
178
  return_full_text: false,
179
  details: false,
 
188
  return payload;
189
  }
190
 
191
+
192
  function getPayloadWithContext(prompt) {
193
  const payload = {
194
  inputs: prompt,
195
  parameters: {
196
+ task: "text2text-generation",
197
+ max_new_tokens: 2048,
198
  num_return_sequences: 1,
199
  temperature: 0.6,
200
  top_k: 50,
201
  top_p: 0.7,
202
+ do_sample: false,
203
  no_repeat_ngram_size: 4,
204
  num_beams: 5,
205
  repetition_penalty: 1.4,
 
220
  const payload = {
221
  inputs: prompt,
222
  parameters: {
223
+ task: "text2text-generation",
224
+ max_new_tokens: 2048,
225
  num_return_sequences: 1,
226
  temperature: 0.6,
227
  top_k: 50,
228
  top_p: 0.7,
229
+ do_sample: false,
230
+ no_repeat_ngram_size: 4,
231
  num_beams: 5,
232
  repetition_penalty: 1.4,
233
  return_full_text: false,
static/javascript/rag_rqs.js CHANGED
@@ -19,7 +19,7 @@
19
  */
20
 
21
  "use strict";
22
- const VERS = "0.1.40 (28-07-2024)";
23
 
24
  var xlog = console.log;
25
  var xerror = console.error;
@@ -113,7 +113,7 @@ function showThread(e) {
113
  function elencoRisposte(e) {
114
  let rs = [...Rag.responses];
115
  if (rs.length == 0) {
116
- rs = UaDb.readArray("id_responses");
117
  }
118
  if (rs.length == 0) return;
119
  const text = rs
 
19
  */
20
 
21
  "use strict";
22
+ const VERS = "0.1.41 (07-08-2024)";
23
 
24
  var xlog = console.log;
25
  var xerror = console.error;
 
113
  function elencoRisposte(e) {
114
  let rs = [...Rag.responses];
115
  if (rs.length == 0) {
116
+ rs = UaDb.readArray(ID_RESPONSES);
117
  }
118
  if (rs.length == 0) return;
119
  const text = rs
static/js/ragrqs.min.js CHANGED
@@ -1,17 +1,22 @@
1
- const removeChars=a=>{a=a.replace(/[\u00AD\u200B\u200C\u200D\u2060\uFEFF]/g,"");return a=Array.from(a).filter(b=>!/^C/.test(b.codePointAt(0))).join("")},replaceChars=a=>{a=a.replace(/[\u00A0\u2000-\u200A\u202F\u205F\u3000\t\r\f\v]/g," ");a=a.replace(/ +/g," ");return a.trim()},removeTag=a=>a=a.replace(/<<<|>>>|<<|>>/g,"");
2
- function cleanDoc(a){try{return a=removeTag(a),a=removeChars(a),a=replaceChars(a),a=a.replace(/\n/g," "),a=a.replace(/\t/g," "),a=a.replace(/ +/g," "),a=a.replace(/\n\s*\n/g,"\n"),a=a.replace(/[\u201c\u201d]/g,'"'),a=a.replace(/[\u2018\u2019]/g,"'"),a=a.replace(/[\u00ab\u00bb\u201e\u201c]/g,'"'),a=a.replace(/[\u2013\u2014]/g,"-"),a=a.replace(/\\[nrt]/g,""),a=a.replace(/[^\w\s\u00e0\u00e8\u00e9\u00ec\u00f2\u00f9\u00c0\u00c8\u00c9\u00cc\u00d2\u00d9\u00e1\u00e9\u00ed\u00f3\u00fa\u00c1\u00c9\u00cd\u00d3\u00da\u00e4\u00eb\u00ef\u00f6\u00fc\u00c4\u00cb\u00cf\u00d6\u00dc\u00e2\u00ea\u00ee\u00f4\u00fb\u00c2\u00ca\u00ce\u00d4\u00db\u00e7\u00c7\u00f1\u00d1.,;:!?'"()-]/g,
3
- ""),a.trim()}catch(b){return xerror(b),"Errore di codifica nel documento"}}
4
- function cleanResponse(a){try{return a=removeChars(a),a=replaceChars(a),a=a.replace(/\t/g," "),a=a.replace(/ +/g," "),a=a.replace(/\n\s*\n/g,"\n"),a=a.replace(/[\u201c\u201d]/g,'"'),a=a.replace(/[\u2018\u2019]/g,"'"),a=a.replace(/[\u00ab\u00bb\u201e\u201c]/g,'"'),a=a.replace(/[\u2013\u2014]/g,"-"),a=a.replace(/\\[nrt]/g,""),a=a.replace(/[^\w\s\u00e0\u00e8\u00e9\u00ec\u00f2\u00f9\u00c0\u00c8\u00c9\u00cc\u00d2\u00d9\u00e1\u00e9\u00ed\u00f3\u00fa\u00c1\u00c9\u00cd\u00d3\u00da\u00e4\u00eb\u00ef\u00f6\u00fc\u00c4\u00cb\u00cf\u00d6\u00dc\u00e2\u00ea\u00ee\u00f4\u00fb\u00c2\u00ca\u00ce\u00d4\u00db\u00e7\u00c7\u00f1\u00d1.,;:!?'"()-]/g,""),
5
- a.trim()}catch(b){return xerror(b),"Errore di codifica nela risposta"}}
6
- function cleanOutput(a){try{return a=removeChars(a),a=replaceChars(a),a=a.replace(/\t/g," "),a=a.replace(/ +/g," "),a=a.replace(/\n\s*\n/g,"\n"),a=a.replace(/[\u201c\u201d]/g,'"'),a=a.replace(/[\u2018\u2019]/g,"'"),a=a.replace(/[\u00ab\u00bb\u201e\u201c]/g,'"'),a=a.replace(/[\u2013\u2014]/g,"-"),a=a.replace(/\\[nrt]/g,""),a=a.replace(/[^\w\s\u00e0\u00e8\u00e9\u00ec\u00f2\u00f9\u00c0\u00c8\u00c9\u00cc\u00d2\u00d9\u00e1\u00e9\u00ed\u00f3\u00fa\u00c1\u00c9\u00cd\u00d3\u00da\u00e4\u00eb\u00ef\u00f6\u00fc\u00c4\u00cb\u00cf\u00d6\u00dc\u00e2\u00ea\u00ee\u00f4\u00fb\u00c2\u00ca\u00ce\u00d4\u00db\u00e7\u00c7\u00f1\u00d1.,;:!?'"()-]/g,""),
7
- a.trim()}catch(b){return xerror(b),"Errore di codifica nell'output"}}function list2text(a){const b={};for(var c of a){a=(a=c.match(/<<<(.*?)>>>/))?a[1]:null;const d=c.replace(/<<<.*?>>>/,"");b[a]=a in b?b[a]+`\n ${d}`:d}c=[];for(let [d,e]of Object.entries(b))c.push(`Documento: ${d}.\n${e}`);return c.join("\n\n")}function subResponseDOcTag(a){return a.replace(/<<<(.*?)>>>/,(b,c)=>`Documento: ${c}`)};const 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.`)},save(a,b){localStorage.setItem(a,b)},getAllIds(){const a=[];for(let b=0;b<localStorage.length;b++)a.push(localStorage.key(b));
8
- 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){try{const b=await requestGet(a),c=cleanDoc(b),d=this.linkToName(a);this.doc_names.push(d);this.docs.push(c);this.saveDbDocs();return c}catch(b){alert("loadDoc()\n"+b+
9
- "\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")},deleteJsonDati(){const a=UaDb.getAllIds();for(const b of a)["id_docs","id_doc_names"].includes(b)||UaDb.delete(b);Rag.ragQuery="";Rag.ragContext="";Rag.ragResponse="";Rag.responses=[];Rag.prompts=
10
- [];ThreadMgr.rows=[]}};const arr=["bWtkW0l+XX0=","SXx2d1FxbVc=","V1tRXlxneUY=","flV6a1NdbUg=","VllpUkc="],model_name="mistralai/Mistral-7B-Instruct-v0.3",umgm=a=>a.map(b=>atob(b).split("").map(c=>String.fromCharCode((c.charCodeAt(0)-5+256)%256)).join("")).join(""),tm=umgm(arr);
11
- async function requestGet(a){try{var b=await fetch(a,{method:"GET",headers:{"Content-Type":"text/plain;charset=UTF-8"}});if(!b.ok)throw Error(`HTTP error! status: ${b.status}`);const c=await b.arrayBuffer();return(new TextDecoder("utf-8")).decode(c)}catch(c){throw xerror(c),b="AbortError"===c.name?"Request was aborted":c.message.includes("HTTP error! status")?c.message:"An error occurred",alert(`requestGet()\nurl: ${a}\n${b}`),c;}}
12
- const ERROR_TOKENS="ERROR_TOKENS",TIMEOUT_ERROR="TIMEOUT_ERROR",HfRequest={controller:null,isCancelled:!1,baseUrl:"https://api-inference.huggingface.co/models",async post(a,b=3E4){this.isCancelled=!1;this.controller=new AbortController;try{const c=setTimeout(()=>{this.controller.abort()},b),d=await fetch(`${this.baseUrl}/${model_name}`,{method:"POST",headers:{Authorization:`Bearer ${tm}`,"Content-Type":"application/json"},body:JSON.stringify(a),signal:this.controller.signal});clearTimeout(c);if(this.isCancelled)return null;
13
  const e=await d.json();if(!d.ok){const g=this.checkError(d.status,e),l=this.createErrorInfo(d.status,d.statusText,e.error,g);throw Error(l);}const f=this.isInvalidResponse(e);if("string"===typeof f){const g=this.createErrorInfo(d.status,d.statusText,e.error,f);throw Error(g);}return e[0].generated_text.trim()}catch(c){if(this.isCancelled)return null;if("AbortError"===c.name)throw a=this.createErrorInfo(0,"Timeout","La richiesta \u00e8 scaduta",TIMEOUT_ERROR),Error(a);throw c;}},cancelRequest(){this.controller&&
14
- (this.isCancelled=!0,this.controller.abort())},checkError(a,b){return 500<=a?"SERVER_ERROR":400<=a&&500>a?"object"===typeof b&&"validation"===b.error_type?b.error.includes("tokens")?ERROR_TOKENS:"ERROR_VALIDATION":"CLIENT_ERROR":"UNKNOWN_ERROR"},isInvalidResponse(a){return a&&Array.isArray(a)&&0!==a.length?a[0].generated_text?null:"MISSING_GENERATED_TEXT":"INVALID_DATA"},createErrorInfo(a,b,c,d){return JSON.stringify({status:a,statusText:b,errorType:d,message:c||"Errore sconosciuto"})}};/*
 
 
 
 
 
15
 
16
  rag_rqs
17
  Copyright (C) 2024 [Il tuo nome]
@@ -29,33 +34,29 @@ const e=await d.json();if(!d.ok){const g=this.checkError(d.status,e),l=this.crea
29
  You should have received a copy of the GNU General Public License
30
  along with this program. If not, see <https://www.gnu.org/licenses/>.
31
  */
32
- const MAX_PROMPT_LENGTH=87040,PROMPT_DECR=2048,Rag={ragContext:"",ragQuery:"",ragResponse:"",responses:[],prompts:[],doc:"",doc_part:"",init(){this.readRespsFromDb();this.readFromDb()},saveToDb(){UaDb.saveJson("id_rag",{context:this.ragContext,ragquery:this.ragQuery,ragresponse:this.ragResponse});UaDb.saveArray("id_thread",ThreadMgr.rows)},readFromDb(){const a=UaDb.readJson("id_rag");this.ragContext=a.context||"";this.ragQuery=a.ragquery||"";this.ragResponse=a.ragresponse||"";ThreadMgr.rows=UaDb.readArray("id_thread")},
33
- saveRespToDb(){UaDb.saveArray("id_responses",this.responses)},readRespsFromDb(){this.responses=UaDb.readArray("id_responses")},addPrompt(a){this.prompts.push(a)},responsesLength(){return this.responses.reduce((a,b)=>a+b.length,0)},ragLog(a,b,c){const d=MAX_PROMPT_LENGTH,e=this.responsesLength();xlog(`${a} mx:${d} lft:${b} rgt:${c} arr:${e}`);UaLog.log(`${a}${"&nbsp;&nbsp;&nbsp;&nbsp;"}${b}${"&nbsp;&nbsp;&nbsp;&nbsp;"}${c}${"&nbsp;&nbsp;&nbsp;&nbsp;"}${e}`)},truncInput(a,b){return a.substring(0,a.length-
34
- b)},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]},errorInfo(a){return JSON.parse(a.message)},errorTotext(a){a=JSON.parse(a.message);return`Errore:
35
- Stato: ${a.status}
36
- Descrizione stato: ${a.statusText}
37
- Tipo di errore: ${a.errorType}
38
- Messaggio: ${a.message}`},async requestDocsRAG(a){DataMgr.deleteJsonDati();DataMgr.readDbDocNames();DataMgr.readDbDocs();this.ragQuery=a;var b=0;try{for(let c=0;c<DataMgr.docs.length;c++){let d=DataMgr.docs[c];if(""==d.trim())continue;const e=DataMgr.doc_names[c],f=d.length;xlog(`${e} (${f}) `);UaLog.log(`${e} (${f}) `);++b;let g=0,l=0,h="",k="",m="";for(;;){let q=this.getPartSize(d,promptDoc("",a),l);if(10>q)break;[k,m]=this.getPartDoc(d,q);this.ragLog(`${b},${g+1}`,k.length,m.length);h=promptDoc(k,
39
- a);const r=getPayloadDoc(h);let n;try{if(n=await HfRequest.post(r),!n)return""}catch(p){if(this.errorInfo(p).errorType===ERROR_TOKENS){UaLog.log(`Error tokens.1 ${k.length}`);xerror(`Error tokens. ${h.length}`);l+=PROMPT_DECR;continue}else throw xerror(p),this.errorTotext(p);}g++;d=m;this.responses.push(`<<<${e}>>>\n${n}`)}}}catch(c){alert("requestDocsRAG(1)\n"+c),xerror(c)}this.ragContext=list2text(this.responses);this.saveToDb();b="";try{let c=promptWithContext(this.ragContext,a);const d=getPayloadWithContext(c);
40
- try{if(b=await HfRequest.post(d),!b)return""}catch(e){this.errorInfo(e);const f=this.errorTotext(e);xerror(e);throw f;}this.ragResponse=b;this.saveRespToDb();ThreadMgr.init();this.saveToDb();UaLog.log(`Risposta (${c.length},${b.length})`)}catch(c){throw b=c,xerror(c),alert("requestDocsRAG(3)\n"+c),c;}finally{return b=cleanOutput(b)}},async requestContext(a){if(!this.ragContext&&!await confirm("Contesto vuoto. Vuoi continuare?"))return"";if(ThreadMgr.isFirst()){var b="";ThreadMgr.init();try{var c=
41
- this.ragContext,d=ThreadMgr.getThread();prompt=promptThread(c,d,a);var e=getPayloadThread(prompt);try{var f=await HfRequest.post(e);if(!f)return""}catch(g){throw this.errorInfo(g).errorType===ERROR_TOKENS?UaLog.log(`Error tokens.4 ${prompt.length}`):alert(g),xerror(g),g;}ThreadMgr.add(a,f);b=ThreadMgr.getOutText();UaLog.log(`Inizio Conversazione (${prompt.length},${f.length})`)}catch(g){throw xerror(g),b=g,g;}finally{return b=cleanOutput(b)}}else{c="";try{b=this.ragContext;let g=ThreadMgr.getThread();
42
- e=d="";for(f=0;;){g=this.truncInput(g,f);d=promptThread(b,g,a);const l=getPayloadThread(d);try{if(e=await HfRequest.post(l),!e)return""}catch(h){const k=this.errorInfo(h);if(k.errorType===ERROR_TOKENS){UaLog.log(`Error tokens.5 ${d.length}`);xerror(`Error tokens. ${d.length}`);f+=PROMPT_DECR;continue}else throw xerror(h),k.errorType;}break}ThreadMgr.add(a,e);c=ThreadMgr.getOutText();UaLog.log(`Conversazione (${d.length},${e.length})`)}catch(g){throw alert("requestContext(2) \n"+g),xerror(g),c=
43
- g,g;}finally{return c=cleanOutput(c)}}}},LLM="Assistant:",USER="User:",ThreadMgr={rows:[],init(){this.rows=[];Rag.ragResponse?this.add(Rag.ragQuery,Rag.ragResponse):this.add("","")},add(a,b){this.rows.push([a,b]);UaDb.saveArray("id_thread",ThreadMgr.rows)},getOutText(){const a=[];for(const b of this.rows){const c=b[0].trim(),d=b[1].trim();a.push(`\n${USER}\n${c}\n${LLM}\n${d}\n\n`)}return a.join("").trim()},getThread(){const a=[];for(const b of this.rows){const c=b[0].trim(),d=b[1].trim();a.push(`${USER}\n${c}\n${LLM}\n${d}\n\n`)}return a.join("").trim()},
44
- isFirst(){return 2>this.rows.length}};function promptDoc(a,b,c){return`
45
  SYSTEM:
46
  Sei un assistente AI specializzato nell'analisi di documenti. Rispondi sempre in italiano.
47
 
48
  TASK:
49
- Analizzare il documento ${c} ed estrarre le informazioni rilevanti per rispondere alla domanda fornita.
50
 
51
  INSTRUCTIONS:
52
- 1. Analizza attentamente il documento.
53
- 2. Identifica le informazioni pertinenti alla domanda.
54
- 3. Estrai i concetti chiave e fai inferenze ragionevoli.
55
- 4. Organizza le informazioni in modo logico.
56
- 5. Prepara una risposta completa ma concisa.
57
- 6. Includi un'introduzione breve, sviluppa l'analisi, presenta le inferenze e concludi con una sintesi.
58
- 7. Cita il documento quando \u00e9 utile per chiarire informazioni o inferenze.
59
  8. Mantieni un tono oggettivo e uno stile fluido e coerente.
60
 
61
  DOCUMENT:
@@ -67,13 +68,10 @@ QUESTION:
67
  ${b}
68
 
69
  OUTPUT_FORMAT:
70
- - Inizia la tua risposta direttamente con il contenuto, senza etichette o introduzioni.
71
- - Fornisci la tua risposta come testo continuo diviso in paragrafi.
72
- - Non usare elenchi puntati o numerati.
73
- - Evita qualsiasi tipo di etichetta o marcatori speciali.
74
 
75
  RESPONSE:
76
- `}function promptWithContext(a,b){return`
77
  SYSTEM:
78
  Sei un assistente AI specializzato nell'analisi e nell'elaborazione di informazioni contestuali. Rispondi sempre in italiano.
79
 
@@ -81,13 +79,13 @@ TASK:
81
  Elaborare la risposta alla domanda sulla base del contesto fornito.
82
 
83
  INSTRUCTIONS:
84
- 1. Analizza attentamente il contesto fornito.
85
- 2. Identifica le informazioni pertinenti alla domanda.
86
- 3. Estrai i concetti chiave e fai inferenze ragionevoli.
87
- 4. Prepara una risposta completa ma concisa.
88
- 5. Struttura la risposta in paragrafi logici.
89
- 6. Includi un'introduzione breve, sviluppa l'analisi, presenta le inferenze e concludi con una sintesi.
90
- 7. Se la domanda richiede di citare le fonti, fai riferimento al documento fornito distinguendolo chiaramente da eventuali altre fonti citate all'interno del documento stesso.
91
  8. Mantieni un tono oggettivo e uno stile fluido e coerente.
92
 
93
  CONTEXT:
@@ -99,16 +97,16 @@ QUESTION:
99
  ${b}
100
 
101
  OUTPUT_FORMAT:
102
- - Inizia la tua risposta direttamente con il contenuto, senza etichette o introduzioni.
103
- - Fornisci la tua risposta come testo continuo diviso in paragrafi.
104
- - Evita di usare elenchi puntati o numerati.
105
- - Evita qualsiasi tipo di etichetta o marcatori speciali.
106
 
107
  RESPONSE:
108
- `}function promptThread(a,b,c){return`
109
  SYSTEM:
110
  Sei un assistente AI versatile progettato per gestire conversazioni dinamiche e adattarti a varie richieste. Rispondi sempre in italiano.
111
 
 
 
 
112
  INSTRUCTIONS:
113
  1. Analizza attentamente il contesto, la conversazione precedente e la richiesta attuale.
114
  2. Interpreta l'intento dell'utente senza limitarti a categorie predefinite.
@@ -134,17 +132,14 @@ REQUEST:
134
  ${c}
135
 
136
  OUTPUT_FORMAT:
137
- - Inizia la tua risposta direttamente con il contenuto, senza etichette o introduzioni.
138
- - Fornisci la tua risposta come testo continuo diviso in paragrafi.
139
- - Evita di usare elenchi puntati o numerati.
140
- - Evita qualsiasi tipo di etichetta o marcatori speciali.
141
 
142
  RESPONSE:
143
- `}function getPayloadDoc(a){return{inputs:a,parameters:{task:"text2text-generation",max_new_tokens:1024,num_return_sequences:1,temperature:.6,top_k:50,top_p:.7,do_sample:!0,no_repeat_ngram_size:4,num_beams:5,repetition_penalty:1.4,return_full_text:!1,details:!1,max_time:90,seed:42},options:{use_cache:!1,wait_for_model:!0}}}
144
- function getPayloadWithContext(a){return{inputs:a,parameters:{task:"text-generation",max_new_tokens:1024,num_return_sequences:1,temperature:.6,top_k:50,top_p:.7,do_sample:!0,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}}}
145
- function getPayloadThread(a){return{inputs:a,parameters:{task:"text-generation",max_new_tokens:1024,num_return_sequences:1,temperature:.6,top_k:50,top_p:.7,do_sample:!0,no_repeat_ngram_size:43,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.40 (28-07-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)};
146
  function openApp(){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}`)}function showRagResponse(a){wnds.wpre.show(`\n${Rag.ragResponse}`)}function showThread(a){a=ThreadMgr.getOutText();wnds.wpre.show(a)}
147
- function elencoRisposte(a){a=[...Rag.responses];0==a.length&&(a=UaDb.readArray("id_responses"));0!=a.length&&(a=a.map((b,c)=>{b=subResponseDOcTag(b);return`\n[${c+1}]\n ${b.trim()}`}).join("\n"),wnds.wpre.show(a))}function showContesto(a){wnds.wpre.show(`${Rag.ragContext}`)}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)}
148
  async function elencoDocs(a){DataMgr.readDbDocNames();a=DataMgr.doc_names.join("\n");wnds.wpre.show(a)}
149
  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}&nbsp;&nbsp;&nbsp;[${f}]`)}a.push("==================");a.push(`Totale num. Parti: ${b}`);a=a.join("\n");wnds.wpre.show(a)}
150
  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)}
 
1
+ const removeChars=a=>a=a.replace(/[\u00AD\u200B\u200C\u200D\u2060\uFEFF]/g,""),replaceChars=a=>a=a.replace(/[\u00A0\u2000-\u200A\u202F\u205F\u3000\t\r\f\v]/g," "),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=removeChars(a),a=replaceChars(a),a=a.replace(/\n\s*\n/g,"\n"),a=a.replace(/\t/g," "),a=a.replace(/\r/g," "),a=a.replace(/\n/g," "),a=a.replace(/\u201c/g,'"'),a=a.replace(/\u201d/g,'"'),a=a.replace(/[^\w\s\u00e0\u00e8\u00e9\u00ec\u00f2\u00f9\u00c0\u00c8\u00c9\u00cc\u00d2\u00d9\u00e1\u00e9\u00ed\u00f3\u00fa\u00c1\u00c9\u00cd\u00d3\u00da\u00e4\u00eb\u00ef\u00f6\u00fc\u00c4\u00cb\u00cf\u00d6\u00dc\u00e2\u00ea\u00ee\u00f4\u00fb\u00c2\u00ca\u00ce\u00d4\u00db\u00e7\u00c7\u00f1\u00d1.,;:!?'"()-]/g,
3
+ ""),a=a.replace(/ +([.,;:!?])/g,"$1"),a=a.replace(/ +/g," "),a.trim()}catch(b){return xerror(b),"Errore di codifica nella risposta"}}
4
+ function cleanResponse(a){try{return a=removeChars(a),a=replaceChars(a),a=a.replace(/\n\s*\n/g,"\n"),a=a.replace(/\t/g," "),a=a.replace(/\r/g," "),a=a.replace(/\n/g," "),a=a.replace(/[^\w\s\u00e0\u00e8\u00e9\u00ec\u00f2\u00f9\u00c0\u00c8\u00c9\u00cc\u00d2\u00d9\u00e1\u00e9\u00ed\u00f3\u00fa\u00c1\u00c9\u00cd\u00d3\u00da\u00e4\u00eb\u00ef\u00f6\u00fc\u00c4\u00cb\u00cf\u00d6\u00dc\u00e2\u00ea\u00ee\u00f4\u00fb\u00c2\u00ca\u00ce\u00d4\u00db\u00e7\u00c7\u00f1\u00d1.,;:!?'"()-]/g,""),a=a.replace(/ +([.,;:!?])/g,
5
+ "$1"),a=a.replace(/ +/g," "),a.trim()}catch(b){return console.error(b),"Errore di codifica nella risposta"}}
6
+ function cleanOutput(a){try{return a=removeChars(a),a=replaceChars(a),a=a.replace(/\t/g," "),a=a.replace(/\n\s*\n/g,"\n"),a=a.replace(/\r/g," "),a=a.replace(/[^\w\s\u00e0\u00e8\u00e9\u00ec\u00f2\u00f9\u00c0\u00c8\u00c9\u00cc\u00d2\u00d9\u00e1\u00e9\u00ed\u00f3\u00fa\u00c1\u00c9\u00cd\u00d3\u00da\u00e4\u00eb\u00ef\u00f6\u00fc\u00c4\u00cb\u00cf\u00d6\u00dc\u00e2\u00ea\u00ee\u00f4\u00fb\u00c2\u00ca\u00ce\u00d4\u00db\u00e7\u00c7\u00f1\u00d1.,;:!?'"()-]/g,""),a=a.replace(/ +/g," "),a.trim()}catch(b){return xerror(b),
7
+ "Errore di codifica nell'output"}}function list2text(a){const b={};for(var c of a){a=(a=c.match(/<<<(.*?)>>>/))?a[1]:null;const d=c.replace(/<<<.*?>>>/,"");b[a]=a in b?b[a]+`\n ${d}`:d}c=[];for(let [d,e]of Object.entries(b))c.push(`Documento: ${d}.\n${e}`);return c.join("\n\n")}function subResponseDOcTag(a){return a.replace(/<<<(.*?)>>>/,(b,c)=>`Documento: ${c}`)};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.`)},
8
+ 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){try{const b=await requestGet(a),c=cleanDoc(b),
9
+ d=this.linkToName(a);this.doc_names.push(d);this.docs.push(c);this.saveDbDocs();return 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)},deleteJsonDati(){const a=UaDb.getAllIds();for(const b of a)[ID_DOCS,ID_DOC_NAMES].includes(b)||
10
+ UaDb.delete(b);Rag.ragQuery="";Rag.ragContext="";Rag.ragResponse="";Rag.responses=[];Rag.prompts=[];ThreadMgr.rows=[]}};const arr=["bWtkW0l+XX0=","SXx2d1FxbVc=","V1tRXlxneUY=","flV6a1NdbUg=","VllpUkc="],model_name="mistralai/Mistral-7B-Instruct-v0.3",umgm=a=>a.map(b=>atob(b).split("").map(c=>String.fromCharCode((c.charCodeAt(0)-5+256)%256)).join("")).join(""),tm=umgm(arr);
11
+ async function requestGet(a){try{var b=await fetch(a,{method:"GET",headers:{"Content-Type":"text/plain;charset=UTF-8"}});if(!b.ok)throw Error(`HTTP error! status: ${b.status}`);const c=await b.arrayBuffer();return(new TextDecoder("utf-8")).decode(c)}catch(c){throw console.error(c),b="AbortError"===c.name?"Request was aborted":c.message.includes("HTTP error! status")?c.message:"An error occurred",alert(`requestGet()\nurl: ${a}\n${b}`),c;}}
12
+ const ERROR_TOKENS="ERROR_TOKENS",TIMEOUT_ERROR="TIMEOUT_ERROR",HfRequest={controller:null,isCancelled:!1,baseUrl:"https://api-inference.huggingface.co/models",async post(a,b=5E4){this.isCancelled=!1;this.controller=new AbortController;try{const c=setTimeout(()=>{this.controller.abort()},b),d=await fetch(`${this.baseUrl}/${model_name}`,{method:"POST",headers:{Authorization:`Bearer ${tm}`,"Content-Type":"application/json"},body:JSON.stringify(a),signal:this.controller.signal});clearTimeout(c);if(this.isCancelled)return null;
13
  const e=await d.json();if(!d.ok){const g=this.checkError(d.status,e),l=this.createErrorInfo(d.status,d.statusText,e.error,g);throw Error(l);}const f=this.isInvalidResponse(e);if("string"===typeof f){const g=this.createErrorInfo(d.status,d.statusText,e.error,f);throw Error(g);}return e[0].generated_text.trim()}catch(c){if(this.isCancelled)return null;if("AbortError"===c.name)throw a=this.createErrorInfo(0,"Timeout","La richiesta \u00e8 scaduta",TIMEOUT_ERROR),Error(a);throw c;}},cancelRequest(){this.controller&&
14
+ (this.isCancelled=!0,this.controller.abort())},checkError(a,b){return 500<=a?"SERVER_ERROR":400<=a&&500>a?"object"===typeof b&&"validation"===b.error_type?b.error.includes("tokens")?ERROR_TOKENS:"ERROR_VALIDATION":"CLIENT_ERROR":"UNKNOWN_ERROR"},isInvalidResponse(a){return a&&Array.isArray(a)&&0!==a.length?a[0].generated_text?null:"MISSING_GENERATED_TEXT":"INVALID_DATA"},createErrorInfo(a,b,c,d){return JSON.stringify({status:a,statusText:b,errorType:d,message:c||"Errore sconosciuto"})}};
15
+ function errorInfo(a){return JSON.parse(a.message)}function errorToText(a){a=JSON.parse(a.message);return`Error:
16
+ Status: ${a.status}
17
+ Status Text: ${a.statusText}
18
+ Error Type: ${a.errorType}
19
+ Message: ${a.message}`};/*
20
 
21
  rag_rqs
22
  Copyright (C) 2024 [Il tuo nome]
 
34
  You should have received a copy of the GNU General Public License
35
  along with this program. If not, see <https://www.gnu.org/licenses/>.
36
  */
37
+ const MAX_PROMPT_LENGTH=81920,PROMPT_DECR=2048,Rag={ragContext:"",ragQuery:"",ragResponse:"",responses:[],prompts:[],doc:"",doc_part:"",init(){this.readRespsFromDb();this.readFromDb()},saveToDb(){UaDb.saveJson(ID_RAG,{context:this.ragContext,ragquery:this.ragQuery,ragresponse:this.ragResponse});UaDb.saveArray(ID_THREAD,ThreadMgr.rows)},readFromDb(){const a=UaDb.readJson(ID_RAG);this.ragContext=a.context||"";this.ragQuery=a.ragquery||"";this.ragResponse=a.ragresponse||"";ThreadMgr.rows=UaDb.readArray(ID_THREAD)},
38
+ saveRespToDb(){UaDb.saveArray(ID_RESPONSES,this.responses)},readRespsFromDb(){this.responses=UaDb.readArray(ID_RESPONSES)},addPrompt(a){this.prompts.push(a)},responsesLength(){return this.responses.reduce((a,b)=>a+b.length,0)},ragLog(a,b,c){const d=MAX_PROMPT_LENGTH,e=this.responsesLength();xlog(`${a} mx:${d} lft:${b} rgt:${c} arr:${e}`);UaLog.log(`${a}${"&nbsp;&nbsp;&nbsp;&nbsp;"}${b}${"&nbsp;&nbsp;&nbsp;&nbsp;"}${c}${"&nbsp;&nbsp;&nbsp;&nbsp;"}${e}`)},truncInput(a,b){return a.substring(0,a.length-
39
+ b)},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]},async requestDocsRAG(a){DataMgr.deleteJsonDati();DataMgr.readDbDocNames();DataMgr.readDbDocs();this.ragQuery=a;var b=0;try{for(let c=0;c<DataMgr.docs.length;c++){let d=DataMgr.docs[c];if(""==d.trim())continue;const e=DataMgr.doc_names[c],f=d.length;xlog(`${e} (${f}) `);UaLog.log(`${e} (${f}) `);
40
+ ++b;let g=0,l=0,h="",k="",n="";for(;;){let q=this.getPartSize(d,promptDoc("",a),l);if(10>q)break;[k,n]=this.getPartDoc(d,q);this.ragLog(`${b},${g+1}`,k.length,n.length);h=promptDoc(k,a);const r=getPayloadDoc(h);let m;try{if(m=await HfRequest.post(r),!m)return""}catch(p){if(errorInfo(p).errorType===ERROR_TOKENS){UaLog.log(`Error tokens.1 ${k.length}`);xerror(`Error tokens. ${h.length}`);l+=PROMPT_DECR;continue}else throw xerror(p),errorToText(p);}g++;d=n;m=cleanResponse(m);this.responses.push(`<<<${e}>>>\n${m}`)}}}catch(c){alert("requestDocsRAG(1)\n"+
41
+ c),xerror(c)}this.ragContext=list2text(this.responses);this.saveToDb();b="";try{let c=promptWithContext(this.ragContext,a);const d=getPayloadWithContext(c);try{if(b=await HfRequest.post(d),!b)return""}catch(e){errorInfo(e);const f=errorToText(e);xerror(e);throw f;}this.ragResponse=b;this.saveRespToDb();ThreadMgr.init();this.saveToDb();UaLog.log(`Risposta (${c.length},${b.length})`)}catch(c){throw b=c,xerror(c),alert("requestDocsRAG(3)\n"+c),c;}finally{return b=cleanOutput(b)}},async requestContext(a){if(!this.ragContext&&
42
+ !await confirm("Contesto vuoto. Vuoi continuare?"))return"";if(ThreadMgr.isFirst()){var b="";ThreadMgr.init();try{var c=this.ragContext,d=ThreadMgr.getThread();prompt=promptThread(c,d,a);var e=getPayloadThread(prompt);try{var f=await HfRequest.post(e);if(!f)return""}catch(g){throw errorInfo(g).errorType===ERROR_TOKENS?UaLog.log(`Error tokens.4 ${prompt.length}`):alert(g),xerror(g),g;}ThreadMgr.add(a,f);b=ThreadMgr.getOutText();UaLog.log(`Inizio Conversazione (${prompt.length},${f.length})`)}catch(g){throw xerror(g),
43
+ b=g,g;}finally{return b=cleanOutput(b)}}else{c="";try{b=this.ragContext;let g=ThreadMgr.getThread();e=d="";for(f=0;;){g=this.truncInput(g,f);d=promptThread(b,g,a);const l=getPayloadThread(d);try{if(e=await HfRequest.post(l),!e)return""}catch(h){const k=errorInfo(h);if(k.errorType===ERROR_TOKENS){UaLog.log(`Error tokens.5 ${d.length}`);xerror(`Error tokens. ${d.length}`);f+=PROMPT_DECR;continue}else throw xerror(h),k.errorType;}break}ThreadMgr.add(a,e);c=ThreadMgr.getOutText();UaLog.log(`Conversazione (${d.length},${e.length})`)}catch(g){throw alert("requestContext(2) \n"+
44
+ g),xerror(g),c=g,g;}finally{return c=cleanOutput(c)}}}},LLM="Assistant:",USER="User:",ThreadMgr={rows:[],init(){this.rows=[];Rag.ragResponse?this.add(Rag.ragQuery,Rag.ragResponse):this.add("","")},add(a,b){this.rows.push([a,b]);UaDb.saveArray(ID_THREAD,ThreadMgr.rows)},getOutText(){const a=[];for(const b of this.rows){const c=b[0].trim(),d=b[1].trim();a.push(`\n${USER}\n${c}\n${LLM}\n${d}\n\n`)}return a.join("").trim()},getThread(){const a=[];for(const b of this.rows){const c=b[0].trim(),d=b[1].trim();
45
+ a.push(`${USER}\n${c}\n${LLM}\n${d}\n\n`)}return a.join("").trim()},isFirst(){return 2>this.rows.length}};function promptDoc(a,b,c){return`
 
 
 
 
46
  SYSTEM:
47
  Sei un assistente AI specializzato nell'analisi di documenti. Rispondi sempre in italiano.
48
 
49
  TASK:
50
+ Analizzare il documento ${c} compreso fra <<<BEGIN_DOCUMENT>>> e <<<ED_DOCUENT>>> ed estrarre le informazioni rilevanti per rispondere alla domanda fornita.
51
 
52
  INSTRUCTIONS:
53
+ 1. Analizza attentamente il documento e identifica le informazioni pertinenti alla domanda.
54
+ 2. Estrai i concetti chiave e fai inferenze ragionevoli.
55
+ 3 Organizza le informazioni in modo logico.
56
+ 4. Prepara una risposta completa.
57
+ 5. Includi un'introduzione breve, sviluppa l'analisi, presenta le inferenze e concludi con una sintesi.
58
+ 6. Cita le fonti quando \u00e8 utile per chiarire informazioni o inferenze.
59
+ 7. Assicurati che la risposta sia interamente in italiano, traduci in italiano se nel testo \u00e8 usata un'altra lingua
60
  8. Mantieni un tono oggettivo e uno stile fluido e coerente.
61
 
62
  DOCUMENT:
 
68
  ${b}
69
 
70
  OUTPUT_FORMAT:
71
+ Rispondi con un testo continuo suddiviso in paragrafi. Inizia direttamente con il contenuto. Non usare etichette, introduzioni, elenchi o marcatori speciali.
 
 
 
72
 
73
  RESPONSE:
74
+ `}function promptWithContext(a,b){return`
75
  SYSTEM:
76
  Sei un assistente AI specializzato nell'analisi e nell'elaborazione di informazioni contestuali. Rispondi sempre in italiano.
77
 
 
79
  Elaborare la risposta alla domanda sulla base del contesto fornito.
80
 
81
  INSTRUCTIONS:
82
+ 1. Analizza attentamente il documento e identifica le informazioni pertinenti alla domanda.
83
+ 2. Estrai i concetti chiave e fai inferenze ragionevoli.
84
+ 3. Prepara una risposta chiara e completa.
85
+ 4. Struttura la risposta in paragrafi logici.
86
+ 5. Includi un'introduzione breve, sviluppa l'analisi, presenta le inferenze e concludi con una sintesi.
87
+ 6. Se la domanda richiede di citare le fonti, fai riferimento al documento fornito distinguendolo chiaramente da eventuali altre fonti citate all'interno del documento stesso.
88
+ 7. Assicurati che la risposta sia interamente in italiano, traduci in italiano se nel testo \u00e8 usata un'altra lingua
89
  8. Mantieni un tono oggettivo e uno stile fluido e coerente.
90
 
91
  CONTEXT:
 
97
  ${b}
98
 
99
  OUTPUT_FORMAT:
100
+ Rispondi con un testo continuo suddiviso in paragrafi. Inizia direttamente con il contenuto. Non usare etichette, introduzioni, elenchi o marcatori speciali.
 
 
 
101
 
102
  RESPONSE:
103
+ `}function promptThread(a,b,c){return`
104
  SYSTEM:
105
  Sei un assistente AI versatile progettato per gestire conversazioni dinamiche e adattarti a varie richieste. Rispondi sempre in italiano.
106
 
107
+ TASK:
108
+ Elaborare la risposta alla domanda sulla base del contesto fornito e della conversazione.
109
+
110
  INSTRUCTIONS:
111
  1. Analizza attentamente il contesto, la conversazione precedente e la richiesta attuale.
112
  2. Interpreta l'intento dell'utente senza limitarti a categorie predefinite.
 
132
  ${c}
133
 
134
  OUTPUT_FORMAT:
135
+ Rispondi con un testo continuo suddiviso in paragrafi. Inizia direttamente con il contenuto. Non usare etichette, introduzioni, elenchi o marcatori speciali.
 
 
 
136
 
137
  RESPONSE:
138
+ `}function getPayloadDoc(a){return{inputs:a,parameters:{task:"text2text-generation",max_new_tokens:1024,num_return_sequences:1,temperature:.4,top_k:50,top_p:.7,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}}}
139
+ function getPayloadWithContext(a){return{inputs:a,parameters:{task:"text2text-generation",max_new_tokens:2048,num_return_sequences:1,temperature:.6,top_k:50,top_p:.7,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}}}
140
+ function getPayloadThread(a){return{inputs:a,parameters:{task:"text2text-generation",max_new_tokens:2048,num_return_sequences:1,temperature:.6,top_k:50,top_p:.7,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.41 (07-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)};
141
  function openApp(){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}`)}function showRagResponse(a){wnds.wpre.show(`\n${Rag.ragResponse}`)}function showThread(a){a=ThreadMgr.getOutText();wnds.wpre.show(a)}
142
+ function elencoRisposte(a){a=[...Rag.responses];0==a.length&&(a=UaDb.readArray(ID_RESPONSES));0!=a.length&&(a=a.map((b,c)=>{b=subResponseDOcTag(b);return`\n[${c+1}]\n ${b.trim()}`}).join("\n"),wnds.wpre.show(a))}function showContesto(a){wnds.wpre.show(`${Rag.ragContext}`)}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)}
143
  async function elencoDocs(a){DataMgr.readDbDocNames();a=DataMgr.doc_names.join("\n");wnds.wpre.show(a)}
144
  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}&nbsp;&nbsp;&nbsp;[${f}]`)}a.push("==================");a.push(`Totale num. Parti: ${b}`);a=a.join("\n");wnds.wpre.show(a)}
145
  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)}
static/less/ragrqs.less CHANGED
@@ -837,6 +837,13 @@ div.menu-h {
837
  font-style: italic;
838
  color: @color3;
839
  }
 
 
 
 
 
 
 
840
  div {
841
  font-family: @fsans;
842
  font-size: @fsize-help;
@@ -928,6 +935,7 @@ div.menu-h {
928
  }
929
  }
930
 
 
931
  //message
932
  @popup-bg-color: #222222;
933
  @popup-text-color: #ffeb3b;
@@ -962,12 +970,13 @@ div.menu-h {
962
 
963
  //////////////// alert
964
  @primary-color: #212121; // Dark primary color
965
- @secondary-color: #37474F; // Dark secondary color
966
- @text-color: #FFFFFF; // Text color
967
  @background-color: #303030; // Background color
968
 
969
  // Style the alert and confirm dialogs
970
- .alert, .confirm {
 
971
  background-color: @background-color !important;
972
  color: @text-color;
973
  padding: 20px;
 
837
  font-style: italic;
838
  color: @color3;
839
  }
840
+ .label {
841
+ margin: 5px 0 5px 10px;
842
+ font-size: @fsize-help;
843
+ font-weight: bold;
844
+ font-style: italic;
845
+ color: @color3;
846
+ }
847
  div {
848
  font-family: @fsans;
849
  font-size: @fsize-help;
 
935
  }
936
  }
937
 
938
+ ///////////////////////////////////////
939
  //message
940
  @popup-bg-color: #222222;
941
  @popup-text-color: #ffeb3b;
 
970
 
971
  //////////////// alert
972
  @primary-color: #212121; // Dark primary color
973
+ @secondary-color: #37474f; // Dark secondary color
974
+ @text-color: #ffffff; // Text color
975
  @background-color: #303030; // Background color
976
 
977
  // Style the alert and confirm dialogs
978
+ .alert,
979
+ .confirm {
980
  background-color: @background-color !important;
981
  color: @text-color;
982
  padding: 20px;
xx.js ADDED
File without changes