import{s as Y,e as g,a as P,c as v,b as B,f as b,g as I,l as q,m as p,i as U,h as o,o as K,p as L,n as O,q as Z,r as $,t as z,d as J,j as M}from"../chunks/scheduler.OwA2AG0M.js";import{e as X}from"../chunks/each.N0yHvFdK.js";import{S as ee,i as te}from"../chunks/index.JlSaLmPP.js";function G(r,e,t){const i=r.slice();return i[13]=e[t],i}function H(r){let e,t,i,n="Вы:",u,f,d,y=r[13][0]+"",_,x,w,F="Бот:",T,A,D,m=r[13][1]+"",k,C;return{c(){e=g("div"),t=g("div"),i=g("p"),i.textContent=n,u=P(),f=g("div"),d=g("p"),_=z(y),x=P(),w=g("p"),w.textContent=F,T=P(),A=g("div"),D=g("pre"),k=z(m),C=P(),this.h()},l(l){e=v(l,"DIV",{class:!0});var a=B(e);t=v(a,"DIV",{class:!0});var c=B(t);i=v(c,"P",{class:!0,"data-svelte-h":!0}),q(i)!=="svelte-rp9yxd"&&(i.textContent=n),u=I(c),f=v(c,"DIV",{class:!0});var s=B(f);d=v(s,"P",{class:!0});var E=B(d);_=J(E,y),E.forEach(b),s.forEach(b),x=I(c),w=v(c,"P",{class:!0,"data-svelte-h":!0}),q(w)!=="svelte-1l7fbwv"&&(w.textContent=F),T=I(c),A=v(c,"DIV",{class:!0});var h=B(A);D=v(h,"PRE",{class:!0});var V=B(D);k=J(V,m),V.forEach(b),h.forEach(b),c.forEach(b),C=I(a),a.forEach(b),this.h()},h(){p(i,"class","font-bold text-sm"),p(d,"class","text-sm"),p(f,"class","self-start bg-blue-500 text-white p-2 rounded-lg"),p(w,"class","font-bold text-sm"),p(D,"class","text-sm svelte-1m09ey3"),p(A,"class","self-start bg-slate-100 text-black p-2 rounded-lg"),p(t,"class","mb-2 flex flex-col"),p(e,"class","mb-2 flex flex-col")},m(l,a){U(l,e,a),o(e,t),o(t,i),o(t,u),o(t,f),o(f,d),o(d,_),o(t,x),o(t,w),o(t,T),o(t,A),o(A,D),o(D,k),o(e,C)},p(l,a){a&3&&y!==(y=l[13][0]+"")&&M(_,y),a&3&&m!==(m=l[13][1]+"")&&M(k,m)},d(l){l&&b(e)}}}function Q(r){let e,t="Остановить",i,n;return{c(){e=g("button"),e.textContent=t,this.h()},l(u){e=v(u,"BUTTON",{class:!0,"data-svelte-h":!0}),q(e)!=="svelte-9vttci"&&(e.textContent=t),this.h()},h(){p(e,"class","ml-2 px-4 py-2 mb-8 bg-cyan-800 text-white rounded-md")},m(u,f){U(u,e,f),i||(n=L(e,"click",r[6]),i=!0)},p:O,d(u){u&&b(e),i=!1,n()}}}function W(r){let e,t="Отправить",i,n;return{c(){e=g("button"),e.textContent=t,this.h()},l(u){e=v(u,"BUTTON",{class:!0,"data-svelte-h":!0}),q(e)!=="svelte-n2s9cz"&&(e.textContent=t),this.h()},h(){p(e,"class","ml-2 px-4 py-2 mb-8 bg-blue-500 text-white rounded-md")},m(u,f){U(u,e,f),i||(n=L(e,"click",r[4]),i=!0)},p:O,d(u){u&&b(e),i=!1,n()}}}function ue(r){let e,t,i,n,u,f,d,y,_,x,w,F,T="Использовать системный промпт",A,D,m,k,C=X(r[0]?r[1].slice(1):r[1]),l=[];for(let s=0;s<C.length;s+=1)l[s]=H(G(r,C,s));let a=r[3]&&Q(r),c=!r[3]&&W(r);return{c(){e=g("div"),t=g("div");for(let s=0;s<l.length;s+=1)l[s].c();i=P(),n=g("div"),u=g("div"),f=g("div"),d=g("textarea"),y=P(),_=g("label"),x=g("input"),w=P(),F=g("p"),F.textContent=T,A=P(),a&&a.c(),D=P(),c&&c.c(),this.h()},l(s){e=v(s,"DIV",{class:!0});var E=B(e);t=v(E,"DIV",{class:!0});var h=B(t);for(let j=0;j<l.length;j+=1)l[j].l(h);h.forEach(b),i=I(E),n=v(E,"DIV",{class:!0});var V=B(n);u=v(V,"DIV",{class:!0});var R=B(u);f=v(R,"DIV",{class:!0});var S=B(f);d=v(S,"TEXTAREA",{class:!0,placeholder:!0}),B(d).forEach(b),y=I(S),_=v(S,"LABEL",{class:!0});var N=B(_);x=v(N,"INPUT",{class:!0,type:!0}),w=I(N),F=v(N,"P",{"data-svelte-h":!0}),q(F)!=="svelte-15ltrgi"&&(F.textContent=T),N.forEach(b),S.forEach(b),A=I(R),a&&a.l(R),D=I(R),c&&c.l(R),R.forEach(b),V.forEach(b),E.forEach(b),this.h()},h(){p(t,"class","flex-1 overflow-y-auto p-4 bg-gray-200"),p(d,"class","flex-1 py-2 px-3 rounded-md border-gray-300 w-full"),p(d,"placeholder","Введите ваше сообщение..."),p(x,"class","checkbox accent-white"),p(x,"type","checkbox"),p(_,"class","flex items-center space-x-2"),p(f,"class","w-full"),p(u,"class","flex"),p(n,"class","p-4 bg-gray-300"),p(e,"class","h-screen flex flex-col py-8")},m(s,E){U(s,e,E),o(e,t);for(let h=0;h<l.length;h+=1)l[h]&&l[h].m(t,null);o(e,i),o(e,n),o(n,u),o(u,f),o(f,d),K(d,r[2]),o(f,y),o(f,_),o(_,x),x.checked=r[0],o(_,w),o(_,F),o(u,A),a&&a.m(u,null),o(u,D),c&&c.m(u,null),m||(k=[L(d,"input",r[7]),L(d,"keydown",r[5]),L(x,"change",r[8])],m=!0)},p(s,[E]){if(E&3){C=X(s[0]?s[1].slice(1):s[1]);let h;for(h=0;h<C.length;h+=1){const V=G(s,C,h);l[h]?l[h].p(V,E):(l[h]=H(V),l[h].c(),l[h].m(t,null))}for(;h<l.length;h+=1)l[h].d(1);l.length=C.length}E&4&&K(d,s[2]),E&1&&(x.checked=s[0]),s[3]?a?a.p(s,E):(a=Q(s),a.c(),a.m(u,D)):a&&(a.d(1),a=null),s[3]?c&&(c.d(1),c=null):c?c.p(s,E):(c=W(s),c.c(),c.m(u,null))},i:O,o:O,d(s){s&&b(e),Z(l,s),a&&a.d(),c&&c.d(),m=!1,$(k)}}}function le(r,e,t){const i=["Ты - бот, ассистент. Ты помогаешь пользователю с его запросами. Отвечай на русском языке, если пользователь не указал иное. Обращайся на Вы. Следуй инструкциям и указаниям пользователя.","Я отвечаю на русском языке!"];let n=[],u="",f=!1,d=new AbortController,y=!0;async function _(){u.trim()!==""&&(t(1,n=[...n,[u,""]]),t(2,u=""),await w())}function x(m){m.key==="Enter"&&!m.shiftKey&&(m.stopPropagation(),m.preventDefault(),_())}const w=async()=>{t(3,f=!0);const m=await fetch("/llm/chat",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({history:n}),signal:d.signal});try{if(d.signal.aborted){console.log("Request was cancelled.");return}if(!m.body){console.log("Response has no body");return}const k=m.body.pipeThrough(new TextDecoderStream).getReader();let C=!0;for(;C;)try{if(d.signal.aborted){console.log("Request was cancelled during reading.");break}const{value:l,done:a}=await k.read();if(a){C=!1;break}l&&t(1,n[n.length-1][1]+=l,n)}catch(l){if(l.name==="AbortError"){C=!1,console.log("Fetch was aborted during reading.");break}else{C=!1,console.error("Error during reading:",l);break}}t(3,f=!1)}catch(k){k.name==="AbortError"?console.log("Fetch was aborted."):console.error("Error during fetch:",k)}},F=()=>{d.abort("user canceled"),d=new AbortController};function T(m){m?n.unshift(i):t(1,n=n.filter(k=>k!==i))}function A(){u=this.value,t(2,u)}function D(){y=this.checked,t(0,y)}return r.$$.update=()=>{r.$$.dirty&1&&T(y)},[y,n,u,f,_,x,F,A,D]}class ne extends ee{constructor(e){super(),te(this,e,le,ue,Y,{})}}export{ne as component}; | |