Ranked Feedback Instructions
Ask a question and click on the better of the two responses. The better
response will be outlined in green , the worse
response outlined in red . This data will be
automatically fed to RLHF.
- Download Data `,l=N(),o=R("div"),r=R("section"),s=R("div");for(let A=0;A{e.scrollIntoView({behavior:"smooth"})},0)}async function ad(e){const t=await fetch("/chat/ranking_table/update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(t.ok)console.log("response",t);else{const n=await t.text();alert(n)}}function ud(e,t,n){let l,o;ue(e,Il,v=>n(3,o=v));let r="",s="",u=!1;ft(()=>{});const a=async v=>{v.preventDefault(),r=s,n(0,s=""),n(1,u=!0);let w={question:r,up_ranking_answer:"Loading...",low_ranking_answer:"Loading..."};Pe(Il,o=[...o,w],o);const y=await fetch(`/chat/multi_responses/${r}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:r})});if(y.ok){const C=await y.json();w.up_ranking_answer=C.answer[0],w.low_ranking_answer=C.answer[1],Il.update(M=>(M[M.length-1]=w,M))}else{const C=await y.text();alert(C)}n(1,u=!1)};let f=0;setInterval(()=>{n(6,f=(f+1)%4)},200);function c(v,w,y,C){const M=o[y],$={1:"up_ranking_answer",2:"low_ranking_answer"},F={question:M.question,up_ranking_answer:M[$[C]],low_ranking_answer:M[$[C%2+1]]};ad(F),pt(v.currentTarget.parentNode).selectAll("div").style("outline","2px solid var(--red)").style("border","1px solid var(--red)"),pt(v.currentTarget).style("outline","2px solid var(--green)").style("border","1px solid var(--green)")}const d=(v,w,y)=>c(y,v,w,1),g=(v,w,y)=>c(y,v,w,1),p=(v,w,y)=>c(y,v,w,2),m=(v,w,y)=>c(y,v,w,2);function _(){s=this.value,n(0,s)}return e.$$.update=()=>{e.$$.dirty&64&&n(2,l=".".repeat(f).padEnd(3))},[s,u,l,o,a,c,f,d,g,p,m,_]}class fd extends ce{constructor(t){super(),de(this,t,ud,rd,fe,{})}}function fi(e,t,n){const l=e.slice();return l[8]=t[n],l[10]=n,l}function ci(e){let t,n,l,o,r=e[8].name+"",s,u,a,f,c;function d(...g){return e[6](e[8],...g)}return{c(){t=R("label"),n=R("input"),s=H(r),u=N(),h(n,"type","checkbox"),h(n,"id",l=e[8].id),n.checked=o=e[1].has(e[8].name),h(t,"for",a=e[8].id)},m(g,p){T(g,t,p),b(t,n),b(t,s),b(t,u),f||(c=x(n,"change",d),f=!0)},p(g,p){e=g,p&1&&l!==(l=e[8].id)&&h(n,"id",l),p&3&&o!==(o=e[1].has(e[8].name))&&(n.checked=o),p&1&&r!==(r=e[8].name+"")&&K(s,r),p&1&&a!==(a=e[8].id)&&h(t,"for",a)},d(g){g&&P(t),f=!1,c()}}}function cd(e){let t,n,l,o,r,s,u,a,f,c,d,g=e[0],p=[];for(let m=0;mn(1,l=d));let{documents:o=[]}=t,r=!1,s;function u(){n(2,r=!r)}function a(d,g){g.target.checked?l.add(d):l.delete(d),oo.set(new Set(l))}const f=(d,g)=>a(d.name,g);function c(d){et[d?"unshift":"push"](()=>{s=d,n(3,s)})}return e.$$set=d=>{"documents"in d&&n(0,o=d.documents)},e.$$.update=()=>{e.$$.dirty&2&&console.log(l)},[o,l,r,s,u,a,f,c]}let hd=class extends ce{constructor(t){super(),de(this,t,dd,cd,fe,{documents:0})}};function ro(e,t=2){if(e===0)return"0 Bytes";const n=1024,l=t<0?0:t,o=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"],r=Math.floor(Math.log(e)/Math.log(n));return parseFloat((e/Math.pow(n,r)).toFixed(l))+" "+o[r]}function gd(e){let t={who:0,what:0,how:0,why:0,where:0,does:0,can:0,"n/a":0};for(let l=0;l({question:l,count:t[l]}))}function Ca(e){return e.map(t=>{const n=t.question.split(" ").length,l=t.answer.split(" ").length;return{index:t.index,question:+n,answer:+l,vote:t.vote}})}function pd(e,t){e.classList.add("tooltip"),e.setAttribute("tabindex",0);function n(){const o=document.createElement("span");o.textContent=t,o.setAttribute("id","tooltip"),e.appendChild(o),e.addEventListener("mouseleave",l),e.addEventListener("blur",l),e.removeEventListener("mouseenter",n),e.removeEventListener("focus",n)}function l(){e.removeChild(e.querySelector("#tooltip")),e.removeEventListener("mouseleave",l),e.removeEventListener("blur",l),e.addEventListener("mouseenter",n),e.addEventListener("focus",n)}return e.addEventListener("mouseenter",n),e.addEventListener("focus",n),{onDestroy(){e.classList.remove("tooltip"),e.removeEventListener("mouseenter",n),e.removeEventListener("focus",n)}}}function Mn(e,{delay:t=0,duration:n=400,easing:l=Eo,axis:o="y"}={}){const r=getComputedStyle(e),s=+r.opacity,u=o==="y"?"height":"width",a=parseFloat(r[u]),f=o==="y"?["top","bottom"]:["left","right"],c=f.map(w=>`${w[0].toUpperCase()}${w.slice(1)}`),d=parseFloat(r[`padding${c[0]}`]),g=parseFloat(r[`padding${c[1]}`]),p=parseFloat(r[`margin${c[0]}`]),m=parseFloat(r[`margin${c[1]}`]),_=parseFloat(r[`border${c[0]}Width`]),v=parseFloat(r[`border${c[1]}Width`]);return{delay:t,duration:n,easing:l,css:w=>`overflow: hidden;opacity: ${Math.min(w*20,1)*s};${u}: ${w*a}px;padding-${f[0]}: ${w*d}px;padding-${f[1]}: ${w*g}px;margin-${f[0]}: ${w*p}px;margin-${f[1]}: ${w*m}px;border-${f[0]}-width: ${w*_}px;border-${f[1]}-width: ${w*v}px;`}}function Ln(e,{delay:t=0,duration:n=400,easing:l=Eo,start:o=0,opacity:r=0}={}){const s=getComputedStyle(e),u=+s.opacity,a=s.transform==="none"?"":s.transform,f=1-o,c=u*(1-r);return{delay:t,duration:n,easing:l,css:(d,g)=>`
+ Download Data `,l=N(),o=A("div"),r=A("section"),s=A("div");for(let R=0;R{e.scrollIntoView({behavior:"smooth"})},0)}async function ud(e){const t=await fetch("/chat/ranking_table/update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(t.ok)console.log("response",t);else{const n=await t.text();alert(n)}}function fd(e,t,n){let l,o;ue(e,Il,v=>n(3,o=v));let r="",s="",u=!1;ft(()=>{});const a=async v=>{v.preventDefault(),r=s,n(0,s=""),n(1,u=!0);let y={question:r,up_ranking_answer:"Loading...",low_ranking_answer:"Loading..."};Pe(Il,o=[...o,y],o);const w=await fetch(`/chat/multi_responses/${r}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:r})});if(w.ok){const S=await w.json();y.up_ranking_answer=S.answer[0],y.low_ranking_answer=S.answer[1],Il.update(M=>(M[M.length-1]=y,M))}else{const S=await w.text();alert(S)}n(1,u=!1)};let f=0;setInterval(()=>{n(6,f=(f+1)%4)},200);function c(v,y,w,S){const M=o[w],$={1:"up_ranking_answer",2:"low_ranking_answer"},F={question:M.question,up_ranking_answer:M[$[S]],low_ranking_answer:M[$[S%2+1]]};ud(F),pt(v.currentTarget.parentNode).selectAll("div").style("outline","2px solid var(--red)").style("border","1px solid var(--red)"),pt(v.currentTarget).style("outline","2px solid var(--green)").style("border","1px solid var(--green)")}const d=(v,y,w)=>c(w,v,y,1),g=(v,y,w)=>c(w,v,y,1),p=(v,y,w)=>c(w,v,y,2),m=(v,y,w)=>c(w,v,y,2);function _(){s=this.value,n(0,s)}return e.$$.update=()=>{e.$$.dirty&64&&n(2,l=".".repeat(f).padEnd(3))},[s,u,l,o,a,c,f,d,g,p,m,_]}class cd extends ce{constructor(t){super(),de(this,t,fd,sd,fe,{})}}function ci(e,t,n){const l=e.slice();return l[8]=t[n],l[10]=n,l}function di(e){let t,n,l,o,r=e[8].name+"",s,u,a,f,c;function d(...g){return e[6](e[8],...g)}return{c(){t=A("label"),n=A("input"),s=q(r),u=N(),h(n,"type","checkbox"),h(n,"id",l=e[8].id),n.checked=o=e[1].has(e[8].name),h(t,"for",a=e[8].id)},m(g,p){T(g,t,p),b(t,n),b(t,s),b(t,u),f||(c=x(n,"change",d),f=!0)},p(g,p){e=g,p&1&&l!==(l=e[8].id)&&h(n,"id",l),p&3&&o!==(o=e[1].has(e[8].name))&&(n.checked=o),p&1&&r!==(r=e[8].name+"")&&K(s,r),p&1&&a!==(a=e[8].id)&&h(t,"for",a)},d(g){g&&P(t),f=!1,c()}}}function dd(e){let t,n,l,o,r,s,u,a,f,c,d,g=e[0],p=[];for(let m=0;mn(1,l=d));let{documents:o=[]}=t,r=!1,s;function u(){n(2,r=!r)}function a(d,g){g.target.checked?l.add(d):l.delete(d),oo.set(new Set(l))}const f=(d,g)=>a(d.name,g);function c(d){et[d?"unshift":"push"](()=>{s=d,n(3,s)})}return e.$$set=d=>{"documents"in d&&n(0,o=d.documents)},e.$$.update=()=>{e.$$.dirty&2&&console.log(l)},[o,l,r,s,u,a,f,c]}let gd=class extends ce{constructor(t){super(),de(this,t,hd,dd,fe,{documents:0})}};function ro(e,t=2){if(e===0)return"0 Bytes";const n=1024,l=t<0?0:t,o=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"],r=Math.floor(Math.log(e)/Math.log(n));return parseFloat((e/Math.pow(n,r)).toFixed(l))+" "+o[r]}function pd(e){let t={who:0,what:0,how:0,why:0,where:0,does:0,can:0,"n/a":0};for(let l=0;l({question:l,count:t[l]}))}function $a(e){return e.map(t=>{const n=t.question.split(" ").length,l=t.answer.split(" ").length;return{index:t.index,question:+n,answer:+l,vote:t.vote}})}function md(e,t){e.classList.add("tooltip"),e.setAttribute("tabindex",0);function n(){const o=document.createElement("span");o.textContent=t,o.setAttribute("id","tooltip"),e.appendChild(o),e.addEventListener("mouseleave",l),e.addEventListener("blur",l),e.removeEventListener("mouseenter",n),e.removeEventListener("focus",n)}function l(){e.removeChild(e.querySelector("#tooltip")),e.removeEventListener("mouseleave",l),e.removeEventListener("blur",l),e.addEventListener("mouseenter",n),e.addEventListener("focus",n)}return e.addEventListener("mouseenter",n),e.addEventListener("focus",n),{onDestroy(){e.classList.remove("tooltip"),e.removeEventListener("mouseenter",n),e.removeEventListener("focus",n)}}}function Mn(e,{delay:t=0,duration:n=400,easing:l=Eo,axis:o="y"}={}){const r=getComputedStyle(e),s=+r.opacity,u=o==="y"?"height":"width",a=parseFloat(r[u]),f=o==="y"?["top","bottom"]:["left","right"],c=f.map(y=>`${y[0].toUpperCase()}${y.slice(1)}`),d=parseFloat(r[`padding${c[0]}`]),g=parseFloat(r[`padding${c[1]}`]),p=parseFloat(r[`margin${c[0]}`]),m=parseFloat(r[`margin${c[1]}`]),_=parseFloat(r[`border${c[0]}Width`]),v=parseFloat(r[`border${c[1]}Width`]);return{delay:t,duration:n,easing:l,css:y=>`overflow: hidden;opacity: ${Math.min(y*20,1)*s};${u}: ${y*a}px;padding-${f[0]}: ${y*d}px;padding-${f[1]}: ${y*g}px;margin-${f[0]}: ${y*p}px;margin-${f[1]}: ${y*m}px;border-${f[0]}-width: ${y*_}px;border-${f[1]}-width: ${y*v}px;`}}function Ln(e,{delay:t=0,duration:n=400,easing:l=Eo,start:o=0,opacity:r=0}={}){const s=getComputedStyle(e),u=+s.opacity,a=s.transform==="none"?"":s.transform,f=1-o,c=u*(1-r);return{delay:t,duration:n,easing:l,css:(d,g)=>`
transform: ${a} scale(${1-f*g});
opacity: ${u-c*g}
- `}}function md(e){let t;return{c(){t=R("p"),t.textContent="⌄",h(t,"class","svelte-1pk2e1k")},m(n,l){T(n,t,l)},d(n){n&&P(t)}}}function _d(e){let t;return{c(){t=R("p"),t.textContent="⌃",h(t,"class","svelte-1pk2e1k")},m(n,l){T(n,t,l)},d(n){n&&P(t)}}}function di(e){let t,n,l,o,r;return{c(){t=R("div"),n=R("p"),l=H(e[1]),h(n,"class","bold svelte-1pk2e1k"),h(t,"class","source_content svelte-1pk2e1k")},m(s,u){T(s,t,u),b(t,n),b(n,l),r=!0},p(s,u){(!r||u&2)&&K(l,s[1])},i(s){r||(Me(()=>{r&&(o||(o=lt(t,Mn,{},!0)),o.run(1))}),r=!0)},o(s){o||(o=lt(t,Mn,{},!1)),o.run(0),r=!1},d(s){s&&P(t),s&&o&&o.end()}}}function vd(e){let t,n,l,o=e[2]+1+"",r,s,u,a,f,c,d,g,p;function m(y,C){return y[3]?_d:md}let _=m(e),v=_(e),w=e[3]&&di(e);return{c(){t=R("div"),n=R("div"),l=R("p"),r=H(o),s=H(": "),u=H(e[0]),a=N(),v.c(),c=N(),w&&w.c(),h(l,"class","bold svelte-1pk2e1k"),h(n,"class","source_tab svelte-1pk2e1k"),h(t,"class","source svelte-1pk2e1k")},m(y,C){T(y,t,C),b(t,n),b(n,l),b(l,r),b(l,s),b(l,u),b(n,a),v.m(n,null),b(t,c),w&&w.m(t,null),d=!0,g||(p=x(n,"click",e[4]),g=!0)},p(y,[C]){(!d||C&4)&&o!==(o=y[2]+1+"")&&K(r,o),(!d||C&1)&&K(u,y[0]),_!==(_=m(y))&&(v.d(1),v=_(y),v&&(v.c(),v.m(n,null))),y[3]?w?(w.p(y,C),C&8&&V(w,1)):(w=di(y),w.c(),V(w,1),w.m(t,null)):w&&(we(),z(w,1,1,()=>{w=null}),ye())},i(y){d||(Me(()=>{d&&(f||(f=lt(n,Mn,{},!0)),f.run(1))}),V(w),d=!0)},o(y){f||(f=lt(n,Mn,{},!1)),f.run(0),z(w),d=!1},d(y){y&&P(t),v.d(),y&&f&&f.end(),w&&w.d(),g=!1,p()}}}function bd(e,t,n){let{source:l=""}=t,{source_content:o=""}=t,{i:r=0}=t,s=r===0;const u=()=>n(3,s=!s);return e.$$set=a=>{"source"in a&&n(0,l=a.source),"source_content"in a&&n(1,o=a.source_content),"i"in a&&n(2,r=a.i)},[l,o,r,s,u]}class wd extends ce{constructor(t){super(),de(this,t,bd,vd,fe,{source:0,source_content:1,i:2})}}function hi(e,t,n){const l=e.slice();return l[4]=t[n],l[6]=n,l}function gi(e){let t,n,l,o;const r=[Cd,Sd,kd,yd],s=[];function u(a,f){return a[0][0]==="N/A"?0:a[0][0]==="Loading..."?1:a[0][0]==="Not loaded"?2:3}return t=u(e),n=s[t]=r[t](e),{c(){n.c(),l=Se()},m(a,f){s[t].m(a,f),T(a,l,f),o=!0},p(a,f){let c=t;t=u(a),t===c?s[t].p(a,f):(we(),z(s[c],1,1,()=>{s[c]=null}),ye(),n=s[t],n?n.p(a,f):(n=s[t]=r[t](a),n.c()),V(n,1),n.m(l.parentNode,l))},i(a){o||(V(n),o=!0)},o(a){z(n),o=!1},d(a){s[t].d(a),a&&P(l)}}}function yd(e){let t,n,l,o=e[0].length+"",r,s,u,a,f,c,d,g;function p(w,y){return w[2]?Ad:$d}let m=p(e),_=m(e),v=e[2]&&pi(e);return{c(){t=R("div"),n=R("h5"),l=H("📖 Response Sources ("),r=H(o),s=H(")"),u=N(),_.c(),a=N(),v&&v.c(),f=Se(),h(n,"class","bold"),h(t,"class","sources-header svelte-1r759df")},m(w,y){T(w,t,y),b(t,n),b(n,l),b(n,r),b(n,s),b(t,u),_.m(t,null),T(w,a,y),v&&v.m(w,y),T(w,f,y),c=!0,d||(g=x(t,"click",e[3]),d=!0)},p(w,y){(!c||y&1)&&o!==(o=w[0].length+"")&&K(r,o),m!==(m=p(w))&&(_.d(1),_=m(w),_&&(_.c(),_.m(t,null))),w[2]?v?(v.p(w,y),y&4&&V(v,1)):(v=pi(w),v.c(),V(v,1),v.m(f.parentNode,f)):v&&(we(),z(v,1,1,()=>{v=null}),ye())},i(w){c||(V(v),c=!0)},o(w){z(v),c=!1},d(w){w&&P(t),_.d(),w&&P(a),v&&v.d(w),w&&P(f),d=!1,g()}}}function kd(e){let t;return{c(){t=R("h5"),t.textContent="⚠️ No sources loaded",h(t,"class","bold")},m(n,l){T(n,t,l)},p:U,i:U,o:U,d(n){n&&P(t)}}}function Sd(e){let t;return{c(){t=R("h5"),t.textContent="📖 Loading...",h(t,"class","bold")},m(n,l){T(n,t,l)},p:U,i:U,o:U,d(n){n&&P(t)}}}function Cd(e){let t;return{c(){t=R("h5"),t.textContent="⚠️ No Retrieval Sources selected",h(t,"class","bold")},m(n,l){T(n,t,l)},p:U,i:U,o:U,d(n){n&&P(t)}}}function $d(e){let t;return{c(){t=R("span"),t.textContent="⌄"},m(n,l){T(n,t,l)},d(n){n&&P(t)}}}function Ad(e){let t;return{c(){t=R("span"),t.textContent="⌃"},m(n,l){T(n,t,l)},d(n){n&&P(t)}}}function pi(e){let t,n,l=e[0],o=[];for(let s=0;sz(o[s],1,1,()=>{o[s]=null});return{c(){for(let s=0;s{l=null}),ye())},i(o){n||(V(l),n=!0)},o(o){z(l),n=!1},d(o){o&&P(t),l&&l.d()}}}function Md(e,t,n){let{sources:l=[]}=t,{source_content:o=[]}=t,r=!1;const s=()=>n(2,r=!r);return e.$$set=u=>{"sources"in u&&n(0,l=u.sources),"source_content"in u&&n(1,o=u.source_content)},[l,o,r,s]}class Ed extends ce{constructor(t){super(),de(this,t,Md,Rd,fe,{sources:0,source_content:1})}}function _i(e,t,n){const l=e.slice();return l[4]=t[n],l}function vi(e,t,n){const l=e.slice();return l[4]=t[n],l}function bi(e){let t,n,l,o=e[4].label+"",r,s,u,a,f;return{c(){t=R("li"),n=R("span"),l=R("h5"),r=H(o),s=N(),h(l,"class","bold"),h(n,"class","svelte-iwm583"),h(t,"class",u=Qo(e[0]===e[4].value?"active":"")+" svelte-iwm583")},m(c,d){T(c,t,d),b(t,n),b(n,l),b(l,r),b(t,s),a||(f=x(n,"click",function(){Ge(e[3](e[4].value))&&e[3](e[4].value).apply(this,arguments)}),a=!0)},p(c,d){e=c,d&2&&o!==(o=e[4].label+"")&&K(r,o),d&3&&u!==(u=Qo(e[0]===e[4].value?"active":"")+" svelte-iwm583")&&h(t,"class",u)},d(c){c&&P(t),a=!1,f()}}}function wi(e){let t,n,l,o;const r=[e[2]];var s=e[4].component;function u(a){let f={};for(let c=0;c{te(d,1)}),ye()}s?(n=At(s,u()),ne(n.$$.fragment),V(n.$$.fragment,1),ee(n,t,l)):n=null}else s&&n.$set(c)},i(a){o||(n&&V(n.$$.fragment,a),o=!0)},o(a){n&&z(n.$$.fragment,a),o=!1},d(a){a&&P(t),n&&te(n)}}}function yi(e){let t,n,l=e[0]==e[4].value&&wi(e);return{c(){l&&l.c(),t=Se()},m(o,r){l&&l.m(o,r),T(o,t,r),n=!0},p(o,r){o[0]==o[4].value?l?(l.p(o,r),r&3&&V(l,1)):(l=wi(o),l.c(),V(l,1),l.m(t.parentNode,t)):l&&(we(),z(l,1,1,()=>{l=null}),ye())},i(o){n||(V(l),n=!0)},o(o){z(l),n=!1},d(o){l&&l.d(o),o&&P(t)}}}function Fd(e){let t,n,l,o,r=e[1],s=[];for(let c=0;cz(a[c],1,1,()=>{a[c]=null});return{c(){t=R("ul");for(let c=0;c()=>n(0,o=u);return e.$$set=u=>{"items"in u&&n(1,l=u.items),"activeTabValue"in u&&n(0,o=u.activeTabValue),"tabProps"in u&&n(2,r=u.tabProps)},[o,l,r,s]}class Id extends ce{constructor(t){super(),de(this,t,Dd,Fd,fe,{items:1,activeTabValue:0,tabProps:2})}}function ki(e){let t;return{c(){t=H("Press ENTER to autofill with the RAG answer.")},m(n,l){T(n,t,l)},d(n){n&&P(t)}}}function Nd(e){let t,n,l,o,r,s,u,a,f,c,d,g,p,m=e[0].edited_answer===sl&&ki();return{c(){t=R("form"),n=R("textarea"),o=N(),r=R("div"),s=R("div"),m&&m.c(),u=N(),a=R("div"),f=R("button"),f.textContent="Update",c=N(),d=R("button"),d.textContent="Reset",h(n,"placeholder",l=e[0].answer),h(s,"class","note svelte-i9wciy"),h(r,"class","button-container svelte-i9wciy")},m(_,v){T(_,t,v),b(t,n),Ye(n,e[0].edited_answer),e[6](n),b(t,o),b(t,r),b(r,s),m&&m.m(s,null),b(r,u),b(r,a),b(a,f),b(a,c),b(a,d),g||(p=[x(n,"input",e[5]),x(n,"keydown",e[4]),x(f,"click",e[2]),x(d,"click",e[3])],g=!0)},p(_,[v]){v&1&&l!==(l=_[0].answer)&&h(n,"placeholder",l),v&1&&Ye(n,_[0].edited_answer),_[0].edited_answer===sl?m||(m=ki(),m.c(),m.m(s,null)):m&&(m.d(1),m=null)},i:U,o:U,d(_){_&&P(t),e[6](null),m&&m.d(),g=!1,be(p)}}}const sl="";function Pd(e,t,n){let{message:l={}}=t,o;const r=async d=>{const g={id:l.id,new_answer:d},p=await fetch("/chat/rag_table/update_answer",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(g)});if(p.ok)console.log("Answer updated successfully",p),n(0,l.edited_answer=d,l);else{const m=await p.text();alert(m)}},s=d=>{d.preventDefault(),r(l.edited_answer)},u=d=>{d.preventDefault(),r(sl)},a=d=>{d.key=="Enter"&&l.edited_answer===sl&&(d.preventDefault(),console.log("ENTER"),n(0,l.edited_answer=l.answer,l))};ft(function(){o.focus()});function f(){l.edited_answer=this.value,n(0,l)}function c(d){et[d?"unshift":"push"](()=>{o=d,n(1,o)})}return e.$$set=d=>{"message"in d&&n(0,l=d.message)},[l,o,s,u,a,f,c]}class Td extends ce{constructor(t){super(),de(this,t,Pd,Nd,fe,{message:0})}}function Si(e){let t,n,l,o,r,s;return{c(){t=R("div"),n=R("button"),n.textContent="👍",l=N(),o=R("button"),o.textContent="👎",h(n,"class","small-button thumbs-up svelte-1u8cd0w"),h(o,"class","small-button thumbs-down svelte-1u8cd0w"),h(t,"class","feedback-buttons svelte-1u8cd0w")},m(u,a){T(u,t,a),b(t,n),b(t,l),b(t,o),r||(s=[x(n,"click",e[4]),x(o,"click",e[5])],r=!0)},p:U,d(u){u&&P(t),r=!1,be(s)}}}function Od(e){let t,n=e[0].answer+"",l,o,r,s=e[1]&&Si(e);return{c(){t=R("div"),l=H(n),o=N(),s&&s.c(),r=Se()},m(u,a){T(u,t,a),b(t,l),T(u,o,a),s&&s.m(u,a),T(u,r,a)},p(u,[a]){a&1&&n!==(n=u[0].answer+"")&&K(l,n),u[1]?s?s.p(u,a):(s=Si(u),s.c(),s.m(r.parentNode,r)):s&&(s.d(1),s=null)},i:U,o:U,d(u){u&&P(t),u&&P(o),s&&s.d(u),u&&P(r)}}}async function Vd(e){const t=await fetch("/chat/rag_table/update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(t.ok)console.log("response",t);else{const n=await t.text();alert(n)}}function zd(e,t,n){let l;ue(e,qe,c=>n(6,l=c));let{message:o={}}=t,{feedback:r=!1}=t,{index:s=0}=t;function u(c,d,g){const p=l[g];p.vote=d;const m={id:g+1,vote_status:d};Vd(m),pt(c.currentTarget.parentNode).selectAll("button").style("border","3px solid transparent").style("opacity",.65),pt(c.currentTarget).style("border","3px solid var(--black)").style("opacity",1)}const a=c=>u(c,"up",s),f=c=>u(c,"down",s);return e.$$set=c=>{"message"in c&&n(0,o=c.message),"feedback"in c&&n(1,r=c.feedback),"index"in c&&n(2,s=c.index)},[o,r,s,u,a,f]}class Ld extends ce{constructor(t){super(),de(this,t,zd,Od,fe,{message:0,feedback:1,index:2})}}function Ci(e,t,n){const l=e.slice();return l[19]=t[n],l[21]=n,l}function $i(e,t){let n,l,o,r,s,u,a,f,c,d=t[19].question+"",g,p,m,_,v,w,y,C,M,$,F,S,A,k,E,I;return M=new Id({props:{items:t[8],tabProps:{message:t[19],feedback:t[0],index:t[21]}}}),F=new Ed({props:{sources:t[19].source,source_content:t[19].source_content}}),{key:e,first:null,c(){n=R("div"),l=R("div"),o=R("div"),r=N(),s=R("div"),u=R("div"),a=R("h5"),a.textContent="Question:",f=N(),c=R("p"),g=H(d),p=N(),m=R("div"),_=R("p"),_.textContent="ℹ️ Retrieval Sources",w=N(),y=R("div"),C=R("div"),ne(M.$$.fragment),$=N(),ne(F.$$.fragment),S=N(),h(o,"class","avatar"),h(a,"class","bold"),h(_,"class","bold"),h(m,"class","rag-sources svelte-vgv4ev"),h(u,"class","question svelte-vgv4ev"),h(C,"class","answer svelte-vgv4ev"),h(y,"class","answers svelte-vgv4ev"),h(s,"class","message-content svelte-vgv4ev"),h(l,"class","chat-message-center svelte-vgv4ev"),h(n,"class","chat-message svelte-vgv4ev"),this.first=n},m(D,L){T(D,n,L),b(n,l),b(l,o),b(l,r),b(l,s),b(s,u),b(u,a),b(u,f),b(u,c),b(c,g),b(u,p),b(u,m),b(m,_),b(s,w),b(s,y),b(y,C),ee(M,C,null),b(s,$),ee(F,s,null),b(n,S),k=!0,E||(I=[Cn(v=pd.call(null,_,Ai(t[19]))),Cn(A=Hd.call(null,n,t[21]===t[5].length-1))],E=!0)},p(D,L){t=D,(!k||L&32)&&d!==(d=t[19].question+"")&&K(g,d),v&&Ge(v.update)&&L&32&&v.update.call(null,Ai(t[19]));const O={};L&33&&(O.tabProps={message:t[19],feedback:t[0],index:t[21]}),M.$set(O);const B={};L&32&&(B.sources=t[19].source),L&32&&(B.source_content=t[19].source_content),F.$set(B),A&&Ge(A.update)&&L&32&&A.update.call(null,t[21]===t[5].length-1)},i(D){k||(V(M.$$.fragment,D),V(F.$$.fragment,D),k=!0)},o(D){z(M.$$.fragment,D),z(F.$$.fragment,D),k=!1},d(D){D&&P(n),te(M),te(F),E=!1,be(I)}}}function qd(e){let t,n,l,o,r,s,u,a,f,c,d,g,p,m,_=[],v=new Map,w,y,C,M,$,F,S,A,k,E=(e[2]?e[4]:"Send")+"",I,D,L,O,B,j,ae;function pe(Y){e[13](Y)}let W={table:"rag_table"};e[3]!==void 0&&(W.showModal=e[3]),t=new Io({props:W}),et.push(()=>An(t,"showModal",pe));let Q=e[5];const X=Y=>Y[21];for(let Y=0;Y{r&&(o||(o=lt(t,Mn,{},!0)),o.run(1))}),r=!0)},o(s){o||(o=lt(t,Mn,{},!1)),o.run(0),r=!1},d(s){s&&P(t),s&&o&&o.end()}}}function bd(e){let t,n,l,o=e[2]+1+"",r,s,u,a,f,c,d,g,p;function m(w,S){return w[3]?vd:_d}let _=m(e),v=_(e),y=e[3]&&hi(e);return{c(){t=A("div"),n=A("div"),l=A("p"),r=q(o),s=q(": "),u=q(e[0]),a=N(),v.c(),c=N(),y&&y.c(),h(l,"class","bold svelte-1pk2e1k"),h(n,"class","source_tab svelte-1pk2e1k"),h(t,"class","source svelte-1pk2e1k")},m(w,S){T(w,t,S),b(t,n),b(n,l),b(l,r),b(l,s),b(l,u),b(n,a),v.m(n,null),b(t,c),y&&y.m(t,null),d=!0,g||(p=x(n,"click",e[4]),g=!0)},p(w,[S]){(!d||S&4)&&o!==(o=w[2]+1+"")&&K(r,o),(!d||S&1)&&K(u,w[0]),_!==(_=m(w))&&(v.d(1),v=_(w),v&&(v.c(),v.m(n,null))),w[3]?y?(y.p(w,S),S&8&&V(y,1)):(y=hi(w),y.c(),V(y,1),y.m(t,null)):y&&(we(),z(y,1,1,()=>{y=null}),ye())},i(w){d||(Me(()=>{d&&(f||(f=lt(n,Mn,{},!0)),f.run(1))}),V(y),d=!0)},o(w){f||(f=lt(n,Mn,{},!1)),f.run(0),z(y),d=!1},d(w){w&&P(t),v.d(),w&&f&&f.end(),y&&y.d(),g=!1,p()}}}function wd(e,t,n){let{source:l=""}=t,{source_content:o=""}=t,{i:r=0}=t,s=r===0;const u=()=>n(3,s=!s);return e.$$set=a=>{"source"in a&&n(0,l=a.source),"source_content"in a&&n(1,o=a.source_content),"i"in a&&n(2,r=a.i)},[l,o,r,s,u]}class yd extends ce{constructor(t){super(),de(this,t,wd,bd,fe,{source:0,source_content:1,i:2})}}function gi(e,t,n){const l=e.slice();return l[4]=t[n],l[6]=n,l}function pi(e){let t,n,l,o;const r=[$d,Cd,Sd,kd],s=[];function u(a,f){return a[0][0]==="N/A"?0:a[0][0]==="Loading..."?1:a[0][0]==="Not loaded"?2:3}return t=u(e),n=s[t]=r[t](e),{c(){n.c(),l=Se()},m(a,f){s[t].m(a,f),T(a,l,f),o=!0},p(a,f){let c=t;t=u(a),t===c?s[t].p(a,f):(we(),z(s[c],1,1,()=>{s[c]=null}),ye(),n=s[t],n?n.p(a,f):(n=s[t]=r[t](a),n.c()),V(n,1),n.m(l.parentNode,l))},i(a){o||(V(n),o=!0)},o(a){z(n),o=!1},d(a){s[t].d(a),a&&P(l)}}}function kd(e){let t,n,l,o=e[0].length+"",r,s,u,a,f,c,d,g;function p(y,w){return y[2]?Ad:Rd}let m=p(e),_=m(e),v=e[2]&&mi(e);return{c(){t=A("div"),n=A("h5"),l=q("📖 Response Sources ("),r=q(o),s=q(")"),u=N(),_.c(),a=N(),v&&v.c(),f=Se(),h(n,"class","bold"),h(t,"class","sources-header svelte-1r759df")},m(y,w){T(y,t,w),b(t,n),b(n,l),b(n,r),b(n,s),b(t,u),_.m(t,null),T(y,a,w),v&&v.m(y,w),T(y,f,w),c=!0,d||(g=x(t,"click",e[3]),d=!0)},p(y,w){(!c||w&1)&&o!==(o=y[0].length+"")&&K(r,o),m!==(m=p(y))&&(_.d(1),_=m(y),_&&(_.c(),_.m(t,null))),y[2]?v?(v.p(y,w),w&4&&V(v,1)):(v=mi(y),v.c(),V(v,1),v.m(f.parentNode,f)):v&&(we(),z(v,1,1,()=>{v=null}),ye())},i(y){c||(V(v),c=!0)},o(y){z(v),c=!1},d(y){y&&P(t),_.d(),y&&P(a),v&&v.d(y),y&&P(f),d=!1,g()}}}function Sd(e){let t;return{c(){t=A("h5"),t.textContent="⚠️ No sources loaded",h(t,"class","bold")},m(n,l){T(n,t,l)},p:U,i:U,o:U,d(n){n&&P(t)}}}function Cd(e){let t;return{c(){t=A("h5"),t.textContent="📖 Loading...",h(t,"class","bold")},m(n,l){T(n,t,l)},p:U,i:U,o:U,d(n){n&&P(t)}}}function $d(e){let t;return{c(){t=A("h5"),t.textContent="⚠️ No Retrieval Sources selected",h(t,"class","bold")},m(n,l){T(n,t,l)},p:U,i:U,o:U,d(n){n&&P(t)}}}function Rd(e){let t;return{c(){t=A("span"),t.textContent="⌄"},m(n,l){T(n,t,l)},d(n){n&&P(t)}}}function Ad(e){let t;return{c(){t=A("span"),t.textContent="⌃"},m(n,l){T(n,t,l)},d(n){n&&P(t)}}}function mi(e){let t,n,l=e[0],o=[];for(let s=0;sz(o[s],1,1,()=>{o[s]=null});return{c(){for(let s=0;s{l=null}),ye())},i(o){n||(V(l),n=!0)},o(o){z(l),n=!1},d(o){o&&P(t),l&&l.d()}}}function Ed(e,t,n){let{sources:l=[]}=t,{source_content:o=[]}=t,r=!1;const s=()=>n(2,r=!r);return e.$$set=u=>{"sources"in u&&n(0,l=u.sources),"source_content"in u&&n(1,o=u.source_content)},[l,o,r,s]}class Fd extends ce{constructor(t){super(),de(this,t,Ed,Md,fe,{sources:0,source_content:1})}}function vi(e,t,n){const l=e.slice();return l[4]=t[n],l}function bi(e,t,n){const l=e.slice();return l[4]=t[n],l}function wi(e){let t,n,l,o=e[4].label+"",r,s,u,a,f;return{c(){t=A("li"),n=A("span"),l=A("h5"),r=q(o),s=N(),h(l,"class","bold"),h(n,"class","svelte-iwm583"),h(t,"class",u=Qo(e[0]===e[4].value?"active":"")+" svelte-iwm583")},m(c,d){T(c,t,d),b(t,n),b(n,l),b(l,r),b(t,s),a||(f=x(n,"click",function(){Ge(e[3](e[4].value))&&e[3](e[4].value).apply(this,arguments)}),a=!0)},p(c,d){e=c,d&2&&o!==(o=e[4].label+"")&&K(r,o),d&3&&u!==(u=Qo(e[0]===e[4].value?"active":"")+" svelte-iwm583")&&h(t,"class",u)},d(c){c&&P(t),a=!1,f()}}}function yi(e){let t,n,l,o;const r=[e[2]];var s=e[4].component;function u(a){let f={};for(let c=0;c{te(d,1)}),ye()}s?(n=Rt(s,u()),ne(n.$$.fragment),V(n.$$.fragment,1),ee(n,t,l)):n=null}else s&&n.$set(c)},i(a){o||(n&&V(n.$$.fragment,a),o=!0)},o(a){n&&z(n.$$.fragment,a),o=!1},d(a){a&&P(t),n&&te(n)}}}function ki(e){let t,n,l=e[0]==e[4].value&&yi(e);return{c(){l&&l.c(),t=Se()},m(o,r){l&&l.m(o,r),T(o,t,r),n=!0},p(o,r){o[0]==o[4].value?l?(l.p(o,r),r&3&&V(l,1)):(l=yi(o),l.c(),V(l,1),l.m(t.parentNode,t)):l&&(we(),z(l,1,1,()=>{l=null}),ye())},i(o){n||(V(l),n=!0)},o(o){z(l),n=!1},d(o){l&&l.d(o),o&&P(t)}}}function Dd(e){let t,n,l,o,r=e[1],s=[];for(let c=0;cz(a[c],1,1,()=>{a[c]=null});return{c(){t=A("ul");for(let c=0;c()=>n(0,o=u);return e.$$set=u=>{"items"in u&&n(1,l=u.items),"activeTabValue"in u&&n(0,o=u.activeTabValue),"tabProps"in u&&n(2,r=u.tabProps)},[o,l,r,s]}class Nd extends ce{constructor(t){super(),de(this,t,Id,Dd,fe,{items:1,activeTabValue:0,tabProps:2})}}function Si(e){let t;return{c(){t=q("Press ENTER to autofill with the RAG answer.")},m(n,l){T(n,t,l)},d(n){n&&P(t)}}}function Pd(e){let t,n,l,o,r,s,u,a,f,c,d,g,p,m=e[0].edited_answer===sl&&Si();return{c(){t=A("form"),n=A("textarea"),o=N(),r=A("div"),s=A("div"),m&&m.c(),u=N(),a=A("div"),f=A("button"),f.textContent="Update",c=N(),d=A("button"),d.textContent="Reset",h(n,"placeholder",l=e[0].answer),h(s,"class","note svelte-i9wciy"),h(r,"class","button-container svelte-i9wciy")},m(_,v){T(_,t,v),b(t,n),Ye(n,e[0].edited_answer),e[6](n),b(t,o),b(t,r),b(r,s),m&&m.m(s,null),b(r,u),b(r,a),b(a,f),b(a,c),b(a,d),g||(p=[x(n,"input",e[5]),x(n,"keydown",e[4]),x(f,"click",e[2]),x(d,"click",e[3])],g=!0)},p(_,[v]){v&1&&l!==(l=_[0].answer)&&h(n,"placeholder",l),v&1&&Ye(n,_[0].edited_answer),_[0].edited_answer===sl?m||(m=Si(),m.c(),m.m(s,null)):m&&(m.d(1),m=null)},i:U,o:U,d(_){_&&P(t),e[6](null),m&&m.d(),g=!1,be(p)}}}const sl="";function Td(e,t,n){let{message:l={}}=t,o;const r=async d=>{const g={id:l.id,new_answer:d},p=await fetch("/chat/rag_table/update_answer",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(g)});if(p.ok)console.log("Answer updated successfully",p),n(0,l.edited_answer=d,l);else{const m=await p.text();alert(m)}},s=d=>{d.preventDefault(),r(l.edited_answer)},u=d=>{d.preventDefault(),r(sl)},a=d=>{d.key=="Enter"&&l.edited_answer===sl&&(d.preventDefault(),console.log("ENTER"),n(0,l.edited_answer=l.answer,l))};ft(function(){o.focus()});function f(){l.edited_answer=this.value,n(0,l)}function c(d){et[d?"unshift":"push"](()=>{o=d,n(1,o)})}return e.$$set=d=>{"message"in d&&n(0,l=d.message)},[l,o,s,u,a,f,c]}class Od extends ce{constructor(t){super(),de(this,t,Td,Pd,fe,{message:0})}}function Ci(e){let t,n,l,o,r,s;return{c(){t=A("div"),n=A("button"),n.textContent="👍",l=N(),o=A("button"),o.textContent="👎",h(n,"class","small-button thumbs-up svelte-1u8cd0w"),h(o,"class","small-button thumbs-down svelte-1u8cd0w"),h(t,"class","feedback-buttons svelte-1u8cd0w")},m(u,a){T(u,t,a),b(t,n),b(t,l),b(t,o),r||(s=[x(n,"click",e[4]),x(o,"click",e[5])],r=!0)},p:U,d(u){u&&P(t),r=!1,be(s)}}}function Vd(e){let t,n=e[0].answer+"",l,o,r,s=e[1]&&Ci(e);return{c(){t=A("div"),l=q(n),o=N(),s&&s.c(),r=Se()},m(u,a){T(u,t,a),b(t,l),T(u,o,a),s&&s.m(u,a),T(u,r,a)},p(u,[a]){a&1&&n!==(n=u[0].answer+"")&&K(l,n),u[1]?s?s.p(u,a):(s=Ci(u),s.c(),s.m(r.parentNode,r)):s&&(s.d(1),s=null)},i:U,o:U,d(u){u&&P(t),u&&P(o),s&&s.d(u),u&&P(r)}}}async function zd(e){const t=await fetch("/chat/rag_table/update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(t.ok)console.log("response",t);else{const n=await t.text();alert(n)}}function Ld(e,t,n){let l;ue(e,qe,c=>n(6,l=c));let{message:o={}}=t,{feedback:r=!1}=t,{index:s=0}=t;function u(c,d,g){const p=l[g];p.vote=d;const m={id:g+1,vote_status:d};zd(m),pt(c.currentTarget.parentNode).selectAll("button").style("border","3px solid transparent").style("opacity",.65),pt(c.currentTarget).style("border","3px solid var(--black)").style("opacity",1)}const a=c=>u(c,"up",s),f=c=>u(c,"down",s);return e.$$set=c=>{"message"in c&&n(0,o=c.message),"feedback"in c&&n(1,r=c.feedback),"index"in c&&n(2,s=c.index)},[o,r,s,u,a,f]}class qd extends ce{constructor(t){super(),de(this,t,Ld,Vd,fe,{message:0,feedback:1,index:2})}}function $i(e,t,n){const l=e.slice();return l[19]=t[n],l[21]=n,l}function Ri(e,t){let n,l,o,r,s,u,a,f,c,d=t[19].question+"",g,p,m,_,v,y,w,S,M,$,F,C,R,k,E,I;return M=new Nd({props:{items:t[8],tabProps:{message:t[19],feedback:t[0],index:t[21]}}}),F=new Fd({props:{sources:t[19].source,source_content:t[19].source_content}}),{key:e,first:null,c(){n=A("div"),l=A("div"),o=A("div"),r=N(),s=A("div"),u=A("div"),a=A("h5"),a.textContent="Question:",f=N(),c=A("p"),g=q(d),p=N(),m=A("div"),_=A("p"),_.textContent="ℹ️ Retrieval Sources",y=N(),w=A("div"),S=A("div"),ne(M.$$.fragment),$=N(),ne(F.$$.fragment),C=N(),h(o,"class","avatar"),h(a,"class","bold"),h(_,"class","bold"),h(m,"class","rag-sources svelte-vgv4ev"),h(u,"class","question svelte-vgv4ev"),h(S,"class","answer svelte-vgv4ev"),h(w,"class","answers svelte-vgv4ev"),h(s,"class","message-content svelte-vgv4ev"),h(l,"class","chat-message-center svelte-vgv4ev"),h(n,"class","chat-message svelte-vgv4ev"),this.first=n},m(D,L){T(D,n,L),b(n,l),b(l,o),b(l,r),b(l,s),b(s,u),b(u,a),b(u,f),b(u,c),b(c,g),b(u,p),b(u,m),b(m,_),b(s,y),b(s,w),b(w,S),ee(M,S,null),b(s,$),ee(F,s,null),b(n,C),k=!0,E||(I=[Cn(v=md.call(null,_,Ai(t[19]))),Cn(R=Gd.call(null,n,t[21]===t[5].length-1))],E=!0)},p(D,L){t=D,(!k||L&32)&&d!==(d=t[19].question+"")&&K(g,d),v&&Ge(v.update)&&L&32&&v.update.call(null,Ai(t[19]));const O={};L&33&&(O.tabProps={message:t[19],feedback:t[0],index:t[21]}),M.$set(O);const B={};L&32&&(B.sources=t[19].source),L&32&&(B.source_content=t[19].source_content),F.$set(B),R&&Ge(R.update)&&L&32&&R.update.call(null,t[21]===t[5].length-1)},i(D){k||(V(M.$$.fragment,D),V(F.$$.fragment,D),k=!0)},o(D){z(M.$$.fragment,D),z(F.$$.fragment,D),k=!1},d(D){D&&P(n),te(M),te(F),E=!1,be(I)}}}function Hd(e){let t,n,l,o,r,s,u,a,f,c,d,g,p,m,_=[],v=new Map,y,w,S,M,$,F,C,R,k,E=(e[2]?e[4]:"Send")+"",I,D,L,O,B,j,ae;function pe(Y){e[13](Y)}let W={table:"rag_table"};e[3]!==void 0&&(W.showModal=e[3]),t=new Io({props:W}),et.push(()=>Rn(t,"showModal",pe));let Q=e[5];const X=Y=>Y[21];for(let Y=0;Y👍
button. If the response is not satisfactory, click on the
- 👎 button.`,f=N(),c=R("button"),c.textContent="Download Data",d=N(),g=R("div"),p=R("section"),m=R("div");for(let Y=0;Y<_.length;Y+=1)_[Y].c();w=N(),y=R("div"),C=R("div"),ne(M.$$.fragment),$=N(),F=R("form"),S=R("input"),A=N(),k=R("button"),I=H(E),L=N(),O=R("p"),O.textContent="Note - may produce inaccurate information.",h(s,"class","underline bold svelte-vgv4ev"),h(a,"class","svelte-vgv4ev"),h(c,"class","svelte-vgv4ev"),h(r,"class","instructions svelte-vgv4ev"),h(m,"class","chat-log svelte-vgv4ev"),h(p,"class","chatbox svelte-vgv4ev"),h(S,"class","chat-input-textarea svelte-vgv4ev"),h(S,"placeholder","Type Question Here"),h(k,"class",D="btnyousend "+(e[1]===""?"":"active")+" svelte-vgv4ev"),h(k,"type","submit"),h(F,"class","chat-input-form svelte-vgv4ev"),h(C,"class","chat-and-question svelte-vgv4ev"),h(O,"class","message svelte-vgv4ev"),h(y,"class","chat-input-holder svelte-vgv4ev"),h(g,"class","ranked-chat svelte-vgv4ev"),h(o,"class","ranked-feedback-container svelte-vgv4ev")},m(Y,le){ee(t,Y,le),T(Y,l,le),T(Y,o,le),b(o,r),b(r,s),b(r,u),b(r,a),b(r,f),b(r,c),b(o,d),b(o,g),b(g,p),b(p,m);for(let he=0;he<_.length;he+=1)_[he]&&_[he].m(m,null);b(g,w),b(g,y),b(y,C),ee(M,C,null),b(C,$),b(C,F),b(F,S),Ye(S,e[1]),b(F,A),b(F,k),b(k,I),b(y,L),b(y,O),B=!0,j||(ae=[x(c,"click",e[10]),x(S,"input",e[14]),x(F,"submit",e[9])],j=!0)},p(Y,[le]){const he={};!n&&le&8&&(n=!0,he.showModal=Y[3],$n(()=>n=!1)),t.$set(he),le&289&&(Q=Y[5],we(),_=gt(_,le,X,1,Y,Q,v,m,sa,$i,null,Ci),ye());const Vn={};le&64&&(Vn.documents=Y[6]),M.$set(Vn),le&2&&S.value!==Y[1]&&Ye(S,Y[1]),(!B||le&20)&&E!==(E=(Y[2]?Y[4]:"Send")+"")&&K(I,E),(!B||le&2&&D!==(D="btnyousend "+(Y[1]===""?"":"active")+" svelte-vgv4ev"))&&h(k,"class",D)},i(Y){if(!B){V(t.$$.fragment,Y);for(let le=0;le{e.scrollIntoView({behavior:"smooth"})},0)}function Ai(e){return e.rag_sources.length===0?"No Sources":e.rag_sources.join(", ")}function Gd(e,t,n){let l,o,r,s;ue(e,qe,F=>n(5,o=F)),ue(e,oo,F=>n(16,r=F));let{feedback:u=!1}=t,{is_retrieval:a=!1}=t;const f=De([]);ue(e,f,F=>n(6,s=F));let c="",d="",g=!1,p=!1,m=[{label:"Answer",value:1,component:Ld},{label:"Modified Answer",value:2,component:Td}];ft(()=>{v(),_()});async function _(){const S=await(await fetch("/retrieval/file/get")).json();console.log("data",S.files);const k=S.files.map((E,I)=>({id:String(I),name:E.name}));console.log("files",k),Pe(f,s=[...k],s)}async function v(){const A=(await(await fetch("/chat/rag_table/retrieve")).json()).rows;console.log("Got data from db",A);const k=A.map(E=>({id:E[0],question:E[1],answer:E[2],edited_answer:E[3],vote_status:E[4],rag_sources:E[5],source:E[6],source_content:E[7]}));Pe(qe,o=[...k],o)}const w=async F=>{F.preventDefault(),c=d,n(1,d=""),n(2,g=!0);const S=[...r];let A={id:o.length+1,question:c,answer:"Loading...",rag_sources:S,vote_status:"na",source:["Loading..."],source_content:["Loading..."]};Pe(qe,o=[...o,A],o);const k=a?await fetch("/retrieval/new_message",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:c,file_names:S})}):await fetch(`/chat/${c}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:c})});if(k.ok){const E=await k.json();console.log("response data",E),A.answer=E.answer,A.source=E.source,A.source_content=E.source_content,qe.update(I=>(I[I.length-1]=A,I))}else{const E=await k.text();alert(E)}n(2,g=!1)};let y=0;setInterval(()=>{n(12,y=(y+1)%4)},200);function C(){n(3,p=!0)}function M(F){p=F,n(3,p)}function $(){d=this.value,n(1,d)}return e.$$set=F=>{"feedback"in F&&n(0,u=F.feedback),"is_retrieval"in F&&n(11,a=F.is_retrieval)},e.$$.update=()=>{e.$$.dirty&4096&&n(4,l=".".repeat(y).padEnd(3))},[u,d,g,p,l,o,s,f,m,w,C,a,y,M,$]}class Bd extends ce{constructor(t){super(),de(this,t,Gd,qd,fe,{feedback:0,is_retrieval:11})}}function Ri(e){let t,n;return t=new No({props:{is_retrieval:e[1]}}),{c(){ne(t.$$.fragment)},m(l,o){ee(t,l,o),n=!0},p(l,o){const r={};o&2&&(r.is_retrieval=l[1]),t.$set(r)},i(l){n||(V(t.$$.fragment,l),n=!0)},o(l){z(t.$$.fragment,l),n=!1},d(l){te(t,l)}}}function Mi(e){let t,n;return t=new No({props:{feedback:!0,is_retrieval:e[1]}}),{c(){ne(t.$$.fragment)},m(l,o){ee(t,l,o),n=!0},p(l,o){const r={};o&2&&(r.is_retrieval=l[1]),t.$set(r)},i(l){n||(V(t.$$.fragment,l),n=!0)},o(l){z(t.$$.fragment,l),n=!1},d(l){te(t,l)}}}function Ei(e){let t,n;return t=new Bd({props:{feedback:!0,is_retrieval:e[1]}}),{c(){ne(t.$$.fragment)},m(l,o){ee(t,l,o),n=!0},p(l,o){const r={};o&2&&(r.is_retrieval=l[1]),t.$set(r)},i(l){n||(V(t.$$.fragment,l),n=!0)},o(l){z(t.$$.fragment,l),n=!1},d(l){te(t,l)}}}function Fi(e){let t,n,l,o;const r=[xd,jd],s=[];function u(a,f){return a[1]?0:1}return t=u(e),n=s[t]=r[t](e),{c(){n.c(),l=Se()},m(a,f){s[t].m(a,f),T(a,l,f),o=!0},p(a,f){let c=t;t=u(a),t===c?s[t].p(a,f):(we(),z(s[c],1,1,()=>{s[c]=null}),ye(),n=s[t],n?n.p(a,f):(n=s[t]=r[t](a),n.c()),V(n,1),n.m(l.parentNode,l))},i(a){o||(V(n),o=!0)},o(a){z(n),o=!1},d(a){s[t].d(a),a&&P(l)}}}function jd(e){let t,n;return t=new fd({}),{c(){ne(t.$$.fragment)},m(l,o){ee(t,l,o),n=!0},p:U,i(l){n||(V(t.$$.fragment,l),n=!0)},o(l){z(t.$$.fragment,l),n=!1},d(l){te(t,l)}}}function xd(e){let t,n;return t=new No({props:{feedback:!0,is_retrieval:e[1]}}),{c(){ne(t.$$.fragment)},m(l,o){ee(t,l,o),n=!0},p(l,o){const r={};o&2&&(r.is_retrieval=l[1]),t.$set(r)},i(l){n||(V(t.$$.fragment,l),n=!0)},o(l){z(t.$$.fragment,l),n=!1},d(l){te(t,l)}}}function Ud(e){let t,n,l,o,r,s=!e[0]&&Ri(e),u=e[0]==="vote"&&Mi(e),a=e[0]==="rag"&&Ei(e),f=e[0]==="rank"&&Fi(e);return{c(){s&&s.c(),t=N(),u&&u.c(),n=N(),a&&a.c(),l=N(),f&&f.c(),o=Se()},m(c,d){s&&s.m(c,d),T(c,t,d),u&&u.m(c,d),T(c,n,d),a&&a.m(c,d),T(c,l,d),f&&f.m(c,d),T(c,o,d),r=!0},p(c,[d]){c[0]?s&&(we(),z(s,1,1,()=>{s=null}),ye()):s?(s.p(c,d),d&1&&V(s,1)):(s=Ri(c),s.c(),V(s,1),s.m(t.parentNode,t)),c[0]==="vote"?u?(u.p(c,d),d&1&&V(u,1)):(u=Mi(c),u.c(),V(u,1),u.m(n.parentNode,n)):u&&(we(),z(u,1,1,()=>{u=null}),ye()),c[0]==="rag"?a?(a.p(c,d),d&1&&V(a,1)):(a=Ei(c),a.c(),V(a,1),a.m(l.parentNode,l)):a&&(we(),z(a,1,1,()=>{a=null}),ye()),c[0]==="rank"?f?(f.p(c,d),d&1&&V(f,1)):(f=Fi(c),f.c(),V(f,1),f.m(o.parentNode,o)):f&&(we(),z(f,1,1,()=>{f=null}),ye())},i(c){r||(V(s),V(u),V(a),V(f),r=!0)},o(c){z(s),z(u),z(a),z(f),r=!1},d(c){s&&s.d(c),c&&P(t),u&&u.d(c),c&&P(n),a&&a.d(c),c&&P(l),f&&f.d(c),c&&P(o)}}}function Wd(e,t,n){let{feedback:l}=t,{is_retrieval:o}=t;return e.$$set=r=>{"feedback"in r&&n(0,l=r.feedback),"is_retrieval"in r&&n(1,o=r.is_retrieval)},[l,o]}class Xd extends ce{constructor(t){super(),de(this,t,Wd,Ud,fe,{feedback:0,is_retrieval:1})}}function Di(e,t,n){const l=e.slice();return l[2]=t[n],l}function Ii(e){let t,n=e[2]+"",l,o;return{c(){t=R("option"),l=H(n),t.__value=o=e[2],t.value=t.__value},m(r,s){T(r,t,s),b(t,l)},p(r,s){s&1&&n!==(n=r[2]+"")&&K(l,n),s&1&&o!==(o=r[2])&&(t.__value=o,t.value=t.__value)},d(r){r&&P(t)}}}function Yd(e){let t,n=e[0],l=[];for(let o=0;o{const r=await fetch(`/data/${l}`);n(0,o=await r.json())}),e.$$set=r=>{"data_endpoint"in r&&n(1,l=r.data_endpoint)},[o,l]}class Kd extends ce{constructor(t){super(),de(this,t,Qd,Yd,fe,{data_endpoint:1})}}function Qt(e,t){return e==null||t==null?NaN:et?1:e>=t?0:NaN}function Jd(e,t){return e==null||t==null?NaN:te?1:t>=e?0:NaN}function $a(e){let t,n,l;e.length!==2?(t=Qt,n=(u,a)=>Qt(e(u),a),l=(u,a)=>e(u)-a):(t=e===Qt||e===Jd?e:Zd,n=e,l=e);function o(u,a,f=0,c=u.length){if(f>>1;n(u[d],a)<0?f=d+1:c=d}while(f>>1;n(u[d],a)<=0?f=d+1:c=d}while(ff&&l(u[d-1],a)>-l(u[d],a)?d-1:d}return{left:o,center:s,right:r}}function Zd(){return 0}function eh(e){return e===null?NaN:+e}function*th(e,t){if(t===void 0)for(let n of e)n!=null&&(n=+n)>=n&&(yield n);else{let n=-1;for(let l of e)(l=t(l,++n,e))!=null&&(l=+l)>=l&&(yield l)}}const nh=$a(Qt),lh=nh.right;$a(eh).center;const Aa=lh;function oh(e,t){let n=0;if(t===void 0)for(let l of e)l!=null&&(l=+l)>=l&&++n;else{let l=-1;for(let o of e)(o=t(o,++l,e))!=null&&(o=+o)>=o&&++n}return n}function ih(e,t){let n=0,l,o=0,r=0;if(t===void 0)for(let s of e)s!=null&&(s=+s)>=s&&(l=s-o,o+=l/++n,r+=l*(s-o));else{let s=-1;for(let u of e)(u=t(u,++s,e))!=null&&(u=+u)>=u&&(l=u-o,o+=l/++n,r+=l*(u-o))}if(n>1)return r/(n-1)}function rh(e,t){const n=ih(e,t);return n&&Math.sqrt(n)}function _n(e,t){let n,l;if(t===void 0)for(const o of e)o!=null&&(n===void 0?o>=o&&(n=l=o):(n>o&&(n=o),l=r&&(n=l=r):(n>r&&(n=r),l{const l=e(t,n);return l||l===0?l:(e(n,n)===0)-(e(t,t)===0)}}function Ra(e,t){return(e==null||!(e>=e))-(t==null||!(t>=t))||(et?1:0)}var dh=Array.prototype,hh=dh.slice;function Pl(e){return()=>e}const gh=Math.sqrt(50),ph=Math.sqrt(10),mh=Math.sqrt(2);function al(e,t,n){const l=(t-e)/Math.max(0,n),o=Math.floor(Math.log10(l)),r=l/Math.pow(10,o),s=r>=gh?10:r>=ph?5:r>=mh?2:1;let u,a,f;return o<0?(f=Math.pow(10,-o)/s,u=Math.round(e*f),a=Math.round(t*f),u/ft&&--a,f=-f):(f=Math.pow(10,o)*s,u=Math.round(e/f),a=Math.round(t/f),u*ft&&--a),a0))return[];if(e===t)return[e];const l=t=o))return[];const u=r-o+1,a=new Array(u);if(l)if(s<0)for(let f=0;f0?(e=Math.floor(e/o)*o,t=Math.ceil(t/o)*o):o<0&&(e=Math.ceil(e*o)/o,t=Math.floor(t*o)/o),l=o}}function bh(e){return Math.max(1,Math.ceil(Math.log(oh(e))/Math.LN2)+1)}function Ea(){var e=fh,t=_n,n=bh;function l(o){Array.isArray(o)||(o=Array.from(o));var r,s=o.length,u,a,f=new Array(s);for(r=0;r=g)if(C>=g&&t===_n){const $=en(d,g,M);isFinite($)&&($>0?g=(Math.floor(g/$)+1)*$:$<0&&(g=(Math.ceil(g*-$)+1)/-$))}else p.pop()}for(var m=p.length,_=0,v=m;p[_]<=d;)++_;for(;p[v-1]>g;)--v;(_||v0?p[r-1]:d,y.x1=r0)for(r=0;r=l)&&(n=l);else{let l=-1;for(let o of e)(o=t(o,++l,e))!=null&&(n=o)&&(n=o)}return n}function so(e,t){let n;if(t===void 0)for(const l of e)l!=null&&(n>l||n===void 0&&l>=l)&&(n=l);else{let l=-1;for(let o of e)(o=t(o,++l,e))!=null&&(n>o||n===void 0&&o>=o)&&(n=o)}return n}function Fa(e,t,n=0,l=1/0,o){if(t=Math.floor(t),n=Math.floor(Math.max(0,n)),l=Math.floor(Math.min(e.length-1,l)),!(n<=t&&t<=l))return e;for(o=o===void 0?Ra:ch(o);l>n;){if(l-n>600){const a=l-n+1,f=t-n+1,c=Math.log(a),d=.5*Math.exp(2*c/3),g=.5*Math.sqrt(c*d*(a-d)/a)*(f-a/2<0?-1:1),p=Math.max(n,Math.floor(t-f*d/a+g)),m=Math.min(l,Math.floor(t+(a-f)*d/a+g));Fa(e,t,p,m,o)}const r=e[t];let s=n,u=l;for(un(e,n,t),o(e[l],r)>0&&un(e,n,l);s0;)--u}o(e[n],r)===0?un(e,n,u):(++u,un(e,u,l)),u<=t&&(n=u+1),t<=u&&(l=u-1)}return e}function un(e,t,n){const l=e[t];e[t]=e[n],e[n]=l}function wh(e,t,n){if(e=Float64Array.from(th(e,n)),!(!(l=e.length)||isNaN(t=+t))){if(t<=0||l<2)return so(e);if(t>=1)return mt(e);var l,o=(l-1)*t,r=Math.floor(o),s=mt(Fa(e,r).subarray(0,r+1)),u=so(e.subarray(r+1));return s+(u-s)*(o-r)}}function yh(e,t){let n=0,l=0;if(t===void 0)for(let o of e)o!=null&&(o=+o)>=o&&(++n,l+=o);else{let o=-1;for(let r of e)(r=t(r,++o,e))!=null&&(r=+r)>=r&&(++n,l+=r)}if(n)return l/n}function kh(e,t,n){e=+e,t=+t,n=(o=arguments.length)<2?(t=e,e=0,1):o<3?1:+n;for(var l=-1,o=Math.max(0,Math.ceil((t-e)/n))|0,r=new Array(o);++l=1e21?e.toLocaleString("en").replace(/,/g,""):e.toString(10)}function ul(e,t){if((n=(e=t?e.toExponential(t-1):e.toExponential()).indexOf("e"))<0)return null;var n,l=e.slice(0,n);return[l.length>1?l[0]+l.slice(2):l,+e.slice(n+1)]}function tn(e){return e=ul(Math.abs(e)),e?e[1]:NaN}function Ch(e,t){return function(n,l){for(var o=n.length,r=[],s=0,u=e[0],a=0;o>0&&u>0&&(a+u+1>l&&(u=Math.max(1,l-a)),r.push(n.substring(o-=u,o+u)),!((a+=u+1)>l));)u=e[s=(s+1)%e.length];return r.reverse().join(t)}}function $h(e){return function(t){return t.replace(/[0-9]/g,function(n){return e[+n]})}}var Ah=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function fl(e){if(!(t=Ah.exec(e)))throw new Error("invalid format: "+e);var t;return new Po({fill:t[1],align:t[2],sign:t[3],symbol:t[4],zero:t[5],width:t[6],comma:t[7],precision:t[8]&&t[8].slice(1),trim:t[9],type:t[10]})}fl.prototype=Po.prototype;function Po(e){this.fill=e.fill===void 0?" ":e.fill+"",this.align=e.align===void 0?">":e.align+"",this.sign=e.sign===void 0?"-":e.sign+"",this.symbol=e.symbol===void 0?"":e.symbol+"",this.zero=!!e.zero,this.width=e.width===void 0?void 0:+e.width,this.comma=!!e.comma,this.precision=e.precision===void 0?void 0:+e.precision,this.trim=!!e.trim,this.type=e.type===void 0?"":e.type+""}Po.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(this.width===void 0?"":Math.max(1,this.width|0))+(this.comma?",":"")+(this.precision===void 0?"":"."+Math.max(0,this.precision|0))+(this.trim?"~":"")+this.type};function Rh(e){e:for(var t=e.length,n=1,l=-1,o;n0&&(l=0);break}return l>0?e.slice(0,l)+e.slice(o+1):e}var Da;function Mh(e,t){var n=ul(e,t);if(!n)return e+"";var l=n[0],o=n[1],r=o-(Da=Math.max(-8,Math.min(8,Math.floor(o/3)))*3)+1,s=l.length;return r===s?l:r>s?l+new Array(r-s+1).join("0"):r>0?l.slice(0,r)+"."+l.slice(r):"0."+new Array(1-r).join("0")+ul(e,Math.max(0,t+r-1))[0]}function Ti(e,t){var n=ul(e,t);if(!n)return e+"";var l=n[0],o=n[1];return o<0?"0."+new Array(-o).join("0")+l:l.length>o+1?l.slice(0,o+1)+"."+l.slice(o+1):l+new Array(o-l.length+2).join("0")}const Oi={"%":(e,t)=>(e*100).toFixed(t),b:e=>Math.round(e).toString(2),c:e=>e+"",d:Sh,e:(e,t)=>e.toExponential(t),f:(e,t)=>e.toFixed(t),g:(e,t)=>e.toPrecision(t),o:e=>Math.round(e).toString(8),p:(e,t)=>Ti(e*100,t),r:Ti,s:Mh,X:e=>Math.round(e).toString(16).toUpperCase(),x:e=>Math.round(e).toString(16)};function Vi(e){return e}var zi=Array.prototype.map,Li=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function Eh(e){var t=e.grouping===void 0||e.thousands===void 0?Vi:Ch(zi.call(e.grouping,Number),e.thousands+""),n=e.currency===void 0?"":e.currency[0]+"",l=e.currency===void 0?"":e.currency[1]+"",o=e.decimal===void 0?".":e.decimal+"",r=e.numerals===void 0?Vi:$h(zi.call(e.numerals,String)),s=e.percent===void 0?"%":e.percent+"",u=e.minus===void 0?"−":e.minus+"",a=e.nan===void 0?"NaN":e.nan+"";function f(d){d=fl(d);var g=d.fill,p=d.align,m=d.sign,_=d.symbol,v=d.zero,w=d.width,y=d.comma,C=d.precision,M=d.trim,$=d.type;$==="n"?(y=!0,$="g"):Oi[$]||(C===void 0&&(C=12),M=!0,$="g"),(v||g==="0"&&p==="=")&&(v=!0,g="0",p="=");var F=_==="$"?n:_==="#"&&/[boxX]/.test($)?"0"+$.toLowerCase():"",S=_==="$"?l:/[%p]/.test($)?s:"",A=Oi[$],k=/[defgprs%]/.test($);C=C===void 0?6:/[gprs]/.test($)?Math.max(1,Math.min(21,C)):Math.max(0,Math.min(20,C));function E(I){var D=F,L=S,O,B,j;if($==="c")L=A(I)+L,I="";else{I=+I;var ae=I<0||1/I<0;if(I=isNaN(I)?a:A(Math.abs(I),C),M&&(I=Rh(I)),ae&&+I==0&&m!=="+"&&(ae=!1),D=(ae?m==="("?m:u:m==="-"||m==="("?"":m)+D,L=($==="s"?Li[8+Da/3]:"")+L+(ae&&m==="("?")":""),k){for(O=-1,B=I.length;++Oj||j>57){L=(j===46?o+I.slice(O+1):I.slice(O))+L,I=I.slice(0,O);break}}}y&&!v&&(I=t(I,1/0));var pe=D.length+I.length+L.length,W=pe>1)+D+I+L+W.slice(pe);break;default:I=W+D+I+L;break}return r(I)}return E.toString=function(){return d+""},E}function c(d,g){var p=f((d=fl(d),d.type="f",d)),m=Math.max(-8,Math.min(8,Math.floor(tn(g)/3)))*3,_=Math.pow(10,-m),v=Li[8+m/3];return function(w){return p(_*w)+v}}return{format:f,formatPrefix:c}}var qn,vt,Ia;Fh({thousands:",",grouping:[3],currency:["$",""]});function Fh(e){return qn=Eh(e),vt=qn.format,Ia=qn.formatPrefix,qn}function Dh(e){return Math.max(0,-tn(Math.abs(e)))}function Ih(e,t){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(tn(t)/3)))*3-tn(Math.abs(e)))}function Nh(e,t){return e=Math.abs(e),t=Math.abs(t)-e,Math.max(0,tn(t)-tn(e))+1}function To(e,t){switch(arguments.length){case 0:break;case 1:this.range(e);break;default:this.range(t).domain(e);break}return this}function Ph(e,t){switch(arguments.length){case 0:break;case 1:{typeof e=="function"?this.interpolator(e):this.range(e);break}default:{this.domain(e),typeof t=="function"?this.interpolator(t):this.range(t);break}}return this}const qi=Symbol("implicit");function Mt(){var e=new Ni,t=[],n=[],l=qi;function o(r){let s=e.get(r);if(s===void 0){if(l!==qi)return l;e.set(r,s=t.push(r)-1)}return n[s%n.length]}return o.domain=function(r){if(!arguments.length)return t.slice();t=[],e=new Ni;for(const s of r)e.has(s)||e.set(s,t.push(s)-1);return o},o.range=function(r){return arguments.length?(n=Array.from(r),o):n.slice()},o.unknown=function(r){return arguments.length?(l=r,o):l},o.copy=function(){return Mt(t,n).unknown(l)},To.apply(o,arguments),o}function Lt(){var e=Mt().unknown(void 0),t=e.domain,n=e.range,l=0,o=1,r,s,u=!1,a=0,f=0,c=.5;delete e.unknown;function d(){var g=t().length,p=o>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?Hn(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?Hn(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=Oh.exec(e))?new He(t[1],t[2],t[3],1):(t=Vh.exec(e))?new He(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=zh.exec(e))?Hn(t[1],t[2],t[3],t[4]):(t=Lh.exec(e))?Hn(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=qh.exec(e))?Xi(t[1],t[2]/100,t[3]/100,1):(t=Hh.exec(e))?Xi(t[1],t[2]/100,t[3]/100,t[4]):Gi.hasOwnProperty(e)?xi(Gi[e]):e==="transparent"?new He(NaN,NaN,NaN,0):null}function xi(e){return new He(e>>16&255,e>>8&255,e&255,1)}function Hn(e,t,n,l){return l<=0&&(e=t=n=NaN),new He(e,t,n,l)}function jh(e){return e instanceof Nn||(e=Dn(e)),e?(e=e.rgb(),new He(e.r,e.g,e.b,e.opacity)):new He}function ao(e,t,n,l){return arguments.length===1?jh(e):new He(e,t,n,l??1)}function He(e,t,n,l){this.r=+e,this.g=+t,this.b=+n,this.opacity=+l}Oo(He,ao,Pa(Nn,{brighter(e){return e=e==null?cl:Math.pow(cl,e),new He(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?En:Math.pow(En,e),new He(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new He(Vt(this.r),Vt(this.g),Vt(this.b),dl(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:Ui,formatHex:Ui,formatHex8:xh,formatRgb:Wi,toString:Wi}));function Ui(){return`#${Tt(this.r)}${Tt(this.g)}${Tt(this.b)}`}function xh(){return`#${Tt(this.r)}${Tt(this.g)}${Tt(this.b)}${Tt((isNaN(this.opacity)?1:this.opacity)*255)}`}function Wi(){const e=dl(this.opacity);return`${e===1?"rgb(":"rgba("}${Vt(this.r)}, ${Vt(this.g)}, ${Vt(this.b)}${e===1?")":`, ${e})`}`}function dl(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function Vt(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function Tt(e){return e=Vt(e),(e<16?"0":"")+e.toString(16)}function Xi(e,t,n,l){return l<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new Je(e,t,n,l)}function Ta(e){if(e instanceof Je)return new Je(e.h,e.s,e.l,e.opacity);if(e instanceof Nn||(e=Dn(e)),!e)return new Je;if(e instanceof Je)return e;e=e.rgb();var t=e.r/255,n=e.g/255,l=e.b/255,o=Math.min(t,n,l),r=Math.max(t,n,l),s=NaN,u=r-o,a=(r+o)/2;return u?(t===r?s=(n-l)/u+(n0&&a<1?0:s,new Je(s,u,a,e.opacity)}function Uh(e,t,n,l){return arguments.length===1?Ta(e):new Je(e,t,n,l??1)}function Je(e,t,n,l){this.h=+e,this.s=+t,this.l=+n,this.opacity=+l}Oo(Je,Uh,Pa(Nn,{brighter(e){return e=e==null?cl:Math.pow(cl,e),new Je(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?En:Math.pow(En,e),new Je(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,l=n+(n<.5?n:1-n)*t,o=2*n-l;return new He(Tl(e>=240?e-240:e+120,o,l),Tl(e,o,l),Tl(e<120?e+240:e-120,o,l),this.opacity)},clamp(){return new Je(Yi(this.h),Gn(this.s),Gn(this.l),dl(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=dl(this.opacity);return`${e===1?"hsl(":"hsla("}${Yi(this.h)}, ${Gn(this.s)*100}%, ${Gn(this.l)*100}%${e===1?")":`, ${e})`}`}}));function Yi(e){return e=(e||0)%360,e<0?e+360:e}function Gn(e){return Math.max(0,Math.min(1,e||0))}function Tl(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const Vo=e=>()=>e;function Wh(e,t){return function(n){return e+n*t}}function Xh(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(l){return Math.pow(e+l*t,n)}}function Yh(e){return(e=+e)==1?Oa:function(t,n){return n-t?Xh(t,n,e):Vo(isNaN(t)?n:t)}}function Oa(e,t){var n=t-e;return n?Wh(e,n):Vo(isNaN(e)?t:e)}const uo=function e(t){var n=Yh(t);function l(o,r){var s=n((o=ao(o)).r,(r=ao(r)).r),u=n(o.g,r.g),a=n(o.b,r.b),f=Oa(o.opacity,r.opacity);return function(c){return o.r=s(c),o.g=u(c),o.b=a(c),o.opacity=f(c),o+""}}return l.gamma=e,l}(1);function Qh(e,t){t||(t=[]);var n=e?Math.min(t.length,e.length):0,l=t.slice(),o;return function(r){for(o=0;on&&(r=t.slice(n,r),u[s]?u[s]+=r:u[++s]=r),(l=l[0])===(o=o[0])?u[s]?u[s]+=o:u[++s]=o:(u[++s]=null,a.push({i:s,x:hl(l,o)})),n=Ol.lastIndex;return nt&&(n=e,e=t,t=n),function(l){return Math.max(e,Math.min(t,l))}}function sg(e,t,n){var l=e[0],o=e[1],r=t[0],s=t[1];return o2?ag:sg,a=f=null,d}function d(g){return g==null||isNaN(g=+g)?r:(a||(a=u(e.map(l),t,n)))(l(s(g)))}return d.invert=function(g){return s(o((f||(f=u(t,e.map(l),hl)))(g)))},d.domain=function(g){return arguments.length?(e=Array.from(g,ig),c()):e.slice()},d.range=function(g){return arguments.length?(t=Array.from(g),c()):t.slice()},d.rangeRound=function(g){return t=Array.from(g),n=Va,c()},d.clamp=function(g){return arguments.length?(s=g?!0:kt,c()):s!==kt},d.interpolate=function(g){return arguments.length?(n=g,c()):n},d.unknown=function(g){return arguments.length?(r=g,d):r},function(g,p){return l=g,o=p,c()}}function cg(){return fg()(kt,kt)}function dg(e,t,n,l){var o=_h(e,t,n),r;switch(l=fl(l??",f"),l.type){case"s":{var s=Math.max(Math.abs(e),Math.abs(t));return l.precision==null&&!isNaN(r=Ih(o,s))&&(l.precision=r),Ia(l,s)}case"":case"e":case"g":case"p":case"r":{l.precision==null&&!isNaN(r=Nh(o,Math.max(Math.abs(e),Math.abs(t))))&&(l.precision=r-(l.type==="e"));break}case"f":case"%":{l.precision==null&&!isNaN(r=Dh(o))&&(l.precision=r-(l.type==="%")*2);break}}return vt(l)}function za(e){var t=e.domain;return e.ticks=function(n){var l=t();return Ma(l[0],l[l.length-1],n??10)},e.tickFormat=function(n,l){var o=t();return dg(o[0],o[o.length-1],n??10,l)},e.nice=function(n){n==null&&(n=10);var l=t(),o=0,r=l.length-1,s=l[o],u=l[r],a,f,c=10;for(u0;){if(f=en(s,u,n),f===a)return l[o]=s,l[r]=u,t(l);if(f>0)s=Math.floor(s/f)*f,u=Math.ceil(u/f)*f;else if(f<0)s=Math.ceil(s*f)/f,u=Math.floor(u*f)/f;else break;a=f}return e},e}function We(){var e=cg();return e.copy=function(){return ug(e,We())},To.apply(e,arguments),za(e)}function hg(){var e=0,t=1,n,l,o,r,s=kt,u=!1,a;function f(d){return d==null||isNaN(d=+d)?a:s(o===0?.5:(d=(r(d)-n)*o,u?Math.max(0,Math.min(1,d)):d))}f.domain=function(d){return arguments.length?([e,t]=d,n=r(e=+e),l=r(t=+t),o=n===l?0:1/(l-n),f):[e,t]},f.clamp=function(d){return arguments.length?(u=!!d,f):u},f.interpolator=function(d){return arguments.length?(s=d,f):s};function c(d){return function(g){var p,m;return arguments.length?([p,m]=g,s=d(p,m),f):[s(0),s(1)]}}return f.range=c(Pn),f.rangeRound=c(Va),f.unknown=function(d){return arguments.length?(a=d,f):a},function(d){return r=d,n=d(e),l=d(t),o=n===l?0:1/(l-n),f}}function gg(e,t){return t.domain(e.domain()).interpolator(e.interpolator()).clamp(e.clamp()).unknown(e.unknown())}function La(){var e=za(hg()(kt));return e.copy=function(){return gg(e,La())},Ph.apply(e,arguments)}function nt(e){return function(){return e}}const ho=Math.PI,go=2*ho,It=1e-6,pg=go-It;function qa(e){this._+=e[0];for(let t=1,n=e.length;t=0))throw new Error(`invalid digits: ${e}`);if(t>15)return qa;const n=10**t;return function(l){this._+=l[0];for(let o=1,r=l.length;oIt)if(!(Math.abs(d*a-f*c)>It)||!r)this._append`L${this._x1=t},${this._y1=n}`;else{let p=l-s,m=o-u,_=a*a+f*f,v=p*p+m*m,w=Math.sqrt(_),y=Math.sqrt(g),C=r*Math.tan((ho-Math.acos((_+g-v)/(2*w*y)))/2),M=C/y,$=C/w;Math.abs(M-1)>It&&this._append`L${t+M*c},${n+M*d}`,this._append`A${r},${r},0,0,${+(d*p>c*m)},${this._x1=t+$*a},${this._y1=n+$*f}`}}arc(t,n,l,o,r,s){if(t=+t,n=+n,l=+l,s=!!s,l<0)throw new Error(`negative radius: ${l}`);let u=l*Math.cos(o),a=l*Math.sin(o),f=t+u,c=n+a,d=1^s,g=s?o-r:r-o;this._x1===null?this._append`M${f},${c}`:(Math.abs(this._x1-f)>It||Math.abs(this._y1-c)>It)&&this._append`L${f},${c}`,l&&(g<0&&(g=g%go+go),g>pg?this._append`A${l},${l},0,1,${d},${t-u},${n-a}A${l},${l},0,1,${d},${this._x1=f},${this._y1=c}`:g>It&&this._append`A${l},${l},0,${+(g>=ho)},${d},${this._x1=t+l*Math.cos(r)},${this._y1=n+l*Math.sin(r)}`)}rect(t,n,l,o){this._append`M${this._x0=this._x1=+t},${this._y0=this._y1=+n}h${l=+l}v${+o}h${-l}Z`}toString(){return this._}}function vg(e){let t=3;return e.digits=function(n){if(!arguments.length)return t;if(n==null)t=null;else{const l=Math.floor(n);if(!(l>=0))throw new RangeError(`invalid digits: ${n}`);t=l}return e},()=>new _g(t)}function Ha(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function Ga(e){this._context=e}Ga.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;default:this._context.lineTo(e,t);break}}};function bg(e){return new Ga(e)}function wg(e){return e[0]}function yg(e){return e[1]}function kg(e,t){var n=nt(!0),l=null,o=bg,r=null,s=vg(u);e=typeof e=="function"?e:e===void 0?wg:nt(e),t=typeof t=="function"?t:t===void 0?yg:nt(t);function u(a){var f,c=(a=Ha(a)).length,d,g=!1,p;for(l==null&&(r=o(p=s())),f=0;f<=c;++f)!(f1)for(var n=1,l,o,r=e[t[0]],s,u=r.length;n=0;)n[t]=t;return n}function Sg(e,t){return e[t]}function Cg(e){const t=[];return t.key=e,t}function $g(){var e=nt([]),t=mo,n=po,l=Sg;function o(r){var s=Array.from(e.apply(this,arguments),Cg),u,a=s.length,f=-1,c;for(const d of r)for(u=0,++f;uFeedback Distribution