Xenova HF staff commited on
Commit
d828cde
1 Parent(s): 2a8c818

Update assets/index-bc80c313.js

Browse files
Files changed (1) hide show
  1. assets/index-bc80c313.js +1 -1
assets/index-bc80c313.js CHANGED
@@ -47,7 +47,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
47
  monaco.config({ paths: { vs: '...' } })
48
 
49
  For more please check the link https://github.com/suren-atoyan/monaco-loader#config
50
- `},cs=Lp(Ip)(Pc),Dp={config:Mp},Fp=function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return function(l){return n.reduceRight(function(o,i){return i(o)},l)}};function Nc(e,t){return Object.keys(t).forEach(function(n){t[n]instanceof Object&&e[n]&&Object.assign(t[n],Nc(e[n],t[n]))}),is(is({},e),t)}var $p={type:"cancelation",msg:"operation is manually canceled"};function oo(e){var t=!1,n=new Promise(function(r,l){e.then(function(o){return t?l($p):r(o)}),e.catch(l)});return n.cancel=function(){return t=!0},n}var Up=Op.create({config:jp,isInitialized:!1,resolve:null,reject:null,monaco:null}),zc=cp(Up,2),dr=zc[0],Tl=zc[1];function Ap(e){var t=Dp.config(e),n=t.monaco,r=ap(t,["monaco"]);Tl(function(l){return{config:Nc(l.config,r),monaco:n}})}function Vp(){var e=dr(function(t){var n=t.monaco,r=t.isInitialized,l=t.resolve;return{monaco:n,isInitialized:r,resolve:l}});if(!e.isInitialized){if(Tl({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),oo(io);if(window.monaco&&window.monaco.editor)return Oc(window.monaco),e.resolve(window.monaco),oo(io);Fp(Bp,Wp)(Qp)}return oo(io)}function Bp(e){return document.body.appendChild(e)}function Hp(e){var t=document.createElement("script");return e&&(t.src=e),t}function Wp(e){var t=dr(function(r){var l=r.config,o=r.reject;return{config:l,reject:o}}),n=Hp("".concat(t.config.paths.vs,"/loader.js"));return n.onload=function(){return e()},n.onerror=t.reject,n}function Qp(){var e=dr(function(n){var r=n.config,l=n.resolve,o=n.reject;return{config:r,resolve:l,reject:o}}),t=window.require;t.config(e.config),t(["vs/editor/editor.main"],function(n){Oc(n),e.resolve(n)},function(n){e.reject(n)})}function Oc(e){dr().monaco||Tl({monaco:e})}function Kp(){return dr(function(e){var t=e.monaco;return t})}var io=new Promise(function(e,t){return Tl({resolve:e,reject:t})}),jc={config:Ap,init:Vp,__getMonacoInstance:Kp},Yp={wrapper:{display:"flex",position:"relative",textAlign:"initial"},fullWidth:{width:"100%"},hide:{display:"none"}},uo=Yp,Xp={container:{display:"flex",height:"100%",width:"100%",justifyContent:"center",alignItems:"center"}},Gp=Xp;function Zp({children:e}){return Mt.createElement("div",{style:Gp.container},e)}var Jp=Zp,qp=Jp;function bp({width:e,height:t,isEditorReady:n,loading:r,_ref:l,className:o,wrapperProps:i}){return Mt.createElement("section",{style:{...uo.wrapper,width:e,height:t},...i},!n&&Mt.createElement(qp,null,r),Mt.createElement("div",{ref:l,style:{...uo.fullWidth,...!n&&uo.hide},className:o}))}var em=bp,Lc=O.memo(em);function tm(e){O.useEffect(e,[])}var Tc=tm;function nm(e,t,n=!0){let r=O.useRef(!0);O.useEffect(r.current||!n?()=>{r.current=!1}:e,t)}var Ee=nm;function Bn(){}function nn(e,t,n,r){return rm(e,r)||lm(e,t,n,r)}function rm(e,t){return e.editor.getModel(Mc(e,t))}function lm(e,t,n,r){return e.editor.createModel(t,n,r?Mc(e,r):void 0)}function Mc(e,t){return e.Uri.parse(t)}function om({original:e,modified:t,language:n,originalLanguage:r,modifiedLanguage:l,originalModelPath:o,modifiedModelPath:i,keepCurrentOriginalModel:u=!1,keepCurrentModifiedModel:s=!1,theme:c="light",loading:h="Loading...",options:m={},height:p="100%",width:w="100%",className:E,wrapperProps:C={},beforeMount:$=Bn,onMount:f=Bn}){let[a,d]=O.useState(!1),[v,y]=O.useState(!0),x=O.useRef(null),S=O.useRef(null),N=O.useRef(null),z=O.useRef(f),k=O.useRef($),V=O.useRef(!1);Tc(()=>{let T=jc.init();return T.then(A=>(S.current=A)&&y(!1)).catch(A=>(A==null?void 0:A.type)!=="cancelation"&&console.error("Monaco initialization: error:",A)),()=>x.current?ot():T.cancel()}),Ee(()=>{let T=x.current.getModifiedEditor();T.getOption(S.current.editor.EditorOption.readOnly)?T.setValue(t||""):t!==T.getValue()&&(T.executeEdits("",[{range:T.getModel().getFullModelRange(),text:t||"",forceMoveMarkers:!0}]),T.pushUndoStop())},[t],a),Ee(()=>{var T,A;(A=(T=x.current)==null?void 0:T.getModel())==null||A.original.setValue(e||"")},[e],a),Ee(()=>{let{original:T,modified:A}=x.current.getModel();S.current.editor.setModelLanguage(T,r||n||"text"),S.current.editor.setModelLanguage(A,l||n||"text")},[n,r,l],a),Ee(()=>{var T;(T=S.current)==null||T.editor.setTheme(c)},[c],a),Ee(()=>{var T;(T=x.current)==null||T.updateOptions(m)},[m],a);let ie=O.useCallback(()=>{var ze;if(!S.current)return;k.current(S.current);let T=nn(S.current,e||"",r||n||"text",o||""),A=nn(S.current,t||"",l||n||"text",i||"");(ze=x.current)==null||ze.setModel({original:T,modified:A})},[n,t,l,e,r,o,i]),Be=O.useCallback(()=>{var T;!V.current&&N.current&&(x.current=S.current.editor.createDiffEditor(N.current,{automaticLayout:!0,...m}),ie(),(T=S.current)==null||T.editor.setTheme(c),d(!0),V.current=!0)},[m,c,ie]);O.useEffect(()=>{a&&z.current(x.current,S.current)},[a]),O.useEffect(()=>{!v&&!a&&Be()},[v,a,Be]),Ee(()=>{if(x.current&&S.current){let T=x.current.getOriginalEditor(),A=nn(S.current,e||"",r||n||"text",o||"");A!==T.getModel()&&T.setModel(A)}},[o],a),Ee(()=>{if(x.current&&S.current){let T=x.current.getModifiedEditor(),A=nn(S.current,t||"",l||n||"text",i||"");A!==T.getModel()&&T.setModel(A)}},[i],a);function ot(){var A,ze,_,L;let T=(A=x.current)==null?void 0:A.getModel();u||((ze=T==null?void 0:T.original)==null||ze.dispose()),s||((_=T==null?void 0:T.modified)==null||_.dispose()),(L=x.current)==null||L.dispose()}return Mt.createElement(Lc,{width:w,height:p,isEditorReady:a,loading:h,_ref:N,className:E,wrapperProps:C})}var im=om;O.memo(im);function um(e){let t=O.useRef();return O.useEffect(()=>{t.current=e},[e]),t.current}var sm=um,Tr=new Map;function am({defaultValue:e,defaultLanguage:t,defaultPath:n,value:r,language:l,path:o,theme:i="light",line:u,loading:s="Loading...",options:c={},overrideServices:h={},saveViewState:m=!0,keepCurrentModel:p=!1,width:w="100%",height:E="100%",className:C,wrapperProps:$={},beforeMount:f=Bn,onMount:a=Bn,onChange:d,onValidate:v=Bn}){let[y,x]=O.useState(!1),[S,N]=O.useState(!0),z=O.useRef(null),k=O.useRef(null),V=O.useRef(null),ie=O.useRef(a),Be=O.useRef(f),ot=O.useRef(),T=O.useRef(r),A=sm(o),ze=O.useRef(!1),_=O.useRef(!1);Tc(()=>{let j=jc.init();return j.then(M=>(z.current=M)&&N(!1)).catch(M=>(M==null?void 0:M.type)!=="cancelation"&&console.error("Monaco initialization: error:",M)),()=>k.current?R():j.cancel()}),Ee(()=>{var M,ee,Se,He;let j=nn(z.current,e||r||"",t||l||"",o||n||"");j!==((M=k.current)==null?void 0:M.getModel())&&(m&&Tr.set(A,(ee=k.current)==null?void 0:ee.saveViewState()),(Se=k.current)==null||Se.setModel(j),m&&((He=k.current)==null||He.restoreViewState(Tr.get(o))))},[o],y),Ee(()=>{var j;(j=k.current)==null||j.updateOptions(c)},[c],y),Ee(()=>{!k.current||r===void 0||(k.current.getOption(z.current.editor.EditorOption.readOnly)?k.current.setValue(r):r!==k.current.getValue()&&(_.current=!0,k.current.executeEdits("",[{range:k.current.getModel().getFullModelRange(),text:r,forceMoveMarkers:!0}]),k.current.pushUndoStop(),_.current=!1))},[r],y),Ee(()=>{var M,ee;let j=(M=k.current)==null?void 0:M.getModel();j&&l&&((ee=z.current)==null||ee.editor.setModelLanguage(j,l))},[l],y),Ee(()=>{var j;u!==void 0&&((j=k.current)==null||j.revealLine(u))},[u],y),Ee(()=>{var j;(j=z.current)==null||j.editor.setTheme(i)},[i],y);let L=O.useCallback(()=>{var j;if(!(!V.current||!z.current)&&!ze.current){Be.current(z.current);let M=o||n,ee=nn(z.current,r||e||"",t||l||"",M||"");k.current=(j=z.current)==null?void 0:j.editor.create(V.current,{model:ee,automaticLayout:!0,...c},h),m&&k.current.restoreViewState(Tr.get(M)),z.current.editor.setTheme(i),x(!0),ze.current=!0}},[e,t,n,r,l,o,c,h,m,i]);O.useEffect(()=>{y&&ie.current(k.current,z.current)},[y]),O.useEffect(()=>{!S&&!y&&L()},[S,y,L]),T.current=r,O.useEffect(()=>{var j,M;y&&d&&((j=ot.current)==null||j.dispose(),ot.current=(M=k.current)==null?void 0:M.onDidChangeModelContent(ee=>{_.current||d(k.current.getValue(),ee)}))},[y,d]),O.useEffect(()=>{if(y){let j=z.current.editor.onDidChangeMarkers(M=>{var Se;let ee=(Se=k.current.getModel())==null?void 0:Se.uri;if(ee&&M.find(He=>He.path===ee.path)){let He=z.current.editor.getModelMarkers({resource:ee});v==null||v(He)}});return()=>{j==null||j.dispose()}}return()=>{}},[y,v]);function R(){var j,M;(j=ot.current)==null||j.dispose(),p?m&&Tr.set(o,k.current.saveViewState()):(M=k.current.getModel())==null||M.dispose(),k.current.dispose()}return Mt.createElement(Lc,{width:w,height:E,isEditorReady:y,loading:s,_ref:V,className:C,wrapperProps:$})}var cm=am,fm=O.memo(cm),dm=fm;function fs(e,t=0){const n=["Bytes","KB","MB","GB","TB"];if(e===0)return"0 Bytes";const r=parseInt(Math.floor(Math.log(e)/Math.log(1e3)),10);return(e/Math.pow(1e3,r)).toFixed(t)+" "+n[r]}function pm({data:e}){const t=e.progress??0,n=e.file,r=fs(e.loaded),l=fs(e.total);return I.jsx("div",{className:"progress-container",children:I.jsxs("div",{className:"progress-bar",style:{width:`${t}%`},children:[n," (",`${r} / ${l}`,")"]})})}const ds=["Xenova/tiny_starcoder_py","Xenova/codegen-350M-mono"];function mm(){const e=O.useRef(null),[t,n]=O.useState(!1),[r,l]=O.useState("python"),[o,i]=O.useState(null),[u,s]=O.useState(!1),[c,h]=O.useState([]),[m,p]=O.useState(ds[0]),[w,E]=O.useState(45),[C,$]=O.useState(`
51
  def fib(n):
