While some find it comforting to talk about their issues with an AI, the responses are unpredictable.
\n\t\t\t
When using the AI for real world use-cases such as advice or counseling this means you must be able to understand when an answer is wrong.\n\t\t\tIf you would not trust a random person to pretend to be your advisor; you should definitely not use the AI for this. The models are simply too small and not trained for this purpose.
\n\t\t\t
If you still wish to proceed, please type the phrase I understand in the box below, exactly as written.
\n\t\t\t
If you are experiencing feelings of distress, anxiety, suicidal thoughts, or other forms of mental discomfort, it's best to avoid using AI for non fiction or personal matters as it may exacerbate or encourage these feelings.
"}document.getElementById("workertable").innerHTML=t,document.getElementById("worktitlecount").innerText="Worker List - Total "+e.length}function show_my_own_workers(){let e=lastValidFoundUserData,t=find_text_horde(lastValidFoundCluster);if(lastValidFoundUserWorkers=[],t&&e&&e.worker_ids&&e.worker_ids.length>0){let n=e.worker_ids.map((e=>t.maintenance_endpoint+"/"+e));Promise.all(n.map((e=>fetch(e).then((e=>e.json()))))).then((e=>{lastValidFoundUserWorkers=e,console.log(e),document.getElementById("myownworkercontainer").classList.remove("hidden");let t="";for(var n=0;n
"+escapeHtml(o.name.substring(0,32))+"
"+o.uptime+" ("+o.requests_fulfilled+" jobs)
"+o.kudos_rewards.toFixed(0)+"
"+(o.online?"Online":"Offline")+"
"}document.getElementById("myownworkertable").innerHTML=t,localsettings.my_api_key=document.getElementById("apikey").value,null!=localsettings.my_api_key&&""!=localsettings.my_api_key||(localsettings.my_api_key=defaultsettings.my_api_key),autosave()})).catch((e=>{console.log("Error: "+e),msgbox(e,"Error fetching my workers")}))}else msgbox("Unable to find my horde workers.","No valid workers found")}function hide_workertable(){document.getElementById("workercontainer").classList.add("hidden"),document.getElementById("myownworkercontainer").classList.add("hidden")}function hide_popups(){document.getElementById("loadmodelcontainer").classList.add("hidden"),document.getElementById("newgamecontainer").classList.add("hidden"),document.getElementById("yesnocontainer").classList.add("hidden"),document.getElementById("settingscontainer").classList.add("hidden"),document.getElementById("msgboxcontainer").classList.add("hidden"),document.getElementById("memorycontainer").classList.add("hidden"),document.getElementById("workercontainer").classList.add("hidden"),document.getElementById("myownworkercontainer").classList.add("hidden"),document.getElementById("sharecontainer").classList.add("hidden"),document.getElementById("wicontainer").classList.add("hidden"),document.getElementById("customendpointcontainer").classList.add("hidden"),document.getElementById("quickstartcontainer").classList.add("hidden"),document.getElementById("zoomedimgcontainer").classList.add("hidden")}function explain_horde(){msgbox('The AI Horde generates text using crowdsourced GPUs by volunteer workers. By default your inputs are not logged, but as Horde workers are open source, they can be modified to do so.
In all cases, the sender will *always be anonymous*, however you are still advised to avoid sending privacy sensitive information.
For any issues, you can find us on discord at https://koboldai.org/discord',"Disclaimer",!0)}var pendingstyle="";function selectStyle(){inputBox("Style tags to use for generating images:\n(E.g. Sketch, Realistic, Anime, 3D Render, Drawing)\n\n","Extra Image Styles",pendingstyle,"Default Style",(()=>{let e=document.getElementById("inputboxcontainerinput").value;pendingstyle=e,console.log("Saved styles: "+pendingstyle)}),!1)}var msgboxOnDone=hide_popups;function hide_msgbox(){document.getElementById("msgboxcontainer").classList.add("hidden")}function msgbox(e,t="Error Encountered",n=!1,o=!1,r=hide_popups){e||(e=""),n?document.getElementById("msgboxtxt").innerHTML=e:document.getElementById("msgboxtxt").innerText=e,document.getElementById("msgboxtitle").innerText=t,document.getElementById("msgboxcontainer").classList.remove("hidden"),1==o?document.getElementById("msgboxbtnok").classList.add("hidden"):document.getElementById("msgboxbtnok").classList.remove("hidden"),msgboxOnDone=r,console.log("Msgbox: "+e)}var onYesFn=null,onNoFn=null;function msgboxYesNo(e,t,n,o,r=!1){e||(e=""),document.getElementById("yesnocontainer").classList.remove("hidden"),document.getElementById("yesnocontainertitle").innerText=t,r?document.getElementById("yesnocontainertext").innerHTML=e:document.getElementById("yesnocontainertext").innerText=e,onYesFn=n,onNoFn=o}var onInputboxOk=null;function inputBox(e,t,n,o,r,s=!1){e||(e=""),t||(t="User Input"),document.getElementById("inputboxcontainer").classList.remove("hidden"),document.getElementById("inputboxcontainertitle").innerText=t,s?document.getElementById("inputboxcontainertext").innerHTML=e:document.getElementById("inputboxcontainertext").innerText=e,document.getElementById("inputboxcontainerinput").value=escapeHtml(n),document.getElementById("inputboxcontainerinput").placeholder=escapeHtml(o),onInputboxOk=function(){document.getElementById("inputboxcontainer").classList.add("hidden"),r()}}function togglejailbreak(){document.getElementById("jailbreakprompt").checked?document.getElementById("jailbreakprompttext").classList.remove("hidden"):document.getElementById("jailbreakprompttext").classList.add("hidden")}function customapi_dropdown(){let e=document.getElementById("customapidropdown").value;document.getElementById("oaicustom").classList.add("hidden"),document.getElementById("koboldcustom").classList.add("hidden"),document.getElementById("scalecustom").classList.add("hidden"),document.getElementById("claudecustom").classList.add("hidden"),0==e?document.getElementById("koboldcustom").classList.remove("hidden"):1==e?(document.getElementById("oaicustom").classList.remove("hidden"),document.getElementById("custom_oai_endpoint").value=custom_oai_endpoint,""==custom_oai_key&&""!=localsettings.saved_oai_key&&(document.getElementById("custom_oai_key").value=localsettings.saved_oai_key,""!=localsettings.saved_oai_addr&&(document.getElementById("custom_oai_endpoint").value=localsettings.saved_oai_addr)),togglejailbreak()):2==e?document.getElementById("scalecustom").classList.remove("hidden"):3==e&&(document.getElementById("claudecustom").classList.remove("hidden"),document.getElementById("custom_claude_endpoint").value=custom_claude_endpoint,""==custom_claude_key&&""!=localsettings.saved_claude_key&&(document.getElementById("custom_claude_key").value=localsettings.saved_claude_key,""!=localsettings.saved_claude_addr&&(document.getElementById("custom_claude_endpoint").value=localsettings.saved_claude_addr)))}function connect_custom_endpoint(){custom_kobold_endpoint="",custom_oai_key="",custom_scale_key="";let e=document.getElementById("customapidropdown").value;if(0==e){let e=document.getElementById("customendpoint").value;if(null!=e&&""!=e.trim()){hide_popups(),e=e.trim(),e=e.endsWith("#")?e.slice(0,-1):e,e=e.endsWith("/")?e.slice(0,-1):e;let t=[apply_proxy_url(e+kobold_custom_mdl_endpoint),apply_proxy_url(e+kobold_custom_version_endpoint)];Promise.all(t.map((e=>fetch(e).then((e=>e.json()))))).then((t=>{console.log(t);let n=t[0].result,o=t[1].result;n?"ReadOnly"==n?(msgbox("The custom endpoint is working, but no model was loaded.\n\nPlease select and load a model and try again."),selected_models=[],selected_workers=[],custom_kobold_endpoint="",render_gametext()):(custom_kobold_endpoint=e,kobold_endpoint_version=o||"",selected_models=[{performance:100,queued:0,eta:0,name:n,count:1}],selected_workers=[],null==perfdata&&(perfdata={queued_requests:0,queued_tokens:0,past_minute_tokens:0,worker_count:0},document.body.classList.add("connected"),document.getElementById("connectstatus").classList.remove("color_orange"),document.getElementById("connectstatus").classList.add("color_green")),document.getElementById("connectstatus").innerHTML="Connected to Custom Endpoint",render_gametext(),localflag&&fetch(e+koboldcpp_version_endpoint).then((e=>e.json())).then((e=>{e&&""!=e&&e.version&&""!=e.version&&(koboldcpp_version=e.version,console.log("KoboldCpp Detected: "+koboldcpp_version))})).catch((e=>{console.log("Not using KoboldCpp")}))):(msgbox("Error at Custom Kobold Endpoint!\n\nThe custom endpoint failed to respond correctly."),selected_models=[],selected_workers=[],custom_kobold_endpoint="",render_gametext())})).catch((t=>{console.log("Error: "+t);let n=custom_kobold_endpoint.toLowerCase().includes("localhost")||custom_kobold_endpoint.toLowerCase().includes("127.0.0.1")||custom_kobold_endpoint.toLowerCase().includes("192.168.");uses_cors_proxy||n?(msgbox("Failed to connect to Custom Kobold Endpoint!\n\nPlease check if KoboldAI is running at the url: "+e),selected_models=[],selected_workers=[],custom_kobold_endpoint="",render_gametext()):(uses_cors_proxy=!0,connect_custom_endpoint())}))}}else if(1==e){let e=document.getElementById("custom_oai_key").value.trim(),t=document.getElementById("custom_oai_endpoint").value.trim();""==t&&(t=document.getElementById("custom_oai_endpoint").value=default_oai_base),""!=t&&"/"==t.slice(-1)&&(t=t.slice(0,-1)),""!=t&&t.length>4&&!t.slice(-4).toLowerCase().includes("/v")&&(t+="/v1"),""!=e&&""!=t&&(hide_popups(),fetch(t+oai_models_endpoint,{method:"GET",headers:{Authorization:"Bearer "+e,"x-api-key":e},referrerPolicy:"no-referrer"}).then((e=>e.json())).then((n=>{console.log(n),!n.error&&n.data&&n.data.length>0?(custom_oai_endpoint=t,custom_oai_key=e,localsettings.saved_oai_key=custom_oai_key,localsettings.saved_oai_addr=custom_oai_endpoint,custom_oai_model=document.getElementById("custom_oai_model").value.trim(),selected_models=[{performance:100,queued:0,eta:0,name:custom_oai_model,count:1}],selected_workers=[],null==perfdata&&(perfdata={queued_requests:0,queued_tokens:0,past_minute_tokens:0,worker_count:0},document.body.classList.add("connected"),document.getElementById("connectstatus").classList.remove("color_orange"),document.getElementById("connectstatus").classList.add("color_green")),document.getElementById("connectstatus").innerHTML="Connected to OAI Endpoint",render_gametext()):(custom_oai_endpoint=default_oai_base,custom_oai_key="",msgbox(JSON.stringify(n.error.message)))})).catch((e=>{console.log("Error: "+e),custom_oai_endpoint=default_oai_base,custom_oai_key="",msgbox("Error: "+e)})))}else if(2==e){let e=document.getElementById("custom_scale_key").value.trim(),t=document.getElementById("custom_scale_ID").value.trim();t=t.split("#")[0],t=t.split("?")[0],!t.includes("dashboard.scale.com/spellbook/api/v2/deploy/")||25!=e.length||e.includes(" ")||e.includes("/")?(t="",e="",msgbox("Invalid inputs, please try again.")):t=t.split("dashboard.scale.com/spellbook/api/v2/deploy/")[1],""!=e&&""!=t&&(hide_popups(),fetch(cors_proxy+"?"+scale_submit_endpoint+t,{method:"GET",headers:{Authorization:"Bearer "+e},referrerPolicy:"no-referrer"}).then((e=>e.json())).then((n=>{console.log(n),n.message&&""!=n.message?(custom_scale_key=e,custom_scale_ID=t,selected_models=[{performance:100,queued:0,eta:0,name:"SpellbookScaleAI",count:1}],selected_workers=[],null==perfdata&&(perfdata={queued_requests:0,queued_tokens:0,past_minute_tokens:0,worker_count:0},document.body.classList.add("connected"),document.getElementById("connectstatus").classList.remove("color_orange"),document.getElementById("connectstatus").classList.add("color_green")),document.getElementById("connectstatus").innerHTML="Connected to ScaleAI Endpoint",render_gametext()):(custom_scale_key="",msgbox("Cannot connect to Spellbook by ScaleAI"))})).catch((e=>{console.log("Error: "+e),custom_scale_key="",msgbox("Error: "+e)})))}else if(3==e){let e=document.getElementById("custom_claude_key").value.trim(),t=document.getElementById("custom_claude_endpoint").value.trim();""==t&&(t=document.getElementById("custom_claude_endpoint").value=default_claude_base),""!=t&&"/"==t.slice(-1)&&(t=t.slice(0,-1)),""!=t&&t.length>4&&!t.slice(-4).toLowerCase().includes("/v")&&(t+="/v1"),""!=e&&""!=t&&(hide_popups(),custom_claude_endpoint=t,custom_claude_key=e,localsettings.saved_claude_key=custom_claude_key,localsettings.saved_claude_addr=custom_claude_endpoint,custom_claude_model=document.getElementById("custom_claude_model").value.trim(),document.getElementById("clauderenamecompat").checked&&(localsettings.instruct_starttag="Human:",localsettings.chatname="Human",localsettings.instruct_endtag="Assistant:",localsettings.chatopponent="Assistant"),selected_models=[{performance:100,queued:0,eta:0,name:custom_claude_model,count:1}],selected_workers=[],null==perfdata&&(perfdata={queued_requests:0,queued_tokens:0,past_minute_tokens:0,worker_count:0},document.body.classList.add("connected"),document.getElementById("connectstatus").classList.remove("color_orange"),document.getElementById("connectstatus").classList.add("color_green")),document.getElementById("connectstatus").innerHTML="Connected to Claude Endpoint",render_gametext())}}function display_custom_endpoint(){document.getElementById("customendpointcontainer").classList.remove("hidden")}function fetch_models(e){localmode?e(selected_models):multifetch(models_endpoints,((t,n)=>{if(t&&t.length>0){let n=[];for(let e=0;e0?n.models[0]:"None",r=n.name,s=find_text_horde(n.cluster),l=s&&""!=s.tag?s.tag+" ":"",a=n.trusted?'style="color:#b700ff;"':"";a=n.maintenance_mode?'style="color:#ee4444;"':a;let i=n.trusted?" 💜":"";i=n.maintenance_mode?" ⛔":i,e+=""}document.getElementById("pickedmodel").innerHTML=e}else{let e="";for(let t=0;te.cluster==n.cluster&&e.name==n.name)).length>0?" selected":"",l=parseFloat(n.performance);if(!l||isNaN(l)||l>=99999){let e=worker_data.filter((e=>e.cluster==n.cluster&&e.models.includes(n.name)));if(e.length>0){l=0;for(let t=0;t"+r+escapeHtml(n.name)+" (ETA: "+n.eta+"s, Queue: "+n.queued+", Speed: "+l+", Qty: "+n.count+")"}e+='',document.getElementById("pickedmodel").innerHTML=e}}fetch_models((e=>{models_data=e,t=!0,t&&n&&r()})),get_workers((e=>{worker_data=e,n=!0,t&&n&&r()}))}function confirm_models(){let e=Array.from(document.getElementById("pickedmodel").selectedOptions).map((({value:e})=>e));if(1==e.length&&9999==e[0])hide_popups(),display_custom_endpoint();else{custom_kobold_endpoint="",custom_oai_key="",custom_scale_key="";const o=e.indexOf("9999");if(o>-1&&e.splice(o,1),e.length>0){let o=[],r=[],s=!!document.getElementById("manualworker").checked;for(var t=0;te.name==l[n]&&e.cluster==s.cluster));o.includes(e)||o.push(e)}}else{let n=models_data[e[t]];o.push(n)}o=o.filter((e=>e)),r=r.filter((e=>e));const l=o.every((e=>e.cluster===o[0].cluster)),a=r.every((e=>e.cluster===r[0].cluster));if(!l||!a)if(r.length>0){let e=get_most_common_cluster(r);r=r.filter((t=>t.cluster===e)),o=o.filter((t=>t.cluster===e))}else{let e=get_most_common_cluster(o);o=o.filter((t=>t.cluster===e))}selected_models=o,selected_workers=r,localsettings.my_api_key=document.getElementById("apikey").value,null!=localsettings.my_api_key&&""!=localsettings.my_api_key||(localsettings.my_api_key=defaultsettings.my_api_key),null!=desired_new_home_cluster&&(localsettings.home_cluster=desired_new_home_cluster,desired_new_home_cluster=null),document.getElementById("connectstatus").innerHTML="Connected to KoboldAI Horde",render_gametext(),hide_popups(),l&&a||msgbox("You've selected multiple workers from different clusters. Only one cluster will be used.","Caution")}}}function update_my_workers(){let e=document.getElementById("apikey").value,t=find_text_horde(lastValidFoundCluster);for(var n=0;ne.json())).then((e=>{msgbox(JSON.stringify(e),"Update My Worker")})).catch((e=>{console.error("Error:",e)}))}}}let desired_new_home_cluster=null,lastValidFoundUserData=null,lastValidFoundCluster=null,lastValidFoundUserWorkers=[];function fetch_kudo_balance(){if(localmode)return;desired_new_home_cluster=null;let e=document.getElementById("apikey").value;if(null!=e&&""!=e.trim()){document.getElementById("kudos_bal").innerHTML="Checking... ";let t={method:"GET",headers:{apikey:e}};multifetch(finduser_endpoints.map((e=>[e,t])),((e,t)=>{if(e&&e.length>0){lastValidFoundUserData=null,lastValidFoundCluster="";for(let t=0;t"+t+"";e<0?(document.getElementById("kudos_bal").innerHTML=o+r+" Kudos Balance: 0","anonymous#0"==t.toLowerCase()&&(document.getElementById("kudos_bal").innerHTML=o+t+" (Register New User)")):document.getElementById("kudos_bal").innerHTML=o+r+" Kudos Balance: "+e}else document.getElementById("kudos_bal").innerHTML="API Key Error (Register New User)"}else console.log("Error: "+t),document.getElementById("kudos_bal").innerHTML="API Key Error (Register New User)"}))}}function focus_api_keys(){var e=document.getElementById("apikey");e&&"password"===e.type&&(e.type="text"),(e=document.getElementById("custom_oai_key"))&&"password"===e.type&&(e.type="text"),(e=document.getElementById("custom_claude_key"))&&"password"===e.type&&(e.type="text")}function blur_api_keys(){var e=document.getElementById("apikey");e&&"text"===e.type&&(e.type="password"),(e=document.getElementById("custom_oai_key"))&&"text"===e.type&&(e.type="password"),(e=document.getElementById("custom_claude_key"))&&"text"===e.type&&(e.type="password")}function display_settings(){document.getElementById("settingscontainer").classList.remove("hidden"),document.getElementById("max_context_length").value=document.getElementById("max_context_length_slide").value=localsettings.max_context_length,document.getElementById("max_length").value=document.getElementById("max_length_slide").value=localsettings.max_length,document.getElementById("temperature").value=document.getElementById("temperature_slide").value=localsettings.temperature,document.getElementById("rep_pen").value=document.getElementById("rep_pen_slide").value=localsettings.rep_pen,document.getElementById("rep_pen_slope").value=localsettings.rep_pen_slope,document.getElementById("rep_pen_range").value=localsettings.rep_pen_range,document.getElementById("top_p").value=document.getElementById("top_p_slide").value=localsettings.top_p,document.getElementById("autoscroll").checked=localsettings.autoscroll,document.getElementById("export_settings").checked=localsettings.export_settings,document.getElementById("invert_colors").checked=localsettings.invert_colors,document.getElementById("trimsentences").checked=localsettings.trimsentences,document.getElementById("trimwhitespace").checked=localsettings.trimwhitespace,document.getElementById("persist_session").checked=localsettings.persist_session,document.getElementById("opmode").value=localsettings.opmode,document.getElementById("chatname").value=localsettings.chatname,document.getElementById("chatopponent").value=localsettings.chatopponent,document.getElementById("instruct_starttag").value=localsettings.instruct_starttag,document.getElementById("instruct_endtag").value=localsettings.instruct_endtag,document.getElementById("top_k").value=localsettings.top_k,document.getElementById("top_a").value=localsettings.top_a,document.getElementById("typ_s").value=localsettings.typ_s,document.getElementById("tfs_s").value=localsettings.tfs_s,document.getElementById("generate_images").value=localsettings.generate_images,document.getElementById("enhanced_chat_ui").checked=localsettings.enhanced_chat_ui,document.getElementById("multiline_replies").checked=localsettings.multiline_replies,document.getElementById("allow_continue_chat").checked=localsettings.allow_continue_chat,document.getElementById("idle_responses").value=localsettings.idle_responses,document.getElementById("idle_duration").value=localsettings.idle_duration,document.getElementById("adventure_context_mod").checked=localsettings.adventure_context_mod,document.getElementById("instruct_has_markdown").checked=localsettings.instruct_has_markdown,document.getElementById("auto_ctxlen").checked=localsettings.auto_ctxlen,document.getElementById("auto_genamt").checked=localsettings.auto_genamt,pendingstyle=localsettings.image_styles;let e=localsettings.sampler_order.toString();document.getElementById("sampler_order").value=e;let t="";for(var n=0;n'+presets[n].preset+"";t+='',document.getElementById("presets").innerHTML=t,document.getElementById("presets").value=localsettings.last_selected_preset;var o='';if("speechSynthesis"in window){let e=window.speechSynthesis.getVoices();console.log("speech synth available: "+e.length);for(n=0;n'+e[n].name+""}else console.log("No speech synth available");document.getElementById("ttsselect").innerHTML=o,document.getElementById("ttsselect").value=localsettings.speech_synth,document.getElementById("beep_on").checked=localsettings.beep_on,toggle_opmode();let r="";for(n=0;n';document.getElementById("sdmodels").innerHTML=r,document.getElementById("img_autogen").checked=localsettings.img_autogen,document.getElementById("save_images").checked=localsettings.save_images,document.getElementById("img_allownsfw").checked=localsettings.img_allownsfw}function toggle_preset(){let e=document.getElementById("presets").value,t=presets[e];t&&(temp_changingpreset=!0,document.getElementById("temperature").value=document.getElementById("temperature_slide").value=t.temp,document.getElementById("max_length").value=document.getElementById("max_length_slide").value=t.genamt,document.getElementById("top_k").value=t.top_k,document.getElementById("top_p").value=document.getElementById("top_p_slide").value=t.top_p,document.getElementById("top_a").value=t.top_a,document.getElementById("typ_s").value=t.typical,document.getElementById("tfs_s").value=t.tfs,document.getElementById("rep_pen").value=document.getElementById("rep_pen_slide").value=t.rep_pen,document.getElementById("rep_pen_range").value=t.rep_pen_range,document.getElementById("rep_pen_slope").value=t.rep_pen_slope,document.getElementById("sampler_order").value=t.sampler_order.toString())}function validate_sd_model(){var e=document.getElementById("generate_images").value;let t=!1;for(var n=0;n{pending_response_id="-1",waiting_for_autosummary=!0;let e=Math.floor(3.35*localsettings.max_context_length)-100,t=concat_gametext(!0,"");t=end_trim_to_sentence(t,!0),t.substring(t.length-e);let n=t.length>1800;t+="\n### Instruction:Summarize the above text in a single paragraph of up to "+(n?"ten":"five")+" detailed sentences.\n### Response:";let o={prompt:t,params:{n:1,max_context_length:localsettings.max_context_length,max_length:n?200:150,rep_pen:localsettings.rep_pen,temperature:localsettings.temperature,top_p:localsettings.top_p,top_k:localsettings.top_k,top_a:localsettings.top_a,typical:localsettings.typ_s,tfs:localsettings.tfs_s,rep_pen_range:localsettings.rep_pen_range,rep_pen_slope:localsettings.rep_pen_slope,sampler_order:localsettings.sampler_order},models:selected_models.map((e=>e.name))};o.workers=selected_workers.map((e=>e.id)),dispatch_submit_generation(o),render_gametext(),document.getElementById("memorytext").value="[<|Generating summary, do not close window...|>]"};0==gametext_arr.length||1==gametext_arr.length&&""==gametext_arr[0].trim()?console.log("Cannot summarize nothing."):""!=temp_automem_store.trim()?msgboxYesNo("This will modify existing memory. Proceed?","Confirm Modify",(()=>{document.getElementById("yesnocontainer").classList.add("hidden"),e()}),(()=>{document.getElementById("yesnocontainer").classList.add("hidden")})):e()}function handle_incoming_autosummary(e){waiting_for_autosummary=!1;let t=(e=replaceAll(e=(e=e.trim()).split("###")[0],"\n\n","\n")).split("\n"),n=200;if((e=t[0]).length<100&&t.length>1)for(var o=1;o5&&(e+="\n"+t[o]),!(n<=0));++o);e=end_trim_to_sentence(e,!0),""==temp_automem_store.trim()?document.getElementById("memorytext").value="[Summary: "+e+"]":document.getElementById("memorytext").value=temp_automem_store+"\n\n[Summary Continued: "+e+"]"}function clear_poll_flags(){pending_response_id="",poll_in_progress=!1,synchro_polled_response=null,synchro_pending_stream="",waiting_for_autosummary=!1}function restart_new_game(){idle_timer=0,gametext_arr=[],redo_arr=[],last_request_str="No Requests Available",retry_prev_text="",redo_prev_text="",nextgeneratedimagemilestone=generateimagesinterval,pending_response_id="",synchro_polled_response=null,synchro_pending_stream="",waiting_for_autosummary=!1,current_memory="",current_anote="",current_wi=[],pending_context_preinjection="",current_anotetemplate="[Author's note: <|>]",loaded_storyobj=generate_base_storyobj(),document.getElementById("input_text").value="",document.getElementById("cht_inp").value="",image_db={},completed_imgs_meta={},localsettings.adventure_is_action=!1,prev_hl_chunk=null,last_token_budget="",last_known_filename="",render_gametext()}function btn_editmode(){gametext_arr.length>0&&(document.getElementById("allowediting").checked=!0,toggle_editable())}function toggle_editable(){0==gametext_arr.length?selected_models.length>0||selected_workers.length>0?document.getElementById("allowediting").checked&&gametext_arr.push(""):document.getElementById("allowediting").checked=!1:1==gametext_arr.length&&""==gametext_arr[0]&&gametext_arr.pop(),render_gametext()}function end_trim_to_sentence(e,t=!1){let n=-1,o=[".","!","?","`","*",'"',")","}","`","]",";"];for(let t=0;t0?e.substring(0,n+1).trimEnd():e.trimEnd()}function start_trim_to_sentence(e){let t=e.indexOf("."),n=e.indexOf("!"),o=e.indexOf("?"),r=e.indexOf("\n"),s=t,l=!1;return n>0&&n0&&o0&&r0?l?e.substring(s+1):e.substring(s+2):e}function handle_typing(e){var t=(e=e||window.event).keyCode||e.which;if(!e.shiftKey&&13==t){let t=!!document.getElementById("entersubmit").checked,n=""!=document.getElementById("input_text").value;t&&(e.preventDefault(),n&&!document.getElementById("btnsend").disabled&&submit_generation())}}function show_abort_button(e){e?(document.getElementById("abortgen").classList.remove("hidden"),document.getElementById("chat_msg_send_btn_abort").classList.remove("hidden")):(document.getElementById("abortgen").classList.add("hidden"),document.getElementById("chat_msg_send_btn_abort").classList.add("hidden"))}function abort_generation(){let e=pending_response_id;if(is_using_custom_ep()&&""!=pending_response_id&&""!=synchro_pending_stream&&(synchro_polled_response=synchro_pending_stream,poll_in_progress=!1,poll_pending_response()),console.log("Generation "+pending_response_id+" aborted"),clear_poll_flags(),render_gametext(),pending_response_horde&&e&&""!=e&&!is_using_custom_ep()){let t=pending_response_horde.output_endpoint+"/"+e;fetch(t,{method:"DELETE"}).then((e=>e.json())).then((e=>{console.log(e)})).catch((e=>{console.error("Error:",e)}))}else is_using_newer_kcpp()&&fetch(custom_kobold_endpoint+koboldcpp_abort_endpoint,{method:"POST",headers:{"Content-Type":"application/json"}}).then((e=>e.json())).then((e=>{})).catch((e=>{console.error("Error:",e)}));show_abort_button(!1)}function manual_gen_image(){let e=concat_gametext(!0,"");var t=e.length;if(t>0){var n=e.substring(t-300,t);(n=end_trim_to_sentence(n=start_trim_to_sentence(n),!0)).length>0&&(generate_new_image(n),nextgeneratedimagemilestone=t+generateimagesinterval,document.getElementById("btn_genimg").disabled=!0,document.getElementById("btn_genimg2").disabled=!0,setTimeout((()=>{document.getElementById("btn_genimg").disabled=!1,document.getElementById("btn_genimg2").disabled=!1}),1e4))}}function submit_generation(){let e=document.getElementById("input_text").value,t=!1;if(""!=e.trim()||gametext_arr.length>0||""!=current_memory||""!=current_anote){if(waiting_for_autosummary=!1,idle_timer=0,idle_triggered_counter=0,localsettings.speech_synth>0&&"speechSynthesis"in window){let t=new window.SpeechSynthesisUtterance(e);t.voice=window.speechSynthesis.getVoices()[localsettings.speech_synth-1],window.speechSynthesis.speak(t)}4==localsettings.opmode&&""!=e&&(e=get_instruct_starttag(!1)+e+get_instruct_endtag(!1)),3==localsettings.opmode&&""!=e?e="\n"+localsettings.chatname+": "+e:3==localsettings.opmode&&""==e.trim()&&(e=""),2==localsettings.opmode&&""!=e&&localsettings.adventure_is_action&&(e="\n\n> "+e+"\n\n"),2==localsettings.opmode&&""!=e&&0==gametext_arr.length&&(localsettings.adventure_is_action||(localsettings.adventure_is_action=!0,""==current_memory.trim()&&(t=!0))),""!=e&&gametext_arr.push(e),redo_arr=[],retry_prev_text="",redo_prev_text="",document.getElementById("input_text").value="",pending_response_id="-1";let l=document.getElementById("maintxtloader");if(l){l.classList.remove("greenloader"),l.classList.remove("redloader");let e=document.getElementById("outerloadernum");e&&(e.innerText="")}let a=localsettings.max_context_length,i=localsettings.max_length;if(!is_using_custom_ep()&&(localsettings.auto_genamt||localsettings.auto_ctxlen)){let e=selected_workers;if((null==e||0==e.length)&&selected_models&&selected_models.length>0){e=[];for(let t=0;t Look\n\nYou look around, observing yourself and your surroundings.\n\n",d=e+d}if(3==localsettings.opmode){let t=localsettings.chatopponent,r=!1;if(t.includes("||$||")){let e=t.split("||$||");e=e.filter((e=>e&&""!=e)),e=e.map((e=>e.trim())),t=e[Math.floor(Math.random()*e.length)],r=e.length>1}let s=localsettings.chatname;null!=t&&""!=t||(t="");var n=new RegExp("\n(?!"+localsettings.chatname+").+?: ","gi"),o=(current_memory+current_anote+d).match(n);if(""==t&&null!=o&&o.length>0){let e=o[0].replace(": ","");e=e.trim(),""!=e&&(t=e)}if(0==current_anote.length&&0==current_memory.length&&gametext_arr.length>0&&gametext_arr[0].startsWith("\n"+s+": ")){let e="[The following is an interesting chat message log between "+s+" and "+t+".]\n\n"+localsettings.chatname+": Hi.\n"+t+": Hello.";""==t&&(e="[The following is an interesting chat message log between "+s+" and someone else.]\n\n"+localsettings.chatname+": Hi."),r&&(e="[The following is an interesting chat message log between "+s+" and multiple others.]\n\n"+localsettings.chatname+": Hi."),d=e+d}""!=t?(t=replaceAll(t,"\n",""),pending_context_preinjection="\n"+t+":"):pending_context_preinjection="\n",localsettings.allow_continue_chat&&""==e.trim()?pending_context_preinjection="":d+=pending_context_preinjection}if(""!=localsettings.generate_images&&3!=localsettings.opmode&&4!=localsettings.opmode&&localsettings.img_autogen)if(2==localsettings.opmode){if(e.startsWith("\n\n> "))generate_new_image(start_trim_to_sentence(d.substring(r-200,r)))}else{var r=d.length;if(r>nextgeneratedimagemilestone)nextgeneratedimagemilestone=r+generateimagesinterval,generate_new_image(end_trim_to_sentence(start_trim_to_sentence(d.substring(r-300,r)),!0))}let m=Math.floor(.9*c),u=current_memory.substring(current_memory.length-m);null!=u&&""!=u&&(u+="\n");let _=d;if(localsettings.case_sensitive_wi||(_=_.toLowerCase()),current_wi.length>0)for(var s=0;s_.includes(e.trim()))):n.some((e=>_.includes(e.trim().toLowerCase())));else{let t=e.keysecondary.split(",");if(localsettings.case_sensitive_wi){let e=n.some((e=>_.includes(e.trim()))),r=t.some((e=>_.includes(e.trim())));o=e&&r}else{let e=n.some((e=>_.includes(e.trim().toLowerCase()))),r=t.some((e=>_.includes(e.trim().toLowerCase())));o=e&&r}}o&&(u+=e.content+"\n")}let g=current_anotetemplate.replace("<|>",current_anote);if(g=g.substring(g.length-m),0==current_anote.length&&(g=""),u.length>0||current_anote.length>0){d=d.substring(d.length-c);let e=u.length+d.length+g.length-c;d=d.substring(e);let t=anote_strength,n=d.length-t;for(let e=0;e<10&&(n>=0&&ne.name))};p.workers=selected_workers.map((e=>e.id)),t?pending_response_id="":dispatch_submit_generation(p),render_gametext()}}function dispatch_submit_generation(e){if(console.log(e),last_request_str=JSON.stringify(e),startTimeTaken(),is_using_custom_ep())if(console.log("submit custom api"),pending_response_id="submit-v1-dummy-id",poll_ticks_passed=0,poll_in_progress=!1,synchro_polled_response=null,synchro_pending_stream="",""!=custom_kobold_endpoint){let t=e.prompt;(e=e.params).prompt=t;let n=!!document.getElementById("remoteconsolelog").checked;if(e.quiet=!n,kobold_endpoint_version&&""!=kobold_endpoint_version&&compare_version_str(kobold_endpoint_version,"1.2.1")>0){if(2==localsettings.opmode&&(e.stop_sequence=["\n> "]),3==localsettings.opmode&&(e.stop_sequence=[localsettings.chatname+":","\n"+localsettings.chatname+" "],localsettings.chatopponent.includes("||$||"))){let t=localsettings.chatopponent.split("||$||");t=t.filter((e=>e&&""!=e)),t=t.map((e=>e.trim()));for(let n=0;n0&&!e.stop_sequence&&(e.stop_sequence=[]);for(let n=0;n0&&(s=r),kobold_api_stream(apply_proxy_url(custom_kobold_endpoint+kobold_custom_gen_endpoint),e,e.max_length,"",o?s:4096)}else if(""!=custom_oai_key){let t=custom_oai_endpoint+oai_submit_endpoint,n=e.params.rep_pen-1,o={max_tokens:e.params.max_length,model:custom_oai_model,presence_penalty:n,temperature:e.params.temperature,top_p:e.params.top_p,logit_bias:{50256:-100}};"gpt-3.5-turbo"==custom_oai_model||"gpt-3.5-turbo-16k"==custom_oai_model||"gpt-4"==custom_oai_model||"gpt-4-32k"==custom_oai_model?(t=custom_oai_endpoint+oai_submit_endpoint_turbo,document.getElementById("jailbreakprompt")&&document.getElementById("jailbreakprompt").checked&&""!=document.getElementById("jailbreakprompttext").value?o.messages=[{role:"system",content:document.getElementById("jailbreakprompttext").value},{role:"user",content:e.prompt}]:o.messages=[{role:"user",content:e.prompt}]):o.prompt=e.prompt,fetch(t,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":custom_oai_key,Authorization:"Bearer "+custom_oai_key},body:JSON.stringify(o),referrerPolicy:"no-referrer"}).then((e=>e.json())).then((e=>{if(console.log("sync finished response: "+JSON.stringify(e)),""!=custom_oai_key&&null!=e.choices&&e.choices.length>0){let t=e.choices[0];t.text?synchro_polled_response=t.text:t.message?synchro_polled_response=t.message.content:(console.error("Error, unknown OAI response"),clear_poll_flags(),render_gametext(),msgbox("Error, unknown OAI response"))}else console.error("error occurred in OAI generation"),clear_poll_flags(),render_gametext(),msgbox("Error occurred during text generation: "+formatError(e))})).catch((e=>{console.error("Error:",e),clear_poll_flags(),render_gametext(),msgbox("Error while submitting prompt: "+e)}))}else if(""!=custom_scale_key){let t=cors_proxy+"?"+scale_submit_endpoint+custom_scale_ID,n={input:{input:e.prompt}};fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Basic "+custom_scale_key},body:JSON.stringify(n),referrerPolicy:"no-referrer"}).then((e=>e.json())).then((e=>{console.log("sync finished response: "+JSON.stringify(e)),""!=custom_scale_key&&null!=e.output&&""!=e.output?synchro_polled_response=e.output:(console.error("error occurred in Scale generation"),clear_poll_flags(),render_gametext(),msgbox("Error occurred during text generation: "+formatError(e)))})).catch((e=>{console.error("Error:",e),clear_poll_flags(),render_gametext(),msgbox("Error while submitting prompt: "+e)}))}else if(""!=custom_claude_key){let t=cors_proxy+"?"+(custom_claude_endpoint+claude_submit_endpoint),n={prompt:e.prompt,max_tokens_to_sample:e.params.max_length,model:custom_claude_model,top_k:e.params.top_k<=0?-1:e.params.top_k,temperature:e.params.temperature,top_p:e.params.top_p};fetch(t,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":custom_claude_key,Authorization:"Bearer "+custom_claude_key},body:JSON.stringify(n),referrerPolicy:"no-referrer"}).then((e=>e.json())).then((e=>{console.log("sync finished response: "+JSON.stringify(e)),""!=custom_claude_key&&null!=e.completion&&""!=e.completion?synchro_polled_response=e.completion:(console.error("error occurred in Claude generation"),clear_poll_flags(),render_gametext(),msgbox("Error occurred during text generation: "+formatError(e)))})).catch((e=>{console.error("Error:",e),clear_poll_flags(),render_gametext(),msgbox("Error while submitting prompt: "+e)}))}else console.log("Unknown sync endpoint!");else{console.log("submit v2 api");let t=find_text_horde(localsettings.home_cluster);if(selected_workers.length>0){const e=selected_workers.filter((e=>e.cluster==localsettings.home_cluster)),n=selected_workers.filter((e=>e.cluster!=localsettings.home_cluster));if(0==e.length&&n.length>0){let e=find_text_horde(n[0].cluster);e&&(t=e)}}else if(selected_models.length>0){const e=selected_models.filter((e=>e.cluster==localsettings.home_cluster)),n=selected_models.filter((e=>e.cluster!=localsettings.home_cluster));if(0==e.length&&n.length>0){let e=find_text_horde(n[0].cluster);e&&(t=e)}}let n=t.baseurl==localsettings.home_cluster?localsettings.my_api_key:defaultsettings.my_api_key,o=t.client_agent,r={"Content-Type":"application/json",apikey:n};null!=o&&(r["Client-Agent"]=o),fetch(t.submit_endpoint,{method:"POST",headers:r,body:JSON.stringify(e)}).then((e=>e.json())).then((e=>{console.log("Success:",e),e.id&&""!=e.id?(pending_response_id=e.id,pending_response_horde=t,poll_ticks_passed=0,console.log("awaiting response for "+pending_response_id)):(clear_poll_flags(),render_gametext(),""!=e.message?msgbox(e.message):msgbox("Unspecified error while submitting prompt"))})).catch((e=>{console.error("Error:",e),clear_poll_flags(),render_gametext(),msgbox("Error while submitting prompt: "+e)}))}}function sanitize_horde_image_prompt(e){if(null==e||""==e)return"";return(e=(e=(e=(e=(e=e.replace(/\b(girl)\b/gim,"woman")).replace(/\b(boy)\b/gim,"man")).replace(/\b(girls)\b/gim,"women")).replace(/\b(boys)\b/gim,"men")).replace(/\b(under.age|under.aged|underage|underaged|loli|pedo|pedophile|(\w+).year.old|(\w+).years.old|minor|prepubescent|minors|shota)\b/gim,"")).match(/\b(cock|ahegao|hentai|uncensored|lewd|cocks|deepthroat|deepthroating|dick|dicks|cumshot|lesbian|fuck|fucked|fucking|sperm|naked|nipples|tits|boobs|breasts|boob|breast|topless|ass|butt|fingering|masturbate|masturbating|bitch|blowjob|pussy|piss|asshole|dildo|dildos|vibrator|erection|foreskin|handjob|nude|penis|porn|vibrator|virgin|vagina|vulva|threesome|orgy|bdsm|hickey|condom|testicles|anal|bareback|bukkake|creampie|stripper|strap-on|missionary|clitoris|clit|clitty|cowgirl|fleshlight|sex|buttplug|milf|oral|sucking|bondage|orgasm|scissoring|railed|slut|sluts|slutty|cumming|cunt|faggot|sissy|anal|anus|cum|semen|scat|nsfw|xxx|explicit|erotic|horny|aroused|jizz|moan|rape|raped|raping|throbbing|humping)\b/gim)&&(e=(e=e.replace(/\b(youngster|infant|baby|toddler|child|teen|kid|kiddie|kiddo|teenager|student|preteen|pre.teen)\b/gim,"person")).replace(/\b(young|younger|youthful|youth|small|smaller|smallest|girly|boyish|lil|tiny|teenaged|lit[tl]le|school.aged|school|highschool|kindergarten|teens|children|kids)\b/gim,"")),e}function generate_new_image(e){localsettings.image_styles&&""!=localsettings.image_styles&&(e=localsettings.image_styles+" "+e),filter_enabled&&(e=sanitize_horde_image_prompt(e)),console.log("Generating image for: "+e);let t=[];t="*"==localsettings.generate_images?[]:[localsettings.generate_images];let n={prompt:e+" ### disfigured, ugly, deformed, poorly, censor, censored, blurry, lowres, fused, malformed, watermark, misshapen, duplicated, grainy, distorted, signature",params:{cfg_scale:7,sampler_name:"k_euler_a",height:512,width:512,steps:20,karras:!1,n:1,seed:"",post_processing:[]},models:t,nsfw:!!localsettings.img_allownsfw,censor_nsfw:!localsettings.img_allownsfw,trusted_workers:!1,replacement_filter:!0,r2:!1};fetch(stablehorde_submit_endpoint,{method:"POST",headers:{"Content-Type":"application/json","Client-Agent":default_client_agent,apikey:localsettings.my_api_key},body:JSON.stringify(n)}).then((e=>e.json())).then((t=>{if(console.log("genimg result:",t),t.id&&""!=t.id){let n="[<|p|"+t.id+"|p|>]";gametext_arr.push(n),image_db[t.id]={done:!1,queue:"Starting",result:"",alt:e},console.log("New image queued "+n)}else msgbox("Image generation failed: "+t.message)})).catch((e=>{console.error("Error:",e),msgbox("Image generation error: "+e)}))}function click_image(e){if(e){document.getElementById("zoomedimgcontainer").classList.remove("hidden"),document.getElementById("zoomedimg").src=e.src;let t=e.title;t&&""!=t?(t=replaceAll(t," "," "),document.getElementById("zoomedimgdesc").innerText=t):document.getElementById("zoomedimgdesc").innerText="No Saved Description"}}function delete_curr_image(){let e=document.getElementById("zoomedimg").src;if(e&&""!=e){var t="[<|d|"+e+"|d|>]";for(let e=0;e'}{let e="Unavailable";if(null!=image_db[t]){let n=image_db[t].queue;s=image_db[t].alt?escapeHtml(image_db[t].alt):"",e=0==n?"Generating":"Starting"==n?n:"Queue: "+n}else console.log("Cannot render "+t);return'
'+e+"
"}}function handle_incoming_text(e,t,n,o){if(""!=extrastopseq){let t=replaceAll(extrastopseq,"\\n","\n").split("||$||");if(t.length>0)for(let n=0;n ")&&(t=e.split("\n> "),e=t[0])}if(3==localsettings.opmode){let t=e.indexOf(localsettings.chatname+":"),n=e.indexOf("\n"+localsettings.chatname+" "),o=[];if(-1!=t)o=e.split(localsettings.chatname+":");else if(-1!=n)o=e.split("\n"+localsettings.chatname+" ");else if(localsettings.multiline_replies)o.push(e);else if(0==e.indexOf('"')&&e.indexOf('"',1)>0){let t=e.indexOf('"',1);o.push(e.substring(0,t+1))}else o=e.split("\n");let r=o[0];r.length>0&&"\n"==r[r.length-1]&&(r=r.substring(0,r.length-1)),e=r}if(4==localsettings.opmode){let t=get_instruct_starttag(!0),n=get_instruct_endtag(!0),o=e.indexOf(t),r=[];-1!=o&&(r=e.split(t),e=r[0]),o=e.indexOf(n),r=[],-1!=o&&(r=e.split(n),e=r[0])}if(""!=pending_context_preinjection&&(""!=e&&" "!=e[0]&&3==localsettings.opmode&&(e=" "+e),e=pending_context_preinjection+e,pending_context_preinjection=""),localsettings.speech_synth>0&&"speechSynthesis"in window){let t=new window.SpeechSynthesisUtterance(e);t.voice=window.speechSynthesis.getVoices()[localsettings.speech_synth-1],window.speechSynthesis.speak(t)}""!=e&&gametext_arr.push(e),localsettings.beep_on&&playbeep();let r='Last request served by '+t+' using '+n+" for "+o+" kudos in "+getTimeTaken()+" seconds.";document.getElementById("lastreq").innerHTML=r,document.getElementById("lastreq2").innerHTML=r}function poll_image_db(){console.log("polling for pending images "+Object.keys(image_db).length);for(let e in image_db){let t=image_db[e];0==t.done&&fetch(stablehorde_poll_endpoint+"/"+e).then((e=>e.json())).then((n=>{console.log("pollimg result:",n),1==n.faulted||0==n.is_possible?(msgbox("Pending image generation could not complete."),console.log("removing from images: "+e),delete image_db[e]):1==n.done?(t.done=!0,fetch(stablehorde_output_endpoint+"/"+e).then((e=>e.json())).then((n=>{if(console.log("finalimg recv for "+e),1==n.faulted||0==n.is_possible)msgbox("Pending image generation could not complete."),console.log("removing from images: "+e),delete image_db[e];else{t.queue=0,compressImage("data:image/jpeg;base64,"+n.generations[0].img,(e=>{t.result=e}))}})).catch((t=>{console.error("Error:",t),msgbox("Image poll error: "+t),delete image_db[e]}))):t.queue=null==n.queue_position?"Error":n.queue_position})).catch((t=>{console.error("Error:",t),msgbox("Image poll error: "+t),delete image_db[e]}))}let e=!1;for(var t=0;t\]/.test(gametext_arr[t]))for(let n in image_db){let o=image_db[n],r="[<|p|"+n+"|p|>]";if(gametext_arr[t].includes(r)&&(e=!0,1==o.done&&""!=o.result)){let e="[<|d|"+o.result+"|d|>]";console.log("Replacing with Image: "+r),gametext_arr[t]=gametext_arr[t].replace(r,e),completed_imgs_meta[cyrb_hash(o.result)]={alt:image_db[n].alt},delete image_db[n]}}e&&document.activeElement!=document.getElementById("gametext")&&render_gametext()}function compressImage(e,t){let n=document.createElement("img");n.onload=function(){var e=document.createElement("canvas"),n=e.getContext("2d");e.width=256,e.height=256,n.drawImage(this,0,0,256,256);var o=e.toDataURL("image/jpeg",.33);t(o)},n.src=e}var idle_timer=0,idle_triggered_counter=0;function poll_background_tasks(){let e=1e3*localsettings.idle_duration,t=""==document.getElementById("input_text").value,n=""==document.getElementById("cht_inp").value;if((1==localsettings.opmode||3==localsettings.opmode)&&localsettings.idle_responses>0&&t&&n&&!document.getElementById("btnsend").disabled&&idle_triggered_countere){idle_timer=0;let e=++idle_triggered_counter;submit_generation(),idle_triggered_counter=e}console.log("Idling: "+idle_timer+", "+idle_triggered_counter)}else idle_timer=0}function poll_pending_response(){if(++poll_ticks_passed,is_using_custom_ep()||poll_ticks_passed%3==0)if(show_abort_button(!1),pending_response_id&&"-1"!=pending_response_id&&""!=pending_response_id)if(poll_ticks_passed>4/(.001*poll_interval_base_text)&&show_abort_button(!0),poll_in_progress)console.log("Polling still in progress for id: "+pending_response_id);else if(is_using_custom_ep())if(poll_in_progress=!0,null==synchro_polled_response){console.log("v1 still awaiting reply");let e=should_use_pseudostreaming();!!!document.getElementById("pseudostreaming").checked||e||waiting_for_autosummary||poll_ticks_passed%2!=0?poll_in_progress=!1:fetch(custom_kobold_endpoint+koboldcpp_check_endpoint,{method:"POST",headers:{"Content-Type":"application/json"}}).then((e=>e.json())).then((e=>{e&&null!=e.results&&e.results.length>0&&e.results[0].text&&pending_response_id&&""!=pending_response_id&&(synchro_pending_stream=e.results[0].text,render_gametext()),poll_in_progress=!1})).catch((e=>{console.error("Error:",e),poll_in_progress=!1}))}else{console.log("v1 handle recv reply"),pending_response_id="",poll_in_progress=!1;let e=synchro_polled_response;if(null!=e&&""!=e){let t=e,n="Custom Endpoint",o="0",r=selected_models.length>0?selected_models[0].name:"Unknown Model";waiting_for_autosummary?handle_incoming_autosummary(t):handle_incoming_text(t,n,r,o)}synchro_polled_response=null,synchro_pending_stream="",show_abort_button(!1),render_gametext()}else console.log("v2 Polling started for pending id: "+pending_response_id),poll_in_progress=!0,fetch(pending_response_horde.polling_endpoint+"/"+pending_response_id).then((e=>e.json())).then((e=>{if(null!=e.message||1==e.faulted||0==e.is_possible){console.log("Gave up on failed attempt"),clear_poll_flags(),render_gametext(),show_abort_button(!1);let t="Error encountered during text generation!\n";null!=e.message&&(t+=e.message),1==e.faulted&&(t+="Fault encountered during text generation."),0==e.is_possible&&(t+="No workers were able to generate text with your request."),msgbox(t)}else if(1==e.done)setTimeout((()=>{console.log("fetching completed generation for "+pending_response_id),fetch(pending_response_horde.output_endpoint+"/"+pending_response_id).then((e=>e.json())).then((e=>{if(console.log("Finished "+pending_response_id+": "+JSON.stringify(e)),pending_response_id="",poll_in_progress=!1,null!=e.generations&&e.generations.length>0){let t=e.generations[0].text,n=e.generations[0].worker_name,o=e.generations[0].model,r=e.kudos;waiting_for_autosummary?handle_incoming_autosummary(t):handle_incoming_text(t,n,o,r)}render_gametext(),show_abort_button(!1)})).catch((e=>{console.error("Error:",e),clear_poll_flags(),render_gametext(),show_abort_button(!1),msgbox("Error encountered during text generation!")}))}),500);else{poll_in_progress=!1;let t=document.getElementById("maintxtloader");if(t){t.classList.remove("greenloader"),t.classList.remove("redloader"),e.queue_position>0?t.classList.add("redloader"):1==e.processing&&0==e.queue_position&&t.classList.add("greenloader");let n=document.getElementById("outerloadernum");n&&(n.innerText=0==e.queue_position?"":e.queue_position)}console.log("Still awaiting "+pending_response_id+": "+JSON.stringify(e))}})).catch((e=>{console.error("Error:",e),clear_poll_flags(),render_gametext(),show_abort_button(!1),msgbox("Error encountered during text generation!")}));else console.log("Nothing to update: "+pending_response_id)}function click_gametext(){if(document.getElementById("allowediting").checked){if(void 0!==window.getSelection){const e=window.getSelection();null!=e.focusNode&&null!=e.focusNode.parentElement&&e.focusNode.parentElement.classList.contains("txtchunk")&&(null!=prev_hl_chunk&&prev_hl_chunk.classList.remove("hlchunk"),(prev_hl_chunk=e.focusNode.parentElement).classList.add("hlchunk")),idle_timer=0}}}function merge_edit_field(){if(gametext_arr.length>0&&document.getElementById("allowediting").checked){let t=concat_gametext(!0,"\n","",""),n=document.getElementById("gametext");if(t!=n.innerText){gametext_arr=[],redo_arr=[],retry_prev_text="",redo_prev_text="",n.querySelectorAll("div.storyimg,div.storyimgfloat").forEach((e=>{let t=e.getElementsByTagName("img")[0];e.replaceWith(null==t.alt||""==t.alt?"[<|d|"+t.src+"|d|>]":"[<|p|"+t.alt+"|p|>]")}));let t=[];n.querySelectorAll("span.txtchunk").forEach((e=>{t.push(e.innerText)})),n.innerHTML=n.innerHTML.replace(/(.+?)<\/span>/g,"$2"),n.innerHTML=n.innerHTML.replace(/(.+?)<\/span>/g,"$2"),n.innerHTML=replaceAll(n.innerHTML,"
")&&(e=e.slice(0,-4)),document.getElementById("gametext").innerHTML=e}else{if(null==perfdata)document.getElementById("gametext").innerHTML='Welcome to KoboldAI Lite! You are in Offline Mode. You will still be able to load and edit stories, but not generate new text.';else{let e="";e=""!=custom_kobold_endpoint?' You\'re using the custom KoboldAI endpoint at '+custom_kobold_endpoint+"":""!=custom_oai_key?" You're using the OpenAI API":""!=custom_scale_key?" You're using the Spellbook by Scale AI API":""!=custom_claude_key?" You're using the Claude API":' There are '+selected_models.reduce(((e,t)=>e+t.count),0)+'volunteer(s) running selected models with a total queue length of '+selected_models.reduce(((e,t)=>e+t.queued),0)+" tokens",document.getElementById("gametext").innerHTML='Welcome to KoboldAI Lite! You are using the models '+selected_models.reduce(((e,t)=>e+(""==e?"":", ")+t.name),"")+""+(0==selected_workers.length?"":" (Pinned to "+selected_workers.length+" worker IDs)")+"."+e+'.
Enter a prompt below to begin! Or, select a Quick Start Scenario by clicking here. '}document.getElementById("allowediting").checked&&(document.getElementById("allowediting").checked=!1,toggle_editable())}if(null==perfdata?(document.getElementById("topbtn_reconnect").classList.remove("hidden"),localmode?document.getElementById("topbtn_customendpt").classList.add("hidden"):document.getElementById("topbtn_customendpt").classList.remove("hidden"),document.getElementById("topbtn_ai").classList.add("hidden"),document.getElementById("topbtn_newgame").classList.remove("hidden"),document.getElementById("topbtn_save").classList.remove("hidden"),document.getElementById("topbtn_load").classList.remove("hidden"),document.getElementById("topbtn_settings").classList.add("hidden"),document.getElementById("topbtn_share").classList.add("hidden"),document.getElementById("topbtn_scenarios").classList.add("hidden"),document.getElementById("topbtn_quickplay").classList.add("hidden")):(document.getElementById("topbtn_reconnect").classList.add("hidden"),document.getElementById("topbtn_customendpt").classList.add("hidden"),localmode?document.getElementById("topbtn_ai").classList.add("hidden"):document.getElementById("topbtn_ai").classList.remove("hidden"),0==selected_models.length?(document.getElementById("topbtn_newgame").classList.add("hidden"),document.getElementById("topbtn_save").classList.add("hidden"),document.getElementById("topbtn_load").classList.add("hidden"),document.getElementById("topbtn_settings").classList.add("hidden"),document.getElementById("topbtn_share").classList.add("hidden"),document.getElementById("topbtn_scenarios").classList.add("hidden"),document.getElementById("topbtn_quickplay").classList.remove("hidden")):(document.getElementById("topbtn_newgame").classList.remove("hidden"),document.getElementById("topbtn_save").classList.remove("hidden"),document.getElementById("topbtn_load").classList.remove("hidden"),document.getElementById("topbtn_settings").classList.remove("hidden"),document.getElementById("topbtn_share").classList.remove("hidden"),document.getElementById("topbtn_scenarios").classList.remove("hidden"),document.getElementById("topbtn_quickplay").classList.add("hidden"))),0==selected_models.length?(document.getElementById("btn_actmem").disabled=!0,document.getElementById("btn_actwi").disabled=!0,document.getElementById("btn_actundo").disabled=!0,document.getElementById("btn_actredo").disabled=!0,document.getElementById("btn_actretry").disabled=!0,null==perfdata&&(document.getElementById("btn_actmem").disabled=!1,document.getElementById("btn_actwi").disabled=!1)):(document.getElementById("btn_actmem").disabled=!1,document.getElementById("btn_actwi").disabled=!1,document.getElementById("btn_actundo").disabled=!1,document.getElementById("btn_actredo").disabled=!1,document.getElementById("btn_actretry").disabled=!1),null==perfdata)document.getElementById("btnsend").disabled=!0,document.getElementById("btnsend").classList.add("wait"),document.getElementById("btnsend").classList.remove("btn-primary"),document.getElementById("btnsend").innerHTML="Offline",document.getElementById("fvico").href=favivon_normal;else if(0==selected_models.length&&0==selected_workers.length){document.getElementById("btnsend").disabled=!0,document.getElementById("btnsend").classList.add("wait"),document.getElementById("btnsend").classList.remove("btn-primary"),document.getElementById("btnsend").innerHTML="No AI Loaded";let e='There are '+perfdata.worker_count+' total volunteer(s) in the KoboldAI Horde, and '+perfdata.queued_requests+' request(s) in queues. A total of '+perfdata.past_minute_tokens+" tokens were generated in the last minute.
";document.getElementById("gametext").innerHTML='Welcome to KoboldAI Lite!
'+e+'Please select an AI model to use! ',document.getElementById("fvico").href=favivon_normal}else if(""==pending_response_id)document.getElementById("btnsend").disabled=!1,document.getElementById("btnsend").classList.remove("wait"),document.getElementById("btnsend").classList.add("btn-primary"),document.getElementById("btnsend").innerHTML="Submit",document.getElementById("fvico").href=favivon_normal;else{document.getElementById("btnsend").disabled=!0,document.getElementById("btnsend").classList.add("wait"),document.getElementById("btnsend").classList.remove("btn-primary");let e='