diff --git a/langserve/chat_playground/dist/assets/index-86d4d9c0.js b/langserve/chat_playground/dist/assets/index-53ad47d4.js similarity index 97% rename from langserve/chat_playground/dist/assets/index-86d4d9c0.js rename to langserve/chat_playground/dist/assets/index-53ad47d4.js index 82a80da5..ce853986 100644 --- a/langserve/chat_playground/dist/assets/index-86d4d9c0.js +++ b/langserve/chat_playground/dist/assets/index-53ad47d4.js @@ -137,4 +137,4 @@ Check your backend logs for errors.`,{hideProgressBar:!0}),u((O=c[c.length-2])== * (c) 2017-2021 Joachim Wester * MIT license */var K1=new WeakMap,K_=function(){function e(t){this.observers=new Map,this.obj=t}return e}(),Y_=function(){function e(t,n){this.callback=t,this.observer=n}return e}();function Z_(e){return K1.get(e)}function X_(e,t){return e.observers.get(t)}function J_(e,t){e.observers.delete(t.callback)}function ex(e,t){t.unobserve()}function tx(e,t){var n=[],r,o=Z_(e);if(!o)o=new K_(e),K1.set(e,o);else{var u=X_(o,t);r=u&&u.observer}if(r)return r;if(r={},o.value=Fn(e),t){r.callback=t,r.next=null;var s=function(){Wp(r)},l=function(){clearTimeout(r.next),r.next=setTimeout(s)};typeof window<"u"&&(window.addEventListener("mouseup",l),window.addEventListener("keyup",l),window.addEventListener("mousedown",l),window.addEventListener("keydown",l),window.addEventListener("change",l))}return r.patches=n,r.object=e,r.unobserve=function(){Wp(r),clearTimeout(r.next),J_(o,r),typeof window<"u"&&(window.removeEventListener("mouseup",l),window.removeEventListener("keyup",l),window.removeEventListener("mousedown",l),window.removeEventListener("keydown",l),window.removeEventListener("change",l))},o.observers.set(t,new Y_(t,r)),r}function Wp(e,t){t===void 0&&(t=!1);var n=K1.get(e.object);Y1(n.value,e.object,e.patches,"",t),e.patches.length&&Nc(n.value,e.patches);var r=e.patches;return r.length>0&&(e.patches=[],e.callback&&e.callback(r)),r}function Y1(e,t,n,r,o){if(t!==e){typeof t.toJSON=="function"&&(t=t.toJSON());for(var u=Fp(t),s=Fp(e),l=!1,c=s.length-1;c>=0;c--){var f=s[c],h=e[f];if(Up(t,f)&&!(t[f]===void 0&&h!==void 0&&Array.isArray(t)===!1)){var p=t[f];typeof h=="object"&&h!=null&&typeof p=="object"&&p!=null&&Array.isArray(h)===Array.isArray(p)?Y1(h,p,n,r+"/"+oi(f),o):h!==p&&(o&&n.push({op:"test",path:r+"/"+oi(f),value:Fn(h)}),n.push({op:"replace",path:r+"/"+oi(f),value:Fn(p)}))}else Array.isArray(e)===Array.isArray(t)?(o&&n.push({op:"test",path:r+"/"+oi(f),value:Fn(h)}),n.push({op:"remove",path:r+"/"+oi(f)}),l=!0):(o&&n.push({op:"test",path:r,value:e}),n.push({op:"replace",path:r,value:t}))}if(!(!l&&u.length==s.length))for(var c=0;c0){const c=o.decode(s.subarray(0,l)),f=l+(s[l+1]===32?2:1),h=o.decode(s.subarray(f));switch(c){case"data":r.data=r.data?r.data+` -`+h:h;break;case"event":r.event=h;break;case"id":e(r.id=h);break;case"retry":const p=parseInt(h,10);isNaN(p)||t(r.retry=p);break}}}}function sx(e,t){const n=new Uint8Array(e.length+t.length);return n.set(e),n.set(t,e.length),n}function Im(){return{data:"",event:"",id:"",retry:void 0}}var ax=globalThis&&globalThis.__rest||function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(e);o{const g=Object.assign({},r);g.accept||(g.accept=Vp);let E;function _(){E.abort(),document.hidden||S()}c||document.addEventListener("visibilitychange",_);let O=lx,y=0;function w(){document.removeEventListener("visibilitychange",_),window.clearTimeout(y),E.abort()}n==null||n.addEventListener("abort",()=>{w(),p()});const C=f??window.fetch,b=o??fx;async function S(){var k;E=new AbortController;try{const N=await C(e,Object.assign(Object.assign({},h),{headers:g,signal:E.signal}));await b(N),await ox(N.body,ix(ux(P=>{P?g[Lm]=P:delete g[Lm]},P=>{O=P},u))),s==null||s(),w(),p()}catch(N){if(!E.signal.aborted)try{const P=(k=l==null?void 0:l(N))!==null&&k!==void 0?k:O;window.clearTimeout(y),y=window.setTimeout(S,P)}catch(P){w(),v(P)}}}S()})}function fx(e){const t=e.headers.get("content-type");if(!(t!=null&&t.startsWith(Vp)))throw new Error(`Expected content-type to be ${Vp}, Actual: ${t}`)}function dx(e,t){return Nc(e,t,!0,!1).newDocument}function px(e={}){const[t,n]=$.useState(null),[r,o]=$.useState(null),u=$.useRef(e.onStart);u.current=e.onStart;const s=$.useRef(e.onChunk);s.current=e.onChunk;const l=$.useRef(e.onSuccess);l.current=e.onSuccess;const c=$.useRef(e.onError);c.current=e.onError;const f=$.useCallback(async(p,v)=>{var _;const g=new AbortController;o(g),(_=u.current)==null||_.call(u,{input:p});let E=null;await cx(Ei("/stream_log").toString(),{signal:g.signal,method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({input:p,config:v}),onmessage(O){var y,w;O.event==="data"&&(E=dx(E,(y=JSON.parse(O.data))==null?void 0:y.ops),n(E),(w=s.current)==null||w.call(s,JSON.parse(O.data),E))},openWhenHidden:!0,onclose(){var O;o(null),(O=l.current)==null||O.call(l,{input:p,output:E==null?void 0:E.final_output})},onerror(O){var y;throw o(null),(y=c.current)==null||y.call(c,O),O}})},[]),h=$.useCallback(()=>{r==null||r.abort(),o(null)},[r]);return{startStream:f,stopStream:r?h:void 0,latest:t}}function hx(){var g,E,_,O;const{context:e,callbacks:t}=P_(),{startStream:n,stopStream:r}=px(t),o=z_({}),u=U_({}),s=(E=(g=o==null?void 0:o.data)==null?void 0:g.schema)==null?void 0:E.properties,l=(_=u==null?void 0:u.data)==null?void 0:_.schema,c=s===void 0||l===void 0,f=Object.keys(s??{}),h=f.length===1&&(s==null?void 0:s[f[0]].type)==="array"||f.length===2&&((s==null?void 0:s[f[0]].type)==="array"||(s==null?void 0:s[f[1]].type)==="string"||(s==null?void 0:s[f[0]].type)==="string"||(s==null?void 0:s[f[1]].type)==="array"),p=((O=l==null?void 0:l.anyOf)==null?void 0:O.find(y=>{var w,C,b;return(b=(C=(w=y.properties)==null?void 0:w.type)==null?void 0:C.enum)==null?void 0:b.includes("ai")}))||(l==null?void 0:l.type)==="string",v=c||h&&p;return ce.jsx("div",{className:"flex items-center flex-col text-ls-black bg-background",children:ce.jsx(q2.Provider,{value:e,children:v?ce.jsx(H_,{startStream:n,stopStream:r,messagesInputKey:(s==null?void 0:s[f[0]].type)==="array"?f[0]:f[1],inputKey:(s==null?void 0:s[f[0]].type)==="string"?f[0]:f[1]}):ce.jsx("div",{className:"h-[100vh] w-[100vw] flex justify-center items-center text-xl p-16",children:ce.jsxs("span",{children:["The chat playground is only supported for chains that take one of the following as input:",ce.jsxs("ul",{className:"mt-8 list-disc ml-6",children:[ce.jsx("li",{children:"a dict with a single key containing a list of messages"}),ce.jsx("li",{children:"a dict with two keys: one a string input, one an list of messages"})]}),ce.jsx("br",{}),"and which return either an ",ce.jsx("code",{children:"AIMessage"})," or a string.",ce.jsx("br",{}),ce.jsx("br",{}),"You can test this chain in the default LangServe playground instead.",ce.jsx("br",{}),ce.jsx("br",{}),"To use the default playground, set ",ce.jsx("code",{children:'playground_type="default"'})," when adding the route in your backend."]})})})})}var X2={exports:{}};(function(e,t){(function(n,r){e.exports=r()})(qp,function(){var n=1e3,r=6e4,o=36e5,u="millisecond",s="second",l="minute",c="hour",f="day",h="week",p="month",v="quarter",g="year",E="date",_="Invalid Date",O=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,y=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,w={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(G){var K=["th","st","nd","rd"],Q=G%100;return"["+G+(K[(Q-20)%10]||K[Q]||K[0])+"]"}},C=function(G,K,Q){var ue=String(G);return!ue||ue.length>=K?G:""+Array(K+1-ue.length).join(Q)+G},b={s:C,z:function(G){var K=-G.utcOffset(),Q=Math.abs(K),ue=Math.floor(Q/60),U=Q%60;return(K<=0?"+":"-")+C(ue,2,"0")+":"+C(U,2,"0")},m:function G(K,Q){if(K.date()1)return G(ae[0])}else{var I=K.name;k[I]=K,U=I}return!ue&&U&&(S=U),U||!ue&&S},L=function(G,K){if(P(G))return G.clone();var Q=typeof K=="object"?K:{};return Q.date=G,Q.args=arguments,new V(Q)},H=b;H.l=ee,H.i=P,H.w=function(G,K){return L(G,{locale:K.$L,utc:K.$u,x:K.$x,$offset:K.$offset})};var V=function(){function G(Q){this.$L=ee(Q.locale,null,!0),this.parse(Q),this.$x=this.$x||Q.x||{},this[N]=!0}var K=G.prototype;return K.parse=function(Q){this.$d=function(ue){var U=ue.date,Z=ue.utc;if(U===null)return new Date(NaN);if(H.u(U))return new Date;if(U instanceof Date)return new Date(U);if(typeof U=="string"&&!/Z$/i.test(U)){var ae=U.match(O);if(ae){var I=ae[2]-1||0,F=(ae[7]||"0").substring(0,3);return Z?new Date(Date.UTC(ae[1],I,ae[3]||1,ae[4]||0,ae[5]||0,ae[6]||0,F)):new Date(ae[1],I,ae[3]||1,ae[4]||0,ae[5]||0,ae[6]||0,F)}}return new Date(U)}(Q),this.init()},K.init=function(){var Q=this.$d;this.$y=Q.getFullYear(),this.$M=Q.getMonth(),this.$D=Q.getDate(),this.$W=Q.getDay(),this.$H=Q.getHours(),this.$m=Q.getMinutes(),this.$s=Q.getSeconds(),this.$ms=Q.getMilliseconds()},K.$utils=function(){return H},K.isValid=function(){return this.$d.toString()!==_},K.isSame=function(Q,ue){var U=L(Q);return this.startOf(ue)<=U&&U<=this.endOf(ue)},K.isAfter=function(Q,ue){return L(Q)0,k<=S.r||!S.r){k<=1&&b>0&&(S=w[b-1]);var N=y[S.l];g&&(k=g(""+k)),_=typeof N=="string"?N.replace("%d",k):N(k,h,S.l,O);break}}if(h)return _;var P=O?y.future:y.past;return typeof P=="function"?P(_):P.replace("%s",_)},u.to=function(f,h){return l(f,h,this,!0)},u.from=function(f,h){return l(f,h,this)};var c=function(f){return f.$u?o.utc():o()};u.toNow=function(f){return this.to(c(this),f)},u.fromNow=function(f){return this.from(c(this),f)}}})})(t3);var gx=t3.exports;const wx=Ls(gx);J2.extend(wx);J2.extend(yx);Nd.createRoot(document.getElementById("root")).render(ce.jsx(hx,{})); +`+h:h;break;case"event":r.event=h;break;case"id":e(r.id=h);break;case"retry":const p=parseInt(h,10);isNaN(p)||t(r.retry=p);break}}}}function sx(e,t){const n=new Uint8Array(e.length+t.length);return n.set(e),n.set(t,e.length),n}function Im(){return{data:"",event:"",id:"",retry:void 0}}var ax=globalThis&&globalThis.__rest||function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(e);o{const g=Object.assign({},r);g.accept||(g.accept=Vp);let E;function _(){E.abort(),document.hidden||S()}c||document.addEventListener("visibilitychange",_);let O=lx,y=0;function w(){document.removeEventListener("visibilitychange",_),window.clearTimeout(y),E.abort()}n==null||n.addEventListener("abort",()=>{w(),p()});const C=f??window.fetch,b=o??fx;async function S(){var k;E=new AbortController;try{const N=await C(e,Object.assign(Object.assign({},h),{headers:g,signal:E.signal}));await b(N),await ox(N.body,ix(ux(P=>{P?g[Lm]=P:delete g[Lm]},P=>{O=P},u))),s==null||s(),w(),p()}catch(N){if(!E.signal.aborted)try{const P=(k=l==null?void 0:l(N))!==null&&k!==void 0?k:O;window.clearTimeout(y),y=window.setTimeout(S,P)}catch(P){w(),v(P)}}}S()})}function fx(e){const t=e.headers.get("content-type");if(!(t!=null&&t.startsWith(Vp)))throw new Error(`Expected content-type to be ${Vp}, Actual: ${t}`)}function dx(e,t){return Nc(e,t,!0,!1).newDocument}function px(e={}){const[t,n]=$.useState(null),[r,o]=$.useState(null),u=$.useRef(e.onStart);u.current=e.onStart;const s=$.useRef(e.onChunk);s.current=e.onChunk;const l=$.useRef(e.onSuccess);l.current=e.onSuccess;const c=$.useRef(e.onError);c.current=e.onError;const f=$.useCallback(async(p,v)=>{var _;const g=new AbortController;o(g),(_=u.current)==null||_.call(u,{input:p});let E=null;await cx(Ei("/stream_log").toString(),{signal:g.signal,method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({input:p,config:v}),onmessage(O){var y,w;O.event==="data"&&(E=dx(E,(y=JSON.parse(O.data))==null?void 0:y.ops),n(E),(w=s.current)==null||w.call(s,JSON.parse(O.data),E))},openWhenHidden:!0,onclose(){var O;o(null),(O=l.current)==null||O.call(l,{input:p,output:E==null?void 0:E.final_output})},onerror(O){var y;throw o(null),(y=c.current)==null||y.call(c,O),O}})},[]),h=$.useCallback(()=>{r==null||r.abort(),o(null)},[r]);return{startStream:f,stopStream:r?h:void 0,latest:t}}function hx(){var g,E,_,O,y;const{context:e,callbacks:t}=P_(),{startStream:n,stopStream:r}=px(t),o=z_({}),u=U_({}),s=(E=(g=o==null?void 0:o.data)==null?void 0:g.schema)==null?void 0:E.properties,l=(_=u==null?void 0:u.data)==null?void 0:_.schema,c=s===void 0||l===void 0,f=Object.keys(s??{}),h=f.length===1&&(s==null?void 0:s[f[0]].type)==="array"||f.length===2&&((s==null?void 0:s[f[0]].type)==="array"||(s==null?void 0:s[f[1]].type)==="string"||(s==null?void 0:s[f[0]].type)==="string"||(s==null?void 0:s[f[1]].type)==="array"),p=((O=l==null?void 0:l.anyOf)==null?void 0:O.find(w=>{var C,b,S;return(S=(b=(C=w.properties)==null?void 0:C.type)==null?void 0:b.enum)==null?void 0:S.includes("ai")}))||((y=l==null?void 0:l.oneOf)==null?void 0:y.find(w=>{var C,b,S;return(S=(b=(C=w.properties)==null?void 0:C.type)==null?void 0:b.enum)==null?void 0:S.includes("ai")}))||(l==null?void 0:l.type)==="string",v=c||h&&p;return ce.jsx("div",{className:"flex items-center flex-col text-ls-black bg-background",children:ce.jsx(q2.Provider,{value:e,children:v?ce.jsx(H_,{startStream:n,stopStream:r,messagesInputKey:(s==null?void 0:s[f[0]].type)==="array"?f[0]:f[1],inputKey:(s==null?void 0:s[f[0]].type)==="string"?f[0]:f[1]}):ce.jsx("div",{className:"h-[100vh] w-[100vw] flex justify-center items-center text-xl p-16",children:ce.jsxs("span",{children:["The chat playground is only supported for chains that take one of the following as input:",ce.jsxs("ul",{className:"mt-8 list-disc ml-6",children:[ce.jsx("li",{children:"a dict with a single key containing a list of messages"}),ce.jsx("li",{children:"a dict with two keys: one a string input, one an list of messages"})]}),ce.jsx("br",{}),"and which return either an ",ce.jsx("code",{children:"AIMessage"})," or a string.",ce.jsx("br",{}),ce.jsx("br",{}),"You can test this chain in the default LangServe playground instead.",ce.jsx("br",{}),ce.jsx("br",{}),"To use the default playground, set ",ce.jsx("code",{children:'playground_type="default"'})," when adding the route in your backend."]})})})})}var X2={exports:{}};(function(e,t){(function(n,r){e.exports=r()})(qp,function(){var n=1e3,r=6e4,o=36e5,u="millisecond",s="second",l="minute",c="hour",f="day",h="week",p="month",v="quarter",g="year",E="date",_="Invalid Date",O=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,y=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,w={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(G){var K=["th","st","nd","rd"],Q=G%100;return"["+G+(K[(Q-20)%10]||K[Q]||K[0])+"]"}},C=function(G,K,Q){var ue=String(G);return!ue||ue.length>=K?G:""+Array(K+1-ue.length).join(Q)+G},b={s:C,z:function(G){var K=-G.utcOffset(),Q=Math.abs(K),ue=Math.floor(Q/60),U=Q%60;return(K<=0?"+":"-")+C(ue,2,"0")+":"+C(U,2,"0")},m:function G(K,Q){if(K.date()1)return G(ae[0])}else{var I=K.name;k[I]=K,U=I}return!ue&&U&&(S=U),U||!ue&&S},L=function(G,K){if(P(G))return G.clone();var Q=typeof K=="object"?K:{};return Q.date=G,Q.args=arguments,new V(Q)},H=b;H.l=ee,H.i=P,H.w=function(G,K){return L(G,{locale:K.$L,utc:K.$u,x:K.$x,$offset:K.$offset})};var V=function(){function G(Q){this.$L=ee(Q.locale,null,!0),this.parse(Q),this.$x=this.$x||Q.x||{},this[N]=!0}var K=G.prototype;return K.parse=function(Q){this.$d=function(ue){var U=ue.date,Z=ue.utc;if(U===null)return new Date(NaN);if(H.u(U))return new Date;if(U instanceof Date)return new Date(U);if(typeof U=="string"&&!/Z$/i.test(U)){var ae=U.match(O);if(ae){var I=ae[2]-1||0,F=(ae[7]||"0").substring(0,3);return Z?new Date(Date.UTC(ae[1],I,ae[3]||1,ae[4]||0,ae[5]||0,ae[6]||0,F)):new Date(ae[1],I,ae[3]||1,ae[4]||0,ae[5]||0,ae[6]||0,F)}}return new Date(U)}(Q),this.init()},K.init=function(){var Q=this.$d;this.$y=Q.getFullYear(),this.$M=Q.getMonth(),this.$D=Q.getDate(),this.$W=Q.getDay(),this.$H=Q.getHours(),this.$m=Q.getMinutes(),this.$s=Q.getSeconds(),this.$ms=Q.getMilliseconds()},K.$utils=function(){return H},K.isValid=function(){return this.$d.toString()!==_},K.isSame=function(Q,ue){var U=L(Q);return this.startOf(ue)<=U&&U<=this.endOf(ue)},K.isAfter=function(Q,ue){return L(Q)0,k<=S.r||!S.r){k<=1&&b>0&&(S=w[b-1]);var N=y[S.l];g&&(k=g(""+k)),_=typeof N=="string"?N.replace("%d",k):N(k,h,S.l,O);break}}if(h)return _;var P=O?y.future:y.past;return typeof P=="function"?P(_):P.replace("%s",_)},u.to=function(f,h){return l(f,h,this,!0)},u.from=function(f,h){return l(f,h,this)};var c=function(f){return f.$u?o.utc():o()};u.toNow=function(f){return this.to(c(this),f)},u.fromNow=function(f){return this.from(c(this),f)}}})})(t3);var gx=t3.exports;const wx=Ls(gx);J2.extend(wx);J2.extend(yx);Nd.createRoot(document.getElementById("root")).render(ce.jsx(hx,{})); diff --git a/langserve/chat_playground/dist/index.html b/langserve/chat_playground/dist/index.html index e7cfd963..fe229612 100644 --- a/langserve/chat_playground/dist/index.html +++ b/langserve/chat_playground/dist/index.html @@ -5,7 +5,7 @@ Chat Playground - + diff --git a/langserve/chat_playground/src/App.tsx b/langserve/chat_playground/src/App.tsx index 29903f66..2ad5a974 100644 --- a/langserve/chat_playground/src/App.tsx +++ b/langserve/chat_playground/src/App.tsx @@ -30,6 +30,7 @@ export function App() { ); const outputSchemaSupported = ( outputDataSchema?.anyOf?.find((option) => option.properties?.type?.enum?.includes("ai")) || + outputDataSchema?.oneOf?.find((option) => option.properties?.type?.enum?.includes("ai")) || outputDataSchema?.type === "string" ); const isSupported = isLoading || (inputSchemaSupported && outputSchemaSupported);