(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[7278],{92164:function(e,t,s){Promise.resolve().then(s.bind(s,9479)),Promise.resolve().then(s.t.bind(s,72972,23))},9479:function(e,t,s){"use strict";s.d(t,{default:function(){return v}});var a=s(57437),l=s(2265),n=s(32970);s(92581),s(18206);var r=s(12574),o=s(84436),i=s(19683),c=s(81315),d=s(92735),u=s(30401),m=s(78867),p=s(33523),h=s(92619);let f={javascript:".js",python:".py",java:".java",c:".c",cpp:".cpp","c++":".cpp","c#":".cs",ruby:".rb",php:".php",swift:".swift","objective-c":".m",kotlin:".kt",typescript:".ts",go:".go",perl:".pl",rust:".rs",scala:".scala",haskell:".hs",lua:".lua",shell:".sh",sql:".sql",html:".html",css:".css"},x=function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],s="ABCDEFGHJKLMNPQRSTUVWXY3456789",a="";for(let t=0;t<e;t++)a+=s.charAt(Math.floor(Math.random()*s.length));return t?a.toLowerCase():a},b=(0,l.memo)(e=>{let{language:t,value:s}=e,{isCopied:n,copyToClipboard:r}=function(e){let{timeout:t=2e3}=e,[s,a]=l.useState(!1);return{isCopied:s,copyToClipboard:e=>{var s;(null===(s=navigator.clipboard)||void 0===s?void 0:s.writeText)&&e&&navigator.clipboard.writeText(e).then(()=>{a(!0),setTimeout(()=>{a(!1)},t)})}}}({timeout:2e3});return(0,a.jsxs)("div",{className:"codeblock relative w-full font-sans my-3",children:[(0,a.jsxs)("div",{className:"flex w-full items-center justify-between bg-gray-dark p-2 rounded-md pr-4 text-light",children:[(0,a.jsx)("span",{className:"text-xs lowercase",children:t}),(0,a.jsxs)("div",{className:"flex items-center space-x-5",children:[(0,a.jsxs)("button",{onClick:()=>{let e=f[t]||".file",a="file-".concat(x(3,!0)).concat(e),l=window.prompt("Enter file name",a);if(!l)return;let n=new Blob([s],{type:"text/plain"}),r=URL.createObjectURL(n),o=document.createElement("a");o.download=l,o.href=r,o.style.display="none",document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(r)},id:"downloadButton","aria-label":"Download",children:[(0,a.jsx)(d.Z,{}),(0,a.jsx)("span",{className:"sr-only",children:"Download"})]}),(0,a.jsxs)("button",{onClick:()=>{n||r(s)},id:"copyButton","aria-label":"Copy",children:[n?(0,a.jsx)(u.Z,{className:"h-4 w-4"}):(0,a.jsx)(m.Z,{className:"h-4 w-4"}),(0,a.jsx)("span",{className:"sr-only",children:"Copy code"})]})]})]}),(0,a.jsx)(p.Z,{language:t,style:h.RY,PreTag:"span",showLineNumbers:!0,customStyle:{width:"100%",background:"transparent",display:"block",padding:"1.5rem 1rem",borderRadius:"0.5rem"},codeTagProps:{style:{fontSize:"0.9rem",fontFamily:"var(--font-mono)"}},children:s})]})});b.displayName="CodeBlock";let g=(0,l.memo)(o.U,(e,t)=>e.children===t.children&&e.className===t.className),j={p(e){let{children:t}=e;return t?(0,a.jsx)("p",{className:"mb-2 last:mb-1",children:t}):null},code(e){let{node:t,inline:s,className:l,children:n,...r}=e;if(!n)return null;let o=Array.isArray(n)?n.join(""):n;if("string"==typeof o&&o.length){if("▍"===o)return(0,a.jsx)("span",{className:"mt-1 animate-pulse cursor-default",children:"▍"});let e=o.replace("▍","▍");if(!e.includes("\n"))return(0,a.jsx)("code",{className:l,...r,children:e});{let t=/language-(\w+)/.exec(l||"");return(0,a.jsx)(b,{language:t&&t[1]||"",value:e.replace(/\n$/,""),...r},Math.random())}}return null}};function y(e){let{content:t}=e;return(0,a.jsx)(g,{className:"prose dark:prose-invert prose-p:leading-relaxed prose-pre:p-0 break-words",remarkPlugins:[i.Z,c.Z],components:j,children:t})}let w=()=>"".concat(Date.now(),"-").concat(Math.random().toString(36).substring(2,9));var v=()=>{let[e,t]=(0,l.useState)([]),[s,o]=(0,l.useState)(0),[i,c]=(0,l.useState)(""),d=(0,l.useRef)(null),[u,m]=(0,l.useState)(!1),[p,h]=(0,l.useState)(null),f=async s=>{if(s.preventDefault(),!i.trim())return;let a=[...e,{id:w(),role:"user",content:i}];t(a),c("");let l=new AbortController;h(l);try{let e=await fetch("/api/chatbot/",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({messages:a}),signal:l.signal});if(e.body){let s=e.body.getReader(),a=new TextDecoder("utf-8"),n="",r=w();t(e=>[...e,{id:r,role:"assistant",content:""}]);let i=e.headers.get("X-Token-Usage");i&&o(parseInt(i,10));let c=async()=>{m(!0);try{for(;;){let{done:e,value:o}=await s.read();if(e||l.signal.aborted)break;let i=a.decode(o,{stream:!0});n+=i,t(e=>e.map(e=>e.id===r?{...e,content:n}:e))}}catch(e){}finally{l.signal.aborted||m(!1)}};await c()}}catch(e){}finally{h(null)}};return(0,l.useEffect)(()=>{var e;null===(e=d.current)||void 0===e||e.scrollIntoView({behavior:"smooth"})},[e]),(0,a.jsxs)("div",{className:"text-base sm:text-md md:text-lg p-2 bg-light dark:bg-dark rounded-md",children:[e&&e.length>0&&(0,a.jsx)("button",{className:"p-2 ring-1 rounded-md text-sm absolute -top-2 right-0",onClick:()=>{t([])},id:"clearChatButton",children:"Clear Chat"}),s>0&&(0,a.jsx)("div",{className:"text-sm text-center",children:(0,a.jsxs)("p",{children:["Token Usage: ",s]})}),(0,a.jsxs)("article",{className:"flex flex-col items-stretch w-full mx-auto max-h-[300px] h-full overflow-y-auto mb-9",children:[e.map(e=>(0,a.jsxs)("div",{className:"space-y-6",children:["user"===e.role?"User: ":"Assistant: ",(0,a.jsx)("div",{className:"markdown"}),(0,a.jsx)(y,{content:e.content})]},e.id)),(0,a.jsx)("div",{ref:d})]}),(0,a.jsx)("form",{onSubmit:f,className:"absolute bottom-0 left-0 w-full",children:(0,a.jsxs)("div",{className:"flex",children:[(0,a.jsx)("label",{htmlFor:"user_input",className:"sr-only",children:"User Input"}),(0,a.jsx)("input",{className:"p-2 border border-gray rounded shadow-xl w-full",value:i,id:"user_input",placeholder:"Ask something...",onChange:e=>c(e.target.value)}),(0,a.jsx)("button",{type:"submit",className:"ml-2 p-2 text-white rounded ring-2 bg-blue-dark min-w-12",id:"sendMessageButton",children:u?(0,a.jsx)(r.NB,{width:32,height:32}):(0,a.jsx)(n.pzg,{size:32})})]})})]})}}},function(e){e.O(0,[3344,9571,8447,8206,2972,9379,3734,2971,2117,1744],function(){return e(e.s=92164)}),_N_E=e.O()}]);