From 02f57f0c38a357db6ee42243660ab57ef29ad3c2 Mon Sep 17 00:00:00 2001 From: Jay Wang Date: Fri, 9 Feb 2024 05:00:16 -0500 Subject: [PATCH] Deploy 7c588579e9ec7be783fb4fa1df792041b6886fb5 --- assets/{main-bunx7bzE.js => main-h9FkW8KM.js} | 6 +++--- index.html | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) rename assets/{main-bunx7bzE.js => main-h9FkW8KM.js} (99%) diff --git a/assets/main-bunx7bzE.js b/assets/main-h9FkW8KM.js similarity index 99% rename from assets/main-bunx7bzE.js rename to assets/main-h9FkW8KM.js index 6aa486d..cd86b67 100644 --- a/assets/main-bunx7bzE.js +++ b/assets/main-h9FkW8KM.js @@ -1865,7 +1865,7 @@ If a question does not make any sense, or is not factually coherent, explain why {{user}} -{{context}}`,promptTemplates={"arxiv-1k":arXivTemplates,"arxiv-10k":arXivTemplates,"arxiv-120k":arXivTemplates,"diffusiondb-10k":diffusiondbTemplates,"diffusiondb-100k":diffusiondbTemplates,"diffusiondb-500k":diffusiondbTemplates,"diffusiondb-1m":diffusiondbTemplates,"accident-3k":accidentTemplates},arXivQueries=["How to integrate information retrieval into machine learning systems?","What are the best practices for preprocessing data for machine learning models?","How can we improve the interpretability of deep learning models?","What are effective methods for dealing with imbalanced datasets in classification tasks?","How can transfer learning be applied to small datasets in a specific domain?","What are the challenges and solutions for real-time machine learning predictions?","How can unsupervised learning techniques improve data understanding in unlabeled datasets?","What are the key factors in choosing between traditional machine learning algorithms and deep learning approaches?","How can machine learning be used to enhance cybersecurity defenses?","What are the ethical considerations in developing and deploying machine learning models?","How can reinforcement learning be applied to optimize decision-making processes in business?","What are the current limitations of natural language processing models, and how can they be addressed?","How can machine learning contribute to personalized medicine and healthcare?","What strategies can be used to reduce overfitting in complex machine learning models?","How can machine learning algorithms be adapted for energy-efficient computing?","What are the implications of federated learning for privacy-preserving machine learning?","How can anomaly detection be improved in machine learning models for fraud detection?","What role does feature engineering play in improving the performance of machine learning models?","How can machine learning be integrated with blockchain technology for enhanced security?","What are the challenges in scaling machine learning models for large-scale applications?","How can machine learning techniques be applied to predict and mitigate the effects of climate change?"],diffusiondbQueries=["A cute brown dog jumping around","White dog wandering through a dense forest","Red apple resting on an aged wooden table","Sunny field dotted with vibrant sunflowers","Blue boat gently floating on a tranquil lake","Green frog perched on a lily pad, eyeing its surroundings","Brown horse galloping across a wide-open meadow","Gray cat curled up, napping on a cozy windowsill","Black bicycle leaning against a graffiti-covered city wall","Orange pumpkin nestled among leaves in a patch","Pink flamingo standing gracefully at the water's edge","Purple butterfly fluttering around a fragrant lavender bush","Goldfish swimming circles in a sparkling fishbowl","Rainbow arching majestically over a lush mountain landscape","Silver key lying atop an ancient, leather-bound book","Colorful parrot perched in the dense canopy of a tropical jungle","Snowman adorned with a carrot nose in a snowy field","Red and white lighthouse standing guard by the rocky coastline","Blue and yellow beach umbrella casting a cool shadow on sandy shores","Chocolate cupcake topped with a rich, creamy swirl on a festive plate","Pair of red sneakers ready at the start line of a running track'"],accidentQueries=["What are some potential harms associated with facial recognition systems?","How could a loan approval ML system inadvertently reinforce existing societal biases?","What risks are involved with an ML-based healthcare diagnosis tool providing incorrect treatment recommendations?","How might a job applicant screening ML system discriminate against certain candidates based on non-job-related characteristics?","What if an autonomous driving ML system fails to correctly interpret road signs or pedestrian signals in different weather conditions?","Could an ML content recommendation system on social media promote harmful or extremist content?","What are the privacy concerns with an ML-powered personal assistant listening to and analyzing private conversations?","How might an ML-powered stock trading system contribute to market instability or unfair trading advantages?","What if an ML-based wildfire prediction system provides inaccurate forecasts, leading to insufficient disaster preparedness?","How could an ML model used for educational content personalization create learning gaps or reinforce stereotypes?","What are the implications of an ML system for energy grid management malfunctioning and causing widespread power outages?","How might an ML-powered emotion detection system in advertising manipulate consumer behavior unethically?","What if an ML model used in wildlife conservation misidentifies species and leads to inappropriate conservation efforts?","Could an ML-based sentencing recommendation tool in the legal system perpetuate racial or gender biases?","What are the potential consequences of an ML-driven agricultural advice system providing incorrect farming guidance?","How might an ML-based air traffic control system's malfunction lead to flight safety risks?","What if an ML algorithm for detecting online bullying overlooks certain forms of harassment, leaving victims unprotected?","How could an ML-powered credit scoring system unfairly lower someone's credit score based on non-financial personal data?","What if an ML-based disaster response system prioritizes resources in a way that discriminates against certain communities?","How might an ML system designed to filter out fake news inadvertently censor legitimate information or viewpoints?"],userQueries={"arxiv-1k":arXivQueries,"arxiv-10k":arXivQueries,"arxiv-120k":arXivQueries,"diffusiondb-10k":diffusiondbQueries,"diffusiondb-100k":diffusiondbQueries,"diffusiondb-500k":diffusiondbQueries,"diffusiondb-1m":diffusiondbQueries,"accident-3k":accidentQueries},componentCSS$8=".query-box{width:100%;display:flex;box-sizing:border-box;flex-direction:column;align-items:center;padding:var(--box-padding-v) var(--box-padding-h);gap:5px}textarea{border:1px solid var(--gray-300);border-radius:5px;padding:5px;width:100%;height:60px;box-sizing:border-box;font-family:inherit;font-size:var(--content-text-size);resize:vertical;min-height:50px}textarea:focus{outline:2px solid var(--focus-border-color);border:1px solid var(--focus-border-color)}textarea::placeholder{color:var(--gray-600)}.header{font-size:var(--header-size);color:var(--gray-600);line-height:1;width:100%;display:flex;flex-direction:row;justify-content:center;align-items:center;gap:10px}.header .text{font-weight:800}.svg-icon{display:flex;justify-content:center;align-items:center;width:1em;height:1em;color:currentColor;transition:transform 80ms linear;transform-origin:center}.svg-icon svg{fill:currentColor;width:100%;height:100%}.button-group{display:flex;flex-flow:row;align-items:center;gap:8px}button{all:unset;line-height:1;padding:4px 6px;border-radius:5px;white-space:nowrap;cursor:pointer;user-select:none;-webkit-user-select:none;background-color:color-mix(in lab,var(--gray-200),white 20%);color:var(--gray-800);display:flex;flex-flow:row;align-items:center;font-size:var(--header-secondary-size);height:1em}button:hover{background-color:color-mix(in lab,var(--gray-300),white 30%)}button:active{background-color:color-mix(in lab,var(--gray-300),white 20%)}button .svg-icon{position:relative;top:1px;margin-right:3px;color:var(--gray-700);width:12px;height:12px}",refreshIcon=` +{{context}}`,promptTemplates={"arxiv-1k":arXivTemplates,"arxiv-10k":arXivTemplates,"arxiv-120k":arXivTemplates,"diffusiondb-10k":diffusiondbTemplates,"diffusiondb-100k":diffusiondbTemplates,"diffusiondb-500k":diffusiondbTemplates,"diffusiondb-1m":diffusiondbTemplates,"accident-3k":accidentTemplates},arXivQueries=["How to integrate information retrieval into machine learning systems?","What are the best practices for preprocessing data for machine learning models?","How can we improve the interpretability of deep learning models?","What are effective methods for dealing with imbalanced datasets in classification tasks?","How can transfer learning be applied to small datasets in a specific domain?","What are the challenges and solutions for real-time machine learning predictions?","How can unsupervised learning techniques improve data understanding in unlabeled datasets?","What are the key factors in choosing between traditional machine learning algorithms and deep learning approaches?","How can machine learning be used to enhance cybersecurity defenses?","What are the ethical considerations in developing and deploying machine learning models?","How can reinforcement learning be applied to optimize decision-making processes in business?","What are the current limitations of natural language processing models, and how can they be addressed?","How can machine learning contribute to personalized medicine and healthcare?","What strategies can be used to reduce overfitting in complex machine learning models?","How can machine learning algorithms be adapted for energy-efficient computing?","What are the implications of federated learning for privacy-preserving machine learning?","How can anomaly detection be improved in machine learning models for fraud detection?","What role does feature engineering play in improving the performance of machine learning models?","How can machine learning be integrated with blockchain technology for enhanced security?","What are the challenges in scaling machine learning models for large-scale applications?","How can machine learning techniques be applied to predict and mitigate the effects of climate change?"],diffusiondbQueries=["A cute brown dog jumps around the tree","White dog wandering through a dense forest","Red apple resting on an aged wooden table","Sunny field dotted with vibrant sunflowers","Blue boat gently floating on a tranquil lake","Green frog perched on a lily pad, eyeing its surroundings","Brown horse galloping across a wide-open meadow","Gray cat curled up, napping on a cozy windowsill","Black bicycle leaning against a graffiti-covered city wall","Orange pumpkin nestled among leaves in a patch","Pink flamingo standing gracefully at the water's edge","Purple butterfly fluttering around a fragrant lavender bush","Goldfish swimming circles in a sparkling fishbowl","Rainbow arching majestically over a lush mountain landscape","Silver key lying atop an ancient, leather-bound book","Colorful parrot perched in the dense canopy of a tropical jungle","Snowman adorned with a carrot nose in a snowy field","Red and white lighthouse standing guard by the rocky coastline","Blue and yellow beach umbrella casting a cool shadow on sandy shores","Chocolate cupcake topped with a rich, creamy swirl on a festive plate","Pair of red sneakers ready at the start line of a running track'"],accidentQueries=["What are some potential harms associated with facial recognition systems?","How could a loan approval ML system inadvertently reinforce existing societal biases?","What risks are involved with an ML-based healthcare diagnosis tool providing incorrect treatment recommendations?","How might a job applicant screening ML system discriminate against certain candidates based on non-job-related characteristics?","What if an autonomous driving ML system fails to correctly interpret road signs or pedestrian signals in different weather conditions?","Could an ML content recommendation system on social media promote harmful or extremist content?","What are the privacy concerns with an ML-powered personal assistant listening to and analyzing private conversations?","How might an ML-powered stock trading system contribute to market instability or unfair trading advantages?","What if an ML-based wildfire prediction system provides inaccurate forecasts, leading to insufficient disaster preparedness?","How could an ML model used for educational content personalization create learning gaps or reinforce stereotypes?","What are the implications of an ML system for energy grid management malfunctioning and causing widespread power outages?","How might an ML-powered emotion detection system in advertising manipulate consumer behavior unethically?","What if an ML model used in wildlife conservation misidentifies species and leads to inappropriate conservation efforts?","Could an ML-based sentencing recommendation tool in the legal system perpetuate racial or gender biases?","What are the potential consequences of an ML-driven agricultural advice system providing incorrect farming guidance?","How might an ML-based air traffic control system's malfunction lead to flight safety risks?","What if an ML algorithm for detecting online bullying overlooks certain forms of harassment, leaving victims unprotected?","How could an ML-powered credit scoring system unfairly lower someone's credit score based on non-financial personal data?","What if an ML-based disaster response system prioritizes resources in a way that discriminates against certain communities?","How might an ML system designed to filter out fake news inadvertently censor legitimate information or viewpoints?"],userQueries={"arxiv-1k":arXivQueries,"arxiv-10k":arXivQueries,"arxiv-120k":arXivQueries,"diffusiondb-10k":diffusiondbQueries,"diffusiondb-100k":diffusiondbQueries,"diffusiondb-500k":diffusiondbQueries,"diffusiondb-1m":diffusiondbQueries,"accident-3k":accidentQueries},componentCSS$8=".query-box{width:100%;display:flex;box-sizing:border-box;flex-direction:column;align-items:center;padding:var(--box-padding-v) var(--box-padding-h);gap:5px}textarea{border:1px solid var(--gray-300);border-radius:5px;padding:5px;width:100%;height:60px;box-sizing:border-box;font-family:inherit;font-size:var(--content-text-size);resize:vertical;min-height:50px}textarea:focus{outline:2px solid var(--focus-border-color);border:1px solid var(--focus-border-color)}textarea::placeholder{color:var(--gray-600)}.header{font-size:var(--header-size);color:var(--gray-600);line-height:1;width:100%;display:flex;flex-direction:row;justify-content:center;align-items:center;gap:10px}.header .text{font-weight:800}.svg-icon{display:flex;justify-content:center;align-items:center;width:1em;height:1em;color:currentColor;transition:transform 80ms linear;transform-origin:center}.svg-icon svg{fill:currentColor;width:100%;height:100%}.button-group{display:flex;flex-flow:row;align-items:center;gap:8px}button{all:unset;line-height:1;padding:4px 6px;border-radius:5px;white-space:nowrap;cursor:pointer;user-select:none;-webkit-user-select:none;background-color:color-mix(in lab,var(--gray-200),white 20%);color:var(--gray-800);display:flex;flex-flow:row;align-items:center;font-size:var(--header-secondary-size);height:1em}button:hover{background-color:color-mix(in lab,var(--gray-300),white 30%)}button:active{background-color:color-mix(in lab,var(--gray-300),white 20%)}button .svg-icon{position:relative;top:1px;margin-right:3px;color:var(--gray-700);width:12px;height:12px}",refreshIcon=` @@ -2431,7 +2431,7 @@ WARNING: Falling back to ${Q(134217728)}...`),J=134217728,134217728>D.limits.max -`;var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=(D,Q,F,J)=>{for(var G=J>1?void 0:J?__getOwnPropDesc$1(Q,F):Q,O=D.length-1,Y;O>=0;O--)(Y=D[O])&&(G=(J?Y(Q,F,G):Y(G))||G);return J&&G&&__defProp$1(Q,F,G),G};const REMOTE_ENDPOINT="https://pub-4eccf317e01e4aa3a5caa9991c8b1e2a.r2.dev/",STORE_ENDPOINT=REMOTE_ENDPOINT;var Dataset=(D=>(D.arXiv1k="arxiv-1k",D.arXiv10k="arxiv-10k",D.arXiv120k="arxiv-120k",D.DiffusionDB10k="diffusiondb-10k",D.DiffusionDB100k="diffusiondb-100k",D.DiffusionDB500k="diffusiondb-500k",D.DiffusionDB1m="diffusiondb-1m",D.accident3k="accident-3k",D))(Dataset||{}),Arrow=(D=>(D.Search="search",D.Input="input",D.Document="document",D.Output="output",D))(Arrow||{});const promptTemplate=promptTemplates,datasets={"arxiv-1k":{indexURL:STORE_ENDPOINT+"ml-arxiv-papers-index-1k.json.gzip",dataURL:STORE_ENDPOINT+"ml-arxiv-papers-1k.ndjson.gzip",datasetName:"ml-arxiv-papers-1k",datasetNameDisplay:"ML arXiv Abstracts (1k)"},"arxiv-10k":{indexURL:STORE_ENDPOINT+"ml-arxiv-papers-index-10k.json.gzip",dataURL:STORE_ENDPOINT+"ml-arxiv-papers-10k.ndjson.gzip",datasetName:"ml-arxiv-papers-10k",datasetNameDisplay:"ML arXiv Abstracts (10k)"},"arxiv-120k":{indexURL:REMOTE_ENDPOINT+"ml-arxiv-papers-index-120k.json.gzip",dataURL:REMOTE_ENDPOINT+"ml-arxiv-papers-120k.ndjson.gzip",datasetName:"ml-arxiv-papers-120k",datasetNameDisplay:"ML arXiv Abstracts (120k)"},"diffusiondb-10k":{indexURL:REMOTE_ENDPOINT+"diffusiondb-prompt-index-10k.json.gzip",dataURL:REMOTE_ENDPOINT+"diffusiondb-prompt-10k.ndjson.gzip",datasetName:"diffusiondb-prompts-10k",datasetNameDisplay:"DiffusionDB Prompts (10k)"},"diffusiondb-100k":{indexURL:REMOTE_ENDPOINT+"diffusiondb-prompt-index-100k.json.gzip",dataURL:REMOTE_ENDPOINT+"diffusiondb-prompt-100k.ndjson.gzip",datasetName:"diffusiondb-prompts-100k",datasetNameDisplay:"DiffusionDB Prompts (100k)"},"diffusiondb-500k":{indexURL:REMOTE_ENDPOINT+"diffusiondb-prompt-index-500k.json.gzip",dataURL:REMOTE_ENDPOINT+"diffusiondb-prompt-500k.ndjson.gzip",datasetName:"diffusiondb-prompts-500k",datasetNameDisplay:"DiffusionDB Prompts (500k)"},"diffusiondb-1m":{indexURL:REMOTE_ENDPOINT+"diffusiondb-prompt-index-1m.json.gzip",dataURL:REMOTE_ENDPOINT+"diffusiondb-prompt-1m.ndjson.gzip",datasetName:"diffusiondb-prompts-1m",datasetNameDisplay:"DiffusionDB Prompts (1M)"},"accident-3k":{indexURL:STORE_ENDPOINT+"accident-index-3k.json.gzip",dataURL:STORE_ENDPOINT+"accident-3k.ndjson.gzip",datasetName:"accidents-3k",datasetNameDisplay:"AI Accidents (3k)"}},DEV_MODE=!1,USE_CACHE=DEV_MODE,FORMATTER=d3.format(",");let MememoPlayground=class extends s{constructor(){super(),this.curDataset="arxiv-10k",this.userQuery="",this.relevantDocuments=[],this.llmOutput="",this.embeddingWorkerRequestCount=0,this.topK=10,this.efSearch=100,this.isSearching=!1,this.searchRunTime=null,this.searchStartTime=0,this.encodeFinishTime=0,this.isRunningLLM=!1,this.LLMRunTime=null,this.LLMStartTime=0,this.toastMessage="",this.toastType="success",this.textGenLocalWorkerResolve=Q=>{},this.arrowElements={document:null,input:null,search:null,output:null},this.embeddingWorker=new WorkerWrapper,this.embeddingWorker.addEventListener("message",Q=>{this.embeddingWorkerMessageHandler(Q)}),this.textGenLocalWorker=new WorkerWrapper$1,this.textGenLocalWorker.addEventListener("message",Q=>{this.textGenLocalWorkerMessageHandler(Q)});const D=Q=>{this.userConfig=Q};this.userConfigManager=new UserConfigManager(D)}get embeddingWorkerRequestID(){return this.embeddingWorkerRequestCount++,`prompt-panel-${this.embeddingWorkerRequestCount}`}firstUpdated(){if(!this.shadowRoot)throw Error("No shadow root.");this.arrowElements={document:this.shadowRoot.querySelector(".flow.text-prompt"),input:this.shadowRoot.querySelector(".flow.input-prompt"),search:this.shadowRoot.querySelector(".flow.input-text"),output:this.shadowRoot.querySelector(".flow.prompt-output")}}willUpdate(D){}disconnectedCallback(){var D;this.embeddingWorker.terminate(),this.textGenLocalWorker.terminate(),(D=this.textViewerComponent)==null||D.mememoWorker.terminate()}async initData(){}getEmbedding(D){this.searchRunTime=null,this.searchStartTime=Date.now(),this.isSearching=!0;const Q={command:"startExtractEmbedding",payload:{detail:"",requestID:this.embeddingWorkerRequestID,model:EmbeddingModel.gteSmall,sentences:D,windowURL:window.location.href}};this.embeddingWorker.postMessage(Q)}semanticSearch(D){var Q;if(!this.textViewerComponent)throw Error("textViewerComponent is not initialized.");(Q=this.arrowElements.search)==null||Q.classList.add("running"),this.textViewerComponent.semanticSearch(D,this.topK,.5,this.efSearch)}userQueryRunClickHandler(D){var Q;this.userQuery=D.detail,this.getEmbedding([this.userQuery]),(Q=this.arrowElements.input)==null||Q.classList.add("activated")}promptRunClickHandler(D){const Q=D.detail;this._runPrompt(Q)}semanticSearchFinishedHandler(D){var Q,F,J;this.relevantDocuments=D.detail,this.searchRunTime=[this.encodeFinishTime-this.searchStartTime,Date.now()-this.searchStartTime],this.isSearching=!1,(Q=this.arrowElements.search)==null||Q.classList.remove("running"),(F=this.arrowElements.search)==null||F.classList.add("activated"),(J=this.arrowElements.document)==null||J.classList.add("activated")}embeddingWorkerMessageHandler(D){switch(D.data.command){case"finishExtractEmbedding":{const{embeddings:Q}=D.data.payload;this.encodeFinishTime=Date.now(),this.semanticSearch(Q[0]);break}case"error":{console.error("Worker error: ",JSON.stringify(D.data.payload.message));break}default:{console.error("Worker: unknown message",D.data.command);break}}}parameterInputChanged(D,Q){const F=D.currentTarget;if(Q==="efSearch"){const J=parseInt(F.value);J>0?this.efSearch=J:this.efSearch=100,F.value=String(this.efSearch)}if(Q==="top-k"){const J=parseInt(F.value);J>0?this.topK=J:this.topK=10,F.value=String(this.topK)}}textGenLocalWorkerMessageHandler(D){switch(D.data.command){case"finishTextGen":{const Q={command:"finishTextGen",payload:D.data.payload};this.textGenLocalWorkerResolve(Q);break}case"progressLoadModel":break;case"finishLoadModel":break;case"error":{const Q={command:"error",payload:D.data.payload};this.textGenLocalWorkerResolve(Q);break}default:{console.error("Worker: unknown message",D.data.command);break}}}_reComputeMaxHeights(D){if(!this.shadowRoot||!this.queryBoxComponent||!this.promptBoxComponent||!this.containerInputElement||!this.containerPromptElement)throw Error("No shadow root.");const F=this.shadowRoot.querySelector(".playground").getBoundingClientRect(),J=82,G=175;if(D==="prompt"){const O=this.containerInputElement.getBoundingClientRect(),Y=F.height-O.height-J-G;this.promptBoxComponent.setTextareaMaxHeight(Y);const z=F.height-Y-J-G;this.queryBoxComponent.setTextareaMaxHeight(z)}else if(D==="input"){const O=this.containerPromptElement.getBoundingClientRect(),Y=F.height-O.height-J-G;this.queryBoxComponent.setTextareaMaxHeight(Y);const z=F.height-Y-J-G;this.promptBoxComponent.setTextareaMaxHeight(z)}}_deactivateAllArrows(){var D;for(const Q of Object.values(Arrow))(D=this.arrowElements[Q])==null||D.classList.remove("activated")}_runPrompt(D,Q=.2){var J;let F;switch(this.llmOutput="",this.LLMRunTime=null,this.LLMStartTime=Date.now(),this.isRunningLLM=!0,this.isRunningLLM=!0,(J=this.arrowElements.output)==null||J.classList.add("running"),this.userConfig.preferredLLM){case SupportedRemoteModel["gpt-3.5"]:{F=textGenGpt(this.userConfig.llmAPIKeys[ModelFamily.openAI],"text-gen",D,Q,"gpt-3.5-turbo",USE_CACHE);break}case SupportedRemoteModel["gpt-4"]:{F=textGenGpt(this.userConfig.llmAPIKeys[ModelFamily.openAI],"text-gen",D,Q,"gpt-4-1106-preview",USE_CACHE);break}case SupportedRemoteModel["gemini-pro"]:{F=textGenGemini(this.userConfig.llmAPIKeys[ModelFamily.google],"text-gen",D,Q,USE_CACHE);break}case SupportedLocalModel["phi-2"]:case SupportedLocalModel["llama-2-7b"]:case SupportedLocalModel["tinyllama-1.1b"]:{F=new Promise(O=>{this.textGenLocalWorkerResolve=O});const G={command:"startTextGen",payload:{apiKey:"",prompt:D,requestID:"",temperature:Q}};this.textGenLocalWorker.postMessage(G);break}case SupportedRemoteModel["gpt-3.5-free"]:{F=textGenMememo("text-gen",D,Q,"gpt-3.5-free",USE_CACHE);break}default:console.error("Unknown case ",this.userConfig.preferredLLM),F=textGenMememo("text-gen",D,Q,"gpt-3.5-free",USE_CACHE)}F.then(G=>{var O,Y,z,AA;switch(G.command){case"finishTextGen":{this.llmOutput=G.payload.result,this.LLMRunTime=Date.now()-this.LLMStartTime,this.isRunningLLM=!1,(O=this.arrowElements.output)==null||O.classList.remove("running"),(Y=this.arrowElements.output)==null||Y.classList.add("activated");break}case"error":console.error(G.payload.message),this.toastMessage="Fail to run this LLM. Try it again later or use a different model.",this.toastType="error",(z=this.toastComponent)==null||z.show(),this.LLMRunTime=null,this.isRunningLLM=!1,(AA=this.arrowElements.output)==null||AA.classList.remove("running")}},()=>{})}dialogClicked(D){D.target===this.dialogElement&&this.dialogElement.close()}render(){return x` +`;var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=(D,Q,F,J)=>{for(var G=J>1?void 0:J?__getOwnPropDesc$1(Q,F):Q,O=D.length-1,Y;O>=0;O--)(Y=D[O])&&(G=(J?Y(Q,F,G):Y(G))||G);return J&&G&&__defProp$1(Q,F,G),G};const REMOTE_ENDPOINT="https://pub-4eccf317e01e4aa3a5caa9991c8b1e2a.r2.dev/",STORE_ENDPOINT=REMOTE_ENDPOINT;var Dataset=(D=>(D.arXiv1k="arxiv-1k",D.arXiv10k="arxiv-10k",D.arXiv120k="arxiv-120k",D.DiffusionDB10k="diffusiondb-10k",D.DiffusionDB100k="diffusiondb-100k",D.DiffusionDB500k="diffusiondb-500k",D.DiffusionDB1m="diffusiondb-1m",D.accident3k="accident-3k",D))(Dataset||{}),Arrow=(D=>(D.Search="search",D.Input="input",D.Document="document",D.Output="output",D))(Arrow||{});const promptTemplate=promptTemplates,datasets={"arxiv-1k":{indexURL:STORE_ENDPOINT+"ml-arxiv-papers-index-1k.json.gzip",dataURL:STORE_ENDPOINT+"ml-arxiv-papers-1k.ndjson.gzip",datasetName:"ml-arxiv-papers-1k",datasetNameDisplay:"ML arXiv Abstracts (1k)"},"arxiv-10k":{indexURL:STORE_ENDPOINT+"ml-arxiv-papers-index-10k.json.gzip",dataURL:STORE_ENDPOINT+"ml-arxiv-papers-10k.ndjson.gzip",datasetName:"ml-arxiv-papers-10k",datasetNameDisplay:"ML arXiv Abstracts (10k)"},"arxiv-120k":{indexURL:REMOTE_ENDPOINT+"ml-arxiv-papers-index-120k.json.gzip",dataURL:REMOTE_ENDPOINT+"ml-arxiv-papers-120k.ndjson.gzip",datasetName:"ml-arxiv-papers-120k",datasetNameDisplay:"ML arXiv Abstracts (120k)"},"diffusiondb-10k":{indexURL:REMOTE_ENDPOINT+"diffusiondb-prompt-index-10k.json.gzip",dataURL:REMOTE_ENDPOINT+"diffusiondb-prompt-10k.ndjson.gzip",datasetName:"diffusiondb-prompts-10k",datasetNameDisplay:"DiffusionDB Prompts (10k)"},"diffusiondb-100k":{indexURL:REMOTE_ENDPOINT+"diffusiondb-prompt-index-100k.json.gzip",dataURL:REMOTE_ENDPOINT+"diffusiondb-prompt-100k.ndjson.gzip",datasetName:"diffusiondb-prompts-100k",datasetNameDisplay:"DiffusionDB Prompts (100k)"},"diffusiondb-500k":{indexURL:REMOTE_ENDPOINT+"diffusiondb-prompt-index-500k.json.gzip",dataURL:REMOTE_ENDPOINT+"diffusiondb-prompt-500k.ndjson.gzip",datasetName:"diffusiondb-prompts-500k",datasetNameDisplay:"DiffusionDB Prompts (500k)"},"diffusiondb-1m":{indexURL:REMOTE_ENDPOINT+"diffusiondb-prompt-index-1m.json.gzip",dataURL:REMOTE_ENDPOINT+"diffusiondb-prompt-1m.ndjson.gzip",datasetName:"diffusiondb-prompts-1m",datasetNameDisplay:"DiffusionDB Prompts (1M)"},"accident-3k":{indexURL:STORE_ENDPOINT+"accident-index-3k.json.gzip",dataURL:STORE_ENDPOINT+"accident-3k.ndjson.gzip",datasetName:"accidents-3k",datasetNameDisplay:"AI Accidents (3k)"}},DEV_MODE=!1,USE_CACHE=DEV_MODE,FORMATTER=d3.format(",");let MememoPlayground=class extends s{constructor(){super(),this.userQuery="",this.relevantDocuments=[],this.llmOutput="",this.embeddingWorkerRequestCount=0,this.topK=10,this.efSearch=100,this.isSearching=!1,this.searchRunTime=null,this.searchStartTime=0,this.encodeFinishTime=0,this.isRunningLLM=!1,this.LLMRunTime=null,this.LLMStartTime=0,this.toastMessage="",this.toastType="success",this.textGenLocalWorkerResolve=Q=>{},this.arrowElements={document:null,input:null,search:null,output:null},this.embeddingWorker=new WorkerWrapper,this.embeddingWorker.addEventListener("message",Q=>{this.embeddingWorkerMessageHandler(Q)}),this.textGenLocalWorker=new WorkerWrapper$1,this.textGenLocalWorker.addEventListener("message",Q=>{this.textGenLocalWorkerMessageHandler(Q)});const D=Q=>{this.userConfig=Q};this.userConfigManager=new UserConfigManager(D)}get embeddingWorkerRequestID(){return this.embeddingWorkerRequestCount++,`prompt-panel-${this.embeddingWorkerRequestCount}`}firstUpdated(){if(!this.shadowRoot)throw Error("No shadow root.");this.arrowElements={document:this.shadowRoot.querySelector(".flow.text-prompt"),input:this.shadowRoot.querySelector(".flow.input-prompt"),search:this.shadowRoot.querySelector(".flow.input-text"),output:this.shadowRoot.querySelector(".flow.prompt-output")}}willUpdate(D){}disconnectedCallback(){var D;this.embeddingWorker.terminate(),this.textGenLocalWorker.terminate(),(D=this.textViewerComponent)==null||D.mememoWorker.terminate()}async initData(){}getEmbedding(D){this.searchRunTime=null,this.searchStartTime=Date.now(),this.isSearching=!0;const Q={command:"startExtractEmbedding",payload:{detail:"",requestID:this.embeddingWorkerRequestID,model:EmbeddingModel.gteSmall,sentences:D,windowURL:window.location.href}};this.embeddingWorker.postMessage(Q)}semanticSearch(D){var Q;if(!this.textViewerComponent)throw Error("textViewerComponent is not initialized.");(Q=this.arrowElements.search)==null||Q.classList.add("running"),this.textViewerComponent.semanticSearch(D,this.topK,.5,this.efSearch)}userQueryRunClickHandler(D){var Q;this.userQuery=D.detail,this.getEmbedding([this.userQuery]),(Q=this.arrowElements.input)==null||Q.classList.add("activated")}promptRunClickHandler(D){const Q=D.detail;this._runPrompt(Q)}semanticSearchFinishedHandler(D){var Q,F,J;this.relevantDocuments=D.detail,this.searchRunTime=[this.encodeFinishTime-this.searchStartTime,Date.now()-this.searchStartTime],this.isSearching=!1,(Q=this.arrowElements.search)==null||Q.classList.remove("running"),(F=this.arrowElements.search)==null||F.classList.add("activated"),(J=this.arrowElements.document)==null||J.classList.add("activated")}embeddingWorkerMessageHandler(D){switch(D.data.command){case"finishExtractEmbedding":{const{embeddings:Q}=D.data.payload;this.encodeFinishTime=Date.now(),this.semanticSearch(Q[0]);break}case"error":{console.error("Worker error: ",JSON.stringify(D.data.payload.message));break}default:{console.error("Worker: unknown message",D.data.command);break}}}parameterInputChanged(D,Q){const F=D.currentTarget;if(Q==="efSearch"){const J=parseInt(F.value);J>0?this.efSearch=J:this.efSearch=100,F.value=String(this.efSearch)}if(Q==="top-k"){const J=parseInt(F.value);J>0?this.topK=J:this.topK=10,F.value=String(this.topK)}}textGenLocalWorkerMessageHandler(D){switch(D.data.command){case"finishTextGen":{const Q={command:"finishTextGen",payload:D.data.payload};this.textGenLocalWorkerResolve(Q);break}case"progressLoadModel":break;case"finishLoadModel":break;case"error":{const Q={command:"error",payload:D.data.payload};this.textGenLocalWorkerResolve(Q);break}default:{console.error("Worker: unknown message",D.data.command);break}}}_reComputeMaxHeights(D){if(!this.shadowRoot||!this.queryBoxComponent||!this.promptBoxComponent||!this.containerInputElement||!this.containerPromptElement)throw Error("No shadow root.");const F=this.shadowRoot.querySelector(".playground").getBoundingClientRect(),J=82,G=175;if(D==="prompt"){const O=this.containerInputElement.getBoundingClientRect(),Y=F.height-O.height-J-G;this.promptBoxComponent.setTextareaMaxHeight(Y);const z=F.height-Y-J-G;this.queryBoxComponent.setTextareaMaxHeight(z)}else if(D==="input"){const O=this.containerPromptElement.getBoundingClientRect(),Y=F.height-O.height-J-G;this.queryBoxComponent.setTextareaMaxHeight(Y);const z=F.height-Y-J-G;this.promptBoxComponent.setTextareaMaxHeight(z)}}_deactivateAllArrows(){var D;for(const Q of Object.values(Arrow))(D=this.arrowElements[Q])==null||D.classList.remove("activated")}_runPrompt(D,Q=.2){var J;let F;switch(this.llmOutput="",this.LLMRunTime=null,this.LLMStartTime=Date.now(),this.isRunningLLM=!0,this.isRunningLLM=!0,(J=this.arrowElements.output)==null||J.classList.add("running"),this.userConfig.preferredLLM){case SupportedRemoteModel["gpt-3.5"]:{F=textGenGpt(this.userConfig.llmAPIKeys[ModelFamily.openAI],"text-gen",D,Q,"gpt-3.5-turbo",USE_CACHE);break}case SupportedRemoteModel["gpt-4"]:{F=textGenGpt(this.userConfig.llmAPIKeys[ModelFamily.openAI],"text-gen",D,Q,"gpt-4-1106-preview",USE_CACHE);break}case SupportedRemoteModel["gemini-pro"]:{F=textGenGemini(this.userConfig.llmAPIKeys[ModelFamily.google],"text-gen",D,Q,USE_CACHE);break}case SupportedLocalModel["phi-2"]:case SupportedLocalModel["llama-2-7b"]:case SupportedLocalModel["tinyllama-1.1b"]:{F=new Promise(O=>{this.textGenLocalWorkerResolve=O});const G={command:"startTextGen",payload:{apiKey:"",prompt:D,requestID:"",temperature:Q}};this.textGenLocalWorker.postMessage(G);break}case SupportedRemoteModel["gpt-3.5-free"]:{F=textGenMememo("text-gen",D,Q,"gpt-3.5-free",USE_CACHE);break}default:console.error("Unknown case ",this.userConfig.preferredLLM),F=textGenMememo("text-gen",D,Q,"gpt-3.5-free",USE_CACHE)}F.then(G=>{var O,Y,z,AA;switch(G.command){case"finishTextGen":{this.llmOutput=G.payload.result,this.LLMRunTime=Date.now()-this.LLMStartTime,this.isRunningLLM=!1,(O=this.arrowElements.output)==null||O.classList.remove("running"),(Y=this.arrowElements.output)==null||Y.classList.add("activated");break}case"error":console.error(G.payload.message),this.toastMessage="Fail to run this LLM. Try it again later or use a different model.",this.toastType="error",(z=this.toastComponent)==null||z.show(),this.LLMRunTime=null,this.isRunningLLM=!1,(AA=this.arrowElements.output)==null||AA.classList.remove("running")}},()=>{})}dialogClicked(D){D.target===this.dialogElement&&this.dialogElement.close()}render(){return x`
D.limits.max -`;var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__decorateClass=(D,Q,F,J)=>{for(var G=J>1?void 0:J?__getOwnPropDesc(Q,F):Q,O=D.length-1,Y;O>=0;O--)(Y=D[O])&&(G=(J?Y(Q,F,G):Y(G))||G);return J&&G&&__defProp(Q,F,G),G};let MememoRagPlayground=class extends s{constructor(){super(),this.curDataset=Dataset.arXiv1k}willUpdate(D){}async initData(){}tabButtonClicked(D){D!==this.curDataset&&(this.curDataset=D)}render(){let D=x``;switch(this.curDataset){case Dataset.arXiv1k:{D=x`{for(var G=J>1?void 0:J?__getOwnPropDesc(Q,F):Q,O=D.length-1,Y;O>=0;O--)(Y=D[O])&&(G=(J?Y(Q,F,G):Y(G))||G);return J&&G&&__defProp(Q,F,G),G};let defaultDataset=Dataset.arXiv10k;if(window.location.search!==""){const D=new URLSearchParams(window.location.search);if(D.has("dataset"))switch(D.get("dataset")){case"paper":{defaultDataset=Dataset.arXiv10k;break}case"diffusiondb":{defaultDataset=Dataset.DiffusionDB10k;break}case"accident":{defaultDataset=Dataset.accident3k;break}}}let MememoRagPlayground=class extends s{constructor(){super(),this.curDataset=defaultDataset}willUpdate(D){}async initData(){}tabButtonClicked(D){D!==this.curDataset&&(this.curDataset=D)}render(){let D=x``;switch(this.curDataset){case Dataset.arXiv1k:{D=x``;break}case Dataset.arXiv10k:{D=x` - +