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