DocuRAG / Api /src /out /_next /static /chunks /app /page-10e8a35fca12752e.js
abadesalex's picture
UI
819bacd
raw
history blame
13 kB
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[931],{8278:function(e,t,r){Promise.resolve().then(r.bind(r,9471))},9471:function(e,t,r){"use strict";r.r(t),r.d(t,{default:function(){return z}});var n=r(7437),o=r(8364),l=r(6031),i=r(9380),a=r(9178);let d={palette:{primary:{main:"#EDE8D0"},secondary:{main:(0,l.Fq)("#8B5A2B",.4)},border:{default:(0,l.Fq)("#000000",.23)},background:{default:(0,l.Fq)("#EDE8D0",.35),base:"#EDE8D0"}},typography:{fontFamily:" 'DM Sans', Inter,sans-serif",body1:{fontSize:"1rem",fontWeight:400,lineHeight:1.5},h1:{fontSize:"2.5rem",fontWeight:600,lineHeight:1.2},h2:{fontSize:"2rem",fontWeight:600,lineHeight:1.3},h3:{fontSize:"1.9rem",fontWeight:600,lineHeight:1.4},h4:{fontSize:"1.2rem",fontWeight:500,lineHeight:1.5},h5:{fontSize:"1rem",fontWeight:400,lineHeight:1.6},h6:{fontSize:"0.9rem",fontWeight:400,lineHeight:1.6},h7:{fontSize:"0.8rem",fontWeight:400,lineHeight:1.6}}};var s="http://localhost:8000/api",c=r(2960),u=r(5961),h=r(2265),x=r(7156),m=r(511);function f(e){let{text:t,isSender:r}=e;return(0,c.Z)(),(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(u.Z,{item:!0,xs:12,container:!0,justifyContent:r?"flex-end":"flex-start",sx:{flexGrow:0},mb:1,children:(0,n.jsx)(u.Z,{item:!0,sx:{backgroundColor:r?"#d1e7dd":"#f5f5f5",padding:"8px 12px",borderRadius:"20px",maxWidth:"80%",border:"1px solid #ccc"},children:(0,n.jsx)(m.Z,{variant:"h5",children:t})})})})}function b(e){let{messages:t}=e,r=(0,c.Z)(),o=(0,h.useRef)(null);return(0,h.useEffect)(()=>{o.current&&(o.current.scrollTop=o.current.scrollHeight)},[t]),(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(x.Z,{mb:2,display:"flex",flexDirection:"column",flexGrow:1,padding:2,style:{border:"2px solid black",overflow:"hidden",overflowY:"scroll",borderRadius:"8px",border:"1px solid #ccc",backgroundColor:r.palette.background.default},children:t.map((e,t)=>(0,n.jsx)(f,{text:e.text,isSender:e.isSender},t))})})}function g(e){let{chunkTest:t}=e,r=(0,c.Z)();return(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(x.Z,{display:"flex",flexDirection:"column",flexGrow:1,padding:2,style:{border:"2px solid black",overflow:"hidden",overflowY:"scroll",borderRadius:"8px",border:"1px solid #ccc",backgroundColor:r.palette.background.default,height:"50%"},children:t?(0,n.jsx)(f,{text:t.text,isSender:!1}):null})})}function p(e){let{chunks:t,documents:r}=e,o=(0,c.Z)();return(0,n.jsx)(n.Fragment,{children:(0,n.jsxs)(u.Z,{container:!0,border:1,mb:2,borderColor:o.palette.border.default,borderRadius:2,padding:1.2,sx:{backgroundColor:o.palette.background.default},children:[(0,n.jsx)(u.Z,{item:!0,sm:5.5,border:1,borderColor:o.palette.border.default,borderRadius:2,alignContent:"center",textAlign:"center",sx:{backgroundColor:"white"},children:(0,n.jsxs)(m.Z,{variant:"h6",children:["N\xba chunks: ",(0,n.jsx)("br",{})," ",t," "]})}),(0,n.jsx)(u.Z,{item:!0,ml:1,sm:5.5,border:1,borderColor:o.palette.border.default,borderRadius:2,alignContent:"center",textAlign:"center",sx:{backgroundColor:"white"},children:(0,n.jsxs)(m.Z,{variant:"h6",children:["N\xba Doc: ",(0,n.jsx)("br",{}),r]})})]})})}var j=r(4875);function Z(){let e=(0,c.Z)();return(0,n.jsx)(n.Fragment,{children:(0,n.jsxs)(u.Z,{container:!0,mb:2,alignItems:"center",border:1,borderColor:e.palette.border.default,borderRadius:2,padding:2,sx:{backgroundColor:e.palette.background.default},children:[(0,n.jsx)(u.Z,{item:!0,sm:3,children:(0,n.jsx)(m.Z,{variant:"h4",children:"Select Model:"})}),(0,n.jsx)(u.Z,{item:!0,container:!0,alignItems:"center",justifyContent:"center",sm:2.5,border:1,borderColor:e.palette.border.default,borderRadius:2,sx:{backgroundColor:"white"},children:(0,n.jsx)(j.Z,{children:(0,n.jsx)(m.Z,{variant:"h6",color:"black",children:"Model 1"})})}),(0,n.jsx)(u.Z,{item:!0,container:!0,ml:2,alignItems:"center",justifyContent:"center",sm:2.5,border:1,borderColor:e.palette.border.default,borderRadius:2,sx:{backgroundColor:"white"},children:(0,n.jsx)(j.Z,{children:(0,n.jsx)(m.Z,{variant:"h6",color:"black",children:"Model 2"})})}),(0,n.jsx)(u.Z,{item:!0,ml:2,container:!0,alignItems:"center",justifyContent:"center",sm:2.5,border:1,borderColor:e.palette.border.default,borderRadius:2,sx:{backgroundColor:"white"},children:(0,n.jsx)(j.Z,{children:(0,n.jsx)(m.Z,{variant:"h6",color:"black",children:"Model 3"})})})]})})}function C(e){let{documentName:t,documentId:r,documentNumber:o,onSelectedChunk:l}=e,i=(0,c.Z)();return(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(j.Z,{onClick:()=>l({documentNumber:o}),sx:{textTransform:"none",color:"inherit",padding:0},children:(0,n.jsxs)(u.Z,{item:!0,container:!0,alignItems:"center",xs:12,mb:1,sx:{backgroundColor:i.palette.secondary.main,padding:"8px 12px",borderRadius:"10px",border:"1px solid",borderColor:i.palette.border.default},children:[(0,n.jsx)(u.Z,{item:!0,container:!0,borderRadius:20,justifyContent:"center",alignContent:"center",border:1,sx:{backgroundColor:i.palette.secondary.main,width:35,height:35},children:(0,n.jsx)(m.Z,{variant:"h5",children:o})}),(0,n.jsx)(u.Z,{container:!0,alignItems:"center",justifyContent:"space-between",sx:{flexGrow:1,marginLeft:1},children:(0,n.jsxs)(u.Z,{item:!0,container:!0,direction:"column",ml:1,alignItems:"flex-start",children:[(0,n.jsx)(u.Z,{item:!0,children:(0,n.jsx)(m.Z,{variant:"h5",sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.substring(0,8)})}),(0,n.jsx)(u.Z,{item:!0,children:(0,n.jsx)(m.Z,{variant:"h7",color:i.palette.border.default,children:r})})]})})]})})})}function k(e){let{chunks:t,onSelectedChunk:r}=e,l=(0,o.u)();return(0,h.useEffect)(()=>{},[t]),(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(x.Z,{display:"flex",flexDirection:"column",flexGrow:1,padding:2,mb:2,style:{border:"2px solid black",overflow:"hidden",overflowY:"scroll",borderRadius:"8px",border:"1px solid #ccc",backgroundColor:l.palette.background.default,height:"60%"},children:t.map((e,t)=>(0,n.jsx)(C,{documentName:"Chunk ".concat(e.id),documentId:"Document_".concat(e.id),documentNumber:t,onSelectedChunk:r},t))})})}var w=r(7630);function y(e){let{documentName:t,documentId:r,documentNumber:o,deleteDocument:l}=e,i=(0,c.Z)();return(0,n.jsx)(n.Fragment,{children:(0,n.jsxs)(u.Z,{item:!0,container:!0,alignItems:"center",xs:12,mb:1,sx:{backgroundColor:i.palette.secondary.main,padding:"8px 12px",borderRadius:"10px",border:"1px solid",borderColor:i.palette.border.default},children:[(0,n.jsx)(u.Z,{item:!0,container:!0,borderRadius:20,justifyContent:"center",alignContent:"center",border:1,sx:{backgroundColor:i.palette.secondary.main,width:35,height:35},children:(0,n.jsx)(m.Z,{variant:"h5",children:o})}),(0,n.jsxs)(u.Z,{container:!0,alignItems:"center",justifyContent:"space-between",sx:{flexGrow:1,marginLeft:1},children:[(0,n.jsxs)(u.Z,{item:!0,container:!0,direction:"column",ml:1,children:[(0,n.jsx)(u.Z,{item:!0,children:(0,n.jsx)(m.Z,{variant:"h5",sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.substring(0,8)})}),(0,n.jsx)(u.Z,{item:!0,children:(0,n.jsx)(m.Z,{variant:"h7",color:i.palette.border.default,children:r})})]}),(0,n.jsx)(u.Z,{item:!0,children:(0,n.jsx)(j.Z,{onClick:()=>l(o),sx:{minWidth:"auto",padding:0,margin:0},children:(0,n.jsx)(w.Z,{fontSize:"small",sx:{color:"black"}})})})]})]})})}function v(e){let{documents:t,fetchDocuments:r,fetchChunks:l}=e,i=(0,o.u)(),a=async e=>{let t="".concat(s,"/upload/delete_document/").concat(e);await fetch(t,{method:"DELETE",headers:{"Content-Type":"application/json"}}).then(r()).then(l())};return(0,h.useEffect)(()=>{},[t]),(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(x.Z,{display:"flex",flexDirection:"column",flexGrow:1,padding:2,mb:2,style:{border:"2px solid black",overflow:"hidden",overflowY:"scroll",borderRadius:"8px",border:"1px solid #ccc",backgroundColor:i.palette.background.default,height:"40%"},children:t.map((e,t)=>(0,n.jsx)(y,{documentName:e.filename,documentId:"Document_".concat(e.id),documentNumber:e.id,deleteDocument:a},t))})})}function S(e){let{chunks:t,tokens:r}=e,o=(0,c.Z)();return(0,n.jsx)(n.Fragment,{children:(0,n.jsxs)(u.Z,{container:!0,border:1,borderColor:o.palette.border.default,borderRadius:2,mb:2,padding:1.2,sx:{backgroundColor:o.palette.background.default},children:[(0,n.jsx)(u.Z,{item:!0,sm:5,ml:1,p:1.2,border:1,borderColor:o.palette.border.default,borderRadius:2,alignContent:"center",textAlign:"center",sx:{backgroundColor:"white"},children:(0,n.jsxs)(m.Z,{variant:"h5",children:["N\xba chunks: ",(0,n.jsx)("br",{})," ",t," "]})}),(0,n.jsx)(u.Z,{item:!0,ml:10,sm:5,p:1.2,border:1,borderColor:o.palette.border.default,borderRadius:2,alignContent:"center",textAlign:"center",sx:{backgroundColor:"white"},children:(0,n.jsxs)(m.Z,{variant:"h5",children:["N\xba tokens: ",(0,n.jsx)("br",{})," ",t," "]})})]})})}var R=r(559),D=r(8410),F=r(5041);let E=async(e,t)=>{let r=new URLSearchParams;for(let e in t)r.append(e,t[e]);let n=await fetch(s+e,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:r.toString()});if(!n.ok){let e=await n.json(),t=Error("HTTP error");throw t.status=n.status,t.detail=e.detail||"Something went wrong",t}return n.json()};function I(e){let{fetchMessages:t}=e,[r,o]=(0,h.useState)(""),{enqueueSnackbar:l}=(0,F.Ds)(),i=(0,c.Z)();return(0,n.jsx)(n.Fragment,{children:(0,n.jsxs)(u.Z,{container:!0,alignItems:"center",xs:12,sm:12,p:2,pl:3,border:1,borderRadius:2,borderColor:i.palette.border.default,sx:{backgroundColor:i.palette.background.default},children:[(0,n.jsx)(u.Z,{item:!0,xs:12,sm:10,children:(0,n.jsx)(D.Z,{fullWidth:!0,size:"small",label:"Ask me anything",onChange:e=>{o(e.target.value)},slotProps:{input:{sx:{backgroundColor:"white",borderRadius:"4px"}}}})}),(0,n.jsx)(u.Z,{ml:4,item:!0,xs:12,border:1,borderColor:i.palette.border.default,borderRadius:20,display:"flex",justifyContent:"center",alignItems:"center",sx:{backgroundColor:i.palette.secondary.main,width:35,height:35},children:(0,n.jsx)(j.Z,{onClick:()=>{if(!r.trim()){l("Please enter a message.",{variant:"warning"});return}E("/query/query_search",{q:r}).then(t).catch(e=>{l(e.detail||e.message,{variant:"error"})}),o("")},children:(0,n.jsx)(R.Z,{fontSize:"small",sx:{color:i.palette.border.default}})})})]})})}var T=r(1867);let _=async(e,t)=>{let r=await fetch(s+e,{method:"POST",body:t});if(!r.ok){let e=await r.json(),t=Error("HTTP error");throw t.status=r.status,t.detail=e.detail||"Something went wrong",t}return r.json()};function N(e){let{fetchDocuments:t,fetchChunks:r}=e,o=(0,c.Z)(),l=(0,h.useRef)(null);return(0,n.jsx)(u.Z,{container:!0,border:1,borderColor:o.palette.border.default,borderRadius:2,p:1,sx:{backgroundColor:o.palette.background.default},children:(0,n.jsx)(j.Z,{fullWidth:!0,sx:{textTransform:"none"},onClick:()=>{l.current.click()},children:(0,n.jsxs)(u.Z,{container:!0,xs:12,alignItems:"center",justifyContent:"space-between",border:1,borderColor:o.palette.divider,borderRadius:1,p:1,sx:{backgroundColor:"white"},children:[(0,n.jsx)("input",{type:"file",ref:l,style:{display:"none"},onChange:e=>{let n=e.target.files[0];if(!n)return;let o=new FormData;o.append("file",n),_("/upload/document",o).then(t()).then(r()).catch(e=>{(0,F.yv)(e.detail||e.message,{variant:"error"})})},accept:".pdf"}),(0,n.jsx)(u.Z,{item:!0,children:(0,n.jsx)(m.Z,{variant:"h6",color:"black",children:"Upload File"})}),(0,n.jsx)(T.Z,{sx:{color:"black"}})]})})})}function W(){(0,c.Z)();let[e,t]=(0,h.useState)([]),[r,o]=(0,h.useState)([]),[l,i]=(0,h.useState)([]),[a,d]=(0,h.useState)(null);console.log(l[a]);let x=async()=>{let e="".concat(s,"/query/get_messages"),r=await fetch(e);t((await r.json()).data)},m=async()=>{let e="".concat(s,"/upload/get_documents"),t=await fetch(e);o((await t.json()).data)},f=async()=>{let e="".concat(s,"/upload/get_embeddings"),t=await fetch(e),r=await t.json(),n=1;i(Object.keys(r.data).flatMap(e=>r.data[e].data.map(e=>({id:n++,text:e.metadata.original_text}))))};return(0,h.useEffect)(()=>{x(),m(),f()},[]),(0,n.jsx)(n.Fragment,{children:(0,n.jsxs)(u.Z,{container:!0,mt:1,style:{height:"97vh"},children:[(0,n.jsxs)(u.Z,{item:!0,xs:12,sm:5,p:1,style:{display:"flex",flexDirection:"column",height:"100%"},children:[(0,n.jsx)(Z,{}),(0,n.jsx)(b,{messages:e}),(0,n.jsx)(I,{fetchMessages:x})]}),(0,n.jsxs)(u.Z,{item:!0,xs:12,sm:2,p:1,style:{display:"flex",flexDirection:"column",height:"100%"},children:[(0,n.jsx)(p,{chunks:2,documents:1}),(0,n.jsx)(k,{chunks:l,onSelectedChunk:e=>{if(e.documentNumber===a){d(null);return}d(e.documentNumber)}}),(0,n.jsx)(v,{documents:r,fetchDocuments:m,fetchChunks:f}),(0,n.jsx)(N,{fetchDocuments:m,fetchChunks:f})]}),(0,n.jsxs)(u.Z,{item:!0,xs:12,sm:5,p:1,style:{display:"flex",flexDirection:"column",height:"100%"},children:[(0,n.jsx)(S,{}),(0,n.jsx)(g,{chunkTest:l[a]})]})]})})}function z(){return(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(o.a,{theme:function(){return arguments.length>0&&void 0!==arguments[0]&&arguments[0],(0,i.Z)((0,a.Z)({...d}))}(),children:(0,n.jsx)(F.wT,{children:(0,n.jsx)(W,{})})})})}}},function(e){e.O(0,[324,971,23,744],function(){return e(e.s=8278)}),_N_E=e.O()}]);