52
  """Calculates the nth Fibonacci number"""
53
  `),[f,a]=O.useState(.5),[d,v]=O.useState(5),[y,x]=O.useState(!1),S=O.useRef(null);O.useEffect(()=>{S.current||(S.current=new Worker(new URL("/assets/worker-5130d00f.js",self.location),{type:"module"}));const z=k=>{switch(k.data.status){case"initiate":i(!1),h(V=>[...V,k.data]);break;case"progress":h(V=>V.map(ie=>ie.file===k.data.file?{...ie,...k.data}:ie));break;case"done":h(V=>V.filter(ie=>ie.file!==k.data.file));break;case"ready":i(!0);break;case"update":$(k.data.output);break;case"complete":s(!1);break}};return S.current.addEventListener("message",z),()=>S.current.removeEventListener("message",z)}),O.useEffect(()=>{const z=e.current;if(!z)return;let k=z.addAction({id:"generate",label:"Generate",contextMenuGroupId:"0_custom",run:()=>{const V=z.getValue();V&&S.current.postMessage({model:m,text:V,max_new_tokens:w,temperature:f,top_k:d,do_sample:y})}});return()=>k.dispose()},[t,m,w,f,d,y]);const N=o===!1||c.length>0;return I.jsxs("div",{className:"flex h-screen w-screen",children:[I.jsxs("div",{className:"gap-1 z-50 top-0 left-0 absolute w-full h-full transition-all px-32 flex flex-col justify-center text-center",style:{opacity:N?1:0,pointerEvents:N?"all":"none",background:"rgba(0, 0, 0, 0.5)",backdropFilter:"blur(4px)"},children:[o===!1&&I.jsx("label",{className:"text-3xl p-3",children:"Loading model..."}),c.map(z=>I.jsx("div",{children:I.jsx(pm,{data:z})},z.file))]}),I.jsx("div",{children:I.jsx(dm,{width:"calc(100vw - 360px)",language:r,value:C,theme:"vs-dark",onMount:z=>{e.current=z,n(!0)},options:{fontSize:24}})}),I.jsxs("div",{className:"flex-grow sidebar p-4 flex flex-col overflow-y-auto",children:[I.jsx("h2",{className:"text-2xl font-semibold text-center mb-1",children:"In-browser code completion"}),I.jsxs("div",{className:"text-center",children:["Made with ",I.jsx("a",{className:"text-white ital underline",href:"https://github.com/xenova/transformers.js",children:"🤗 Transformers.js"})]}),I.jsx("label",{className:"mt-3",children:"Model:"}),I.jsx("select",{value:m,onChange:z=>p(z.target.value),className:"p-2.5 bg-gray-50 border border-gray-200 text-gray-900 rounded-lg",children:ds.map((z,k)=>I.jsx("option",{value:z,children:z},k))}),I.jsxs("div",{className:"mt-3 flex justify-between",children:[I.jsx("label",{children:"Max new tokens:"}),I.jsx("label",{children:w})]}),I.jsx("input",{type:"range",min:"1",max:"512",value:w,onChange:z=>{const k=parseInt(z.target.value);E(k)}}),I.jsxs("div",{className:"mt-3 flex justify-between",children:[I.jsx("label",{children:"Temperature:"}),I.jsx("label",{children:f})]}),I.jsx("input",{type:"range",min:"0",step:"0.05",max:"1",value:f,onChange:z=>{const k=Number(z.target.value);a(k)}}),I.jsxs("div",{className:"mt-3 flex items-center",children:[I.jsx("input",{id:"default-checkbox",type:"checkbox",value:y,onInput:z=>{x(z.target.checked)},className:"w-4 h-4 text-blue-600 rounded focus:ring-blue-600 ring-offset-gray-800 focus:ring-2 bg-gray-700 border-gray-600"}),I.jsx("label",{htmlFor:"default-checkbox",className:"ml-2 font-medium",children:"Sample"})]}),I.jsxs("div",{className:"mt-3 flex justify-between",style:{opacity:y?1:.2},children:[I.jsx("label",{children:"Top K:"}),I.jsx("label",{children:d})]}),I.jsx("input",{disabled:!y,style:{opacity:y?1:.2},type:"range",min:"0",max:"50",value:d,onChange:z=>{const k=parseInt(z.target.value);v(k)}}),I.jsx("div",{className:"flex-grow"}),I.jsxs("div",{className:"flex gap-2 justify-center mt-3",children:[I.jsx("svg",{className:"w-6 h-6 text-white","aria-hidden":"true",xmlns:"http://www.w3.org/2000/svg",fill:"currentColor",viewBox:"0 0 20 20",children:I.jsx("path",{fillRule:"evenodd",d:"M10 .333A9.911 9.911 0 0 0 6.866 19.65c.5.092.678-.215.678-.477 0-.237-.01-1.017-.014-1.845-2.757.6-3.338-1.169-3.338-1.169a2.627 2.627 0 0 0-1.1-1.451c-.9-.615.07-.6.07-.6a2.084 2.084 0 0 1 1.518 1.021 2.11 2.11 0 0 0 2.884.823c.044-.503.268-.973.63-1.325-2.2-.25-4.516-1.1-4.516-4.9A3.832 3.832 0 0 1 4.7 7.068a3.56 3.56 0 0 1 .095-2.623s.832-.266 2.726 1.016a9.409 9.409 0 0 1 4.962 0c1.89-1.282 2.717-1.016 2.717-1.016.366.83.402 1.768.1 2.623a3.827 3.827 0 0 1 1.02 2.659c0 3.807-2.319 4.644-4.525 4.889a2.366 2.366 0 0 1 .673 1.834c0 1.326-.012 2.394-.012 2.72 0 .263.18.572.681.475A9.911 9.911 0 0 0 10 .333Z",clipRule:"evenodd"})}),I.jsx("a",{className:"text-white font-normal underline underline-offset-1",href:"https://github.com/xenova/transformers.js/tree/main/examples/code-completion",children:"Source code"})]})]})]})}so.createRoot(document.getElementById("root")).render(I.jsx(Mt.StrictMode,{children:I.jsx(mm,{})}));
 
47
  monaco.config({ paths: { vs: '...' } })
48
 
49
  For more please check the link https://github.com/suren-atoyan/monaco-loader#config
50
+ `},cs=Lp(Ip)(Pc),Dp={config:Mp},Fp=function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return function(l){return n.reduceRight(function(o,i){return i(o)},l)}};function Nc(e,t){return Object.keys(t).forEach(function(n){t[n]instanceof Object&&e[n]&&Object.assign(t[n],Nc(e[n],t[n]))}),is(is({},e),t)}var $p={type:"cancelation",msg:"operation is manually canceled"};function oo(e){var t=!1,n=new Promise(function(r,l){e.then(function(o){return t?l($p):r(o)}),e.catch(l)});return n.cancel=function(){return t=!0},n}var Up=Op.create({config:jp,isInitialized:!1,resolve:null,reject:null,monaco:null}),zc=cp(Up,2),dr=zc[0],Tl=zc[1];function Ap(e){var t=Dp.config(e),n=t.monaco,r=ap(t,["monaco"]);Tl(function(l){return{config:Nc(l.config,r),monaco:n}})}function Vp(){var e=dr(function(t){var n=t.monaco,r=t.isInitialized,l=t.resolve;return{monaco:n,isInitialized:r,resolve:l}});if(!e.isInitialized){if(Tl({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),oo(io);if(window.monaco&&window.monaco.editor)return Oc(window.monaco),e.resolve(window.monaco),oo(io);Fp(Bp,Wp)(Qp)}return oo(io)}function Bp(e){return document.body.appendChild(e)}function Hp(e){var t=document.createElement("script");return e&&(t.src=e),t}function Wp(e){var t=dr(function(r){var l=r.config,o=r.reject;return{config:l,reject:o}}),n=Hp("".concat(t.config.paths.vs,"/loader.js"));return n.onload=function(){return e()},n.onerror=t.reject,n}function Qp(){var e=dr(function(n){var r=n.config,l=n.resolve,o=n.reject;return{config:r,resolve:l,reject:o}}),t=window.require;t.config(e.config),t(["vs/editor/editor.main"],function(n){Oc(n),e.resolve(n)},function(n){e.reject(n)})}function Oc(e){dr().monaco||Tl({monaco:e})}function Kp(){return dr(function(e){var t=e.monaco;return t})}var io=new Promise(function(e,t){return Tl({resolve:e,reject:t})}),jc={config:Ap,init:Vp,__getMonacoInstance:Kp},Yp={wrapper:{display:"flex",position:"relative",textAlign:"initial"},fullWidth:{width:"100%"},hide:{display:"none"}},uo=Yp,Xp={container:{display:"flex",height:"100%",width:"100%",justifyContent:"center",alignItems:"center"}},Gp=Xp;function Zp({children:e}){return Mt.createElement("div",{style:Gp.container},e)}var Jp=Zp,qp=Jp;function bp({width:e,height:t,isEditorReady:n,loading:r,_ref:l,className:o,wrapperProps:i}){return Mt.createElement("section",{style:{...uo.wrapper,width:e,height:t},...i},!n&&Mt.createElement(qp,null,r),Mt.createElement("div",{ref:l,style:{...uo.fullWidth,...!n&&uo.hide},className:o}))}var em=bp,Lc=O.memo(em);function tm(e){O.useEffect(e,[])}var Tc=tm;function nm(e,t,n=!0){let r=O.useRef(!0);O.useEffect(r.current||!n?()=>{r.current=!1}:e,t)}var Ee=nm;function Bn(){}function nn(e,t,n,r){return rm(e,r)||lm(e,t,n,r)}function rm(e,t){return e.editor.getModel(Mc(e,t))}function lm(e,t,n,r){return e.editor.createModel(t,n,r?Mc(e,r):void 0)}function Mc(e,t){return e.Uri.parse(t)}function om({original:e,modified:t,language:n,originalLanguage:r,modifiedLanguage:l,originalModelPath:o,modifiedModelPath:i,keepCurrentOriginalModel:u=!1,keepCurrentModifiedModel:s=!1,theme:c="light",loading:h="Loading...",options:m={},height:p="100%",width:w="100%",className:E,wrapperProps:C={},beforeMount:$=Bn,onMount:f=Bn}){let[a,d]=O.useState(!1),[v,y]=O.useState(!0),x=O.useRef(null),S=O.useRef(null),N=O.useRef(null),z=O.useRef(f),k=O.useRef($),V=O.useRef(!1);Tc(()=>{let T=jc.init();return T.then(A=>(S.current=A)&&y(!1)).catch(A=>(A==null?void 0:A.type)!=="cancelation"&&console.error("Monaco initialization: error:",A)),()=>x.current?ot():T.cancel()}),Ee(()=>{let T=x.current.getModifiedEditor();T.getOption(S.current.editor.EditorOption.readOnly)?T.setValue(t||""):t!==T.getValue()&&(T.executeEdits("",[{range:T.getModel().getFullModelRange(),text:t||"",forceMoveMarkers:!0}]),T.pushUndoStop())},[t],a),Ee(()=>{var T,A;(A=(T=x.current)==null?void 0:T.getModel())==null||A.original.setValue(e||"")},[e],a),Ee(()=>{let{original:T,modified:A}=x.current.getModel();S.current.editor.setModelLanguage(T,r||n||"text"),S.current.editor.setModelLanguage(A,l||n||"text")},[n,r,l],a),Ee(()=>{var T;(T=S.current)==null||T.editor.setTheme(c)},[c],a),Ee(()=>{var T;(T=x.current)==null||T.updateOptions(m)},[m],a);let ie=O.useCallback(()=>{var ze;if(!S.current)return;k.current(S.current);let T=nn(S.current,e||"",r||n||"text",o||""),A=nn(S.current,t||"",l||n||"text",i||"");(ze=x.current)==null||ze.setModel({original:T,modified:A})},[n,t,l,e,r,o,i]),Be=O.useCallback(()=>{var T;!V.current&&N.current&&(x.current=S.current.editor.createDiffEditor(N.current,{automaticLayout:!0,...m}),ie(),(T=S.current)==null||T.editor.setTheme(c),d(!0),V.current=!0)},[m,c,ie]);O.useEffect(()=>{a&&z.current(x.current,S.current)},[a]),O.useEffect(()=>{!v&&!a&&Be()},[v,a,Be]),Ee(()=>{if(x.current&&S.current){let T=x.current.getOriginalEditor(),A=nn(S.current,e||"",r||n||"text",o||"");A!==T.getModel()&&T.setModel(A)}},[o],a),Ee(()=>{if(x.current&&S.current){let T=x.current.getModifiedEditor(),A=nn(S.current,t||"",l||n||"text",i||"");A!==T.getModel()&&T.setModel(A)}},[i],a);function ot(){var A,ze,_,L;let T=(A=x.current)==null?void 0:A.getModel();u||((ze=T==null?void 0:T.original)==null||ze.dispose()),s||((_=T==null?void 0:T.modified)==null||_.dispose()),(L=x.current)==null||L.dispose()}return Mt.createElement(Lc,{width:w,height:p,isEditorReady:a,loading:h,_ref:N,className:E,wrapperProps:C})}var im=om;O.memo(im);function um(e){let t=O.useRef();return O.useEffect(()=>{t.current=e},[e]),t.current}var sm=um,Tr=new Map;function am({defaultValue:e,defaultLanguage:t,defaultPath:n,value:r,language:l,path:o,theme:i="light",line:u,loading:s="Loading...",options:c={},overrideServices:h={},saveViewState:m=!0,keepCurrentModel:p=!1,width:w="100%",height:E="100%",className:C,wrapperProps:$={},beforeMount:f=Bn,onMount:a=Bn,onChange:d,onValidate:v=Bn}){let[y,x]=O.useState(!1),[S,N]=O.useState(!0),z=O.useRef(null),k=O.useRef(null),V=O.useRef(null),ie=O.useRef(a),Be=O.useRef(f),ot=O.useRef(),T=O.useRef(r),A=sm(o),ze=O.useRef(!1),_=O.useRef(!1);Tc(()=>{let j=jc.init();return j.then(M=>(z.current=M)&&N(!1)).catch(M=>(M==null?void 0:M.type)!=="cancelation"&&console.error("Monaco initialization: error:",M)),()=>k.current?R():j.cancel()}),Ee(()=>{var M,ee,Se,He;let j=nn(z.current,e||r||"",t||l||"",o||n||"");j!==((M=k.current)==null?void 0:M.getModel())&&(m&&Tr.set(A,(ee=k.current)==null?void 0:ee.saveViewState()),(Se=k.current)==null||Se.setModel(j),m&&((He=k.current)==null||He.restoreViewState(Tr.get(o))))},[o],y),Ee(()=>{var j;(j=k.current)==null||j.updateOptions(c)},[c],y),Ee(()=>{!k.current||r===void 0||(k.current.getOption(z.current.editor.EditorOption.readOnly)?k.current.setValue(r):r!==k.current.getValue()&&(_.current=!0,k.current.executeEdits("",[{range:k.current.getModel().getFullModelRange(),text:r,forceMoveMarkers:!0}]),k.current.pushUndoStop(),_.current=!1))},[r],y),Ee(()=>{var M,ee;let j=(M=k.current)==null?void 0:M.getModel();j&&l&&((ee=z.current)==null||ee.editor.setModelLanguage(j,l))},[l],y),Ee(()=>{var j;u!==void 0&&((j=k.current)==null||j.revealLine(u))},[u],y),Ee(()=>{var j;(j=z.current)==null||j.editor.setTheme(i)},[i],y);let L=O.useCallback(()=>{var j;if(!(!V.current||!z.current)&&!ze.current){Be.current(z.current);let M=o||n,ee=nn(z.current,r||e||"",t||l||"",M||"");k.current=(j=z.current)==null?void 0:j.editor.create(V.current,{model:ee,automaticLayout:!0,...c},h),m&&k.current.restoreViewState(Tr.get(M)),z.current.editor.setTheme(i),x(!0),ze.current=!0}},[e,t,n,r,l,o,c,h,m,i]);O.useEffect(()=>{y&&ie.current(k.current,z.current)},[y]),O.useEffect(()=>{!S&&!y&&L()},[S,y,L]),T.current=r,O.useEffect(()=>{var j,M;y&&d&&((j=ot.current)==null||j.dispose(),ot.current=(M=k.current)==null?void 0:M.onDidChangeModelContent(ee=>{_.current||d(k.current.getValue(),ee)}))},[y,d]),O.useEffect(()=>{if(y){let j=z.current.editor.onDidChangeMarkers(M=>{var Se;let ee=(Se=k.current.getModel())==null?void 0:Se.uri;if(ee&&M.find(He=>He.path===ee.path)){let He=z.current.editor.getModelMarkers({resource:ee});v==null||v(He)}});return()=>{j==null||j.dispose()}}return()=>{}},[y,v]);function R(){var j,M;(j=ot.current)==null||j.dispose(),p?m&&Tr.set(o,k.current.saveViewState()):(M=k.current.getModel())==null||M.dispose(),k.current.dispose()}return Mt.createElement(Lc,{width:w,height:E,isEditorReady:y,loading:s,_ref:V,className:C,wrapperProps:$})}var cm=am,fm=O.memo(cm),dm=fm;function fs(e,t=0){const n=["Bytes","KB","MB","GB","TB"];if(e===0)return"0 Bytes";const r=parseInt(Math.floor(Math.log(e)/Math.log(1e3)),10);return(e/Math.pow(1e3,r)).toFixed(t)+" "+n[r]}function pm({data:e}){const t=e.progress??0,n=e.file,r=fs(e.loaded),l=fs(e.total);return I.jsx("div",{className:"progress-container",children:I.jsxs("div",{className:"progress-bar",style:{width:`${t}%`},children:[n," (",`${r} / ${l}`,")"]})})}const ds=["Xenova/tiny_starcoder_py","Xenova/codegen-350M-mono","Xenova/starcoderbase-1b-sft"];function mm(){const e=O.useRef(null),[t,n]=O.useState(!1),[r,l]=O.useState("python"),[o,i]=O.useState(null),[u,s]=O.useState(!1),[c,h]=O.useState([]),[m,p]=O.useState(ds[0]),[w,E]=O.useState(45),[C,$]=O.useState(`
51
  def fib(n):
52
  """Calculates the nth Fibonacci number"""
53
  `),[f,a]=O.useState(.5),[d,v]=O.useState(5),[y,x]=O.useState(!1),S=O.useRef(null);O.useEffect(()=>{S.current||(S.current=new Worker(new URL("/assets/worker-5130d00f.js",self.location),{type:"module"}));const z=k=>{switch(k.data.status){case"initiate":i(!1),h(V=>[...V,k.data]);break;case"progress":h(V=>V.map(ie=>ie.file===k.data.file?{...ie,...k.data}:ie));break;case"done":h(V=>V.filter(ie=>ie.file!==k.data.file));break;case"ready":i(!0);break;case"update":$(k.data.output);break;case"complete":s(!1);break}};return S.current.addEventListener("message",z),()=>S.current.removeEventListener("message",z)}),O.useEffect(()=>{const z=e.current;if(!z)return;let k=z.addAction({id:"generate",label:"Generate",contextMenuGroupId:"0_custom",run:()=>{const V=z.getValue();V&&S.current.postMessage({model:m,text:V,max_new_tokens:w,temperature:f,top_k:d,do_sample:y})}});return()=>k.dispose()},[t,m,w,f,d,y]);const N=o===!1||c.length>0;return I.jsxs("div",{className:"flex h-screen w-screen",children:[I.jsxs("div",{className:"gap-1 z-50 top-0 left-0 absolute w-full h-full transition-all px-32 flex flex-col justify-center text-center",style:{opacity:N?1:0,pointerEvents:N?"all":"none",background:"rgba(0, 0, 0, 0.5)",backdropFilter:"blur(4px)"},children:[o===!1&&I.jsx("label",{className:"text-3xl p-3",children:"Loading model..."}),c.map(z=>I.jsx("div",{children:I.jsx(pm,{data:z})},z.file))]}),I.jsx("div",{children:I.jsx(dm,{width:"calc(100vw - 360px)",language:r,value:C,theme:"vs-dark",onMount:z=>{e.current=z,n(!0)},options:{fontSize:24}})}),I.jsxs("div",{className:"flex-grow sidebar p-4 flex flex-col overflow-y-auto",children:[I.jsx("h2",{className:"text-2xl font-semibold text-center mb-1",children:"In-browser code completion"}),I.jsxs("div",{className:"text-center",children:["Made with ",I.jsx("a",{className:"text-white ital underline",href:"https://github.com/xenova/transformers.js",children:"🤗 Transformers.js"})]}),I.jsx("label",{className:"mt-3",children:"Model:"}),I.jsx("select",{value:m,onChange:z=>p(z.target.value),className:"p-2.5 bg-gray-50 border border-gray-200 text-gray-900 rounded-lg",children:ds.map((z,k)=>I.jsx("option",{value:z,children:z},k))}),I.jsxs("div",{className:"mt-3 flex justify-between",children:[I.jsx("label",{children:"Max new tokens:"}),I.jsx("label",{children:w})]}),I.jsx("input",{type:"range",min:"1",max:"512",value:w,onChange:z=>{const k=parseInt(z.target.value);E(k)}}),I.jsxs("div",{className:"mt-3 flex justify-between",children:[I.jsx("label",{children:"Temperature:"}),I.jsx("label",{children:f})]}),I.jsx("input",{type:"range",min:"0",step:"0.05",max:"1",value:f,onChange:z=>{const k=Number(z.target.value);a(k)}}),I.jsxs("div",{className:"mt-3 flex items-center",children:[I.jsx("input",{id:"default-checkbox",type:"checkbox",value:y,onInput:z=>{x(z.target.checked)},className:"w-4 h-4 text-blue-600 rounded focus:ring-blue-600 ring-offset-gray-800 focus:ring-2 bg-gray-700 border-gray-600"}),I.jsx("label",{htmlFor:"default-checkbox",className:"ml-2 font-medium",children:"Sample"})]}),I.jsxs("div",{className:"mt-3 flex justify-between",style:{opacity:y?1:.2},children:[I.jsx("label",{children:"Top K:"}),I.jsx("label",{children:d})]}),I.jsx("input",{disabled:!y,style:{opacity:y?1:.2},type:"range",min:"0",max:"50",value:d,onChange:z=>{const k=parseInt(z.target.value);v(k)}}),I.jsx("div",{className:"flex-grow"}),I.jsxs("div",{className:"flex gap-2 justify-center mt-3",children:[I.jsx("svg",{className:"w-6 h-6 text-white","aria-hidden":"true",xmlns:"http://www.w3.org/2000/svg",fill:"currentColor",viewBox:"0 0 20 20",children:I.jsx("path",{fillRule:"evenodd",d:"M10 .333A9.911 9.911 0 0 0 6.866 19.65c.5.092.678-.215.678-.477 0-.237-.01-1.017-.014-1.845-2.757.6-3.338-1.169-3.338-1.169a2.627 2.627 0 0 0-1.1-1.451c-.9-.615.07-.6.07-.6a2.084 2.084 0 0 1 1.518 1.021 2.11 2.11 0 0 0 2.884.823c.044-.503.268-.973.63-1.325-2.2-.25-4.516-1.1-4.516-4.9A3.832 3.832 0 0 1 4.7 7.068a3.56 3.56 0 0 1 .095-2.623s.832-.266 2.726 1.016a9.409 9.409 0 0 1 4.962 0c1.89-1.282 2.717-1.016 2.717-1.016.366.83.402 1.768.1 2.623a3.827 3.827 0 0 1 1.02 2.659c0 3.807-2.319 4.644-4.525 4.889a2.366 2.366 0 0 1 .673 1.834c0 1.326-.012 2.394-.012 2.72 0 .263.18.572.681.475A9.911 9.911 0 0 0 10 .333Z",clipRule:"evenodd"})}),I.jsx("a",{className:"text-white font-normal underline underline-offset-1",href:"https://github.com/xenova/transformers.js/tree/main/examples/code-completion",children:"Source code"})]})]})]})}so.createRoot(document.getElementById("root")).render(I.jsx(Mt.StrictMode,{children:I.jsx(mm,{})}));