@@ -12,7 +12,7 @@ Current version indicated by LITEVER below.
1212-->
1313<head>
1414 <script id="init-config">
15- const LITEVER = 326 ;
15+ const LITEVER = 327 ;
1616 const urlParams = new URLSearchParams(window.location.search);
1717 var localflag = urlParams.get('local'); //this will be replaced automatically in embedded kcpp
1818 const STORAGE_PREFIX = (localflag?"e_":"")+"kaihordewebui_";
@@ -3558,6 +3558,7 @@ Current version indicated by LITEVER below.
35583558 // whitelisted auto selected horde model names
35593559 const defaultmodels = ["gpt4all","supercot","pygmalion-6","pygmalion-v8","pygmalion-2","hermes","airoboros","chrono","wizard","mantis","vicuna","manticore","alpaca","myth","xwin","spicyboros","mlewd","mxlewd","westlake","anubis","skyfall","llama2","llama3","llama-2","llama-3-","llama-3.","mistral","maid","mixtral","estopia","fighter","fimbul","euryale","nemo","gemma","lunaris","stheno","magnum","cydonia","qwen2.5-32b","behemoth","exaone","glm4","glm-4","tutu","deepseek","tlacuilo","rocinante","-14B","-32B","-27B","-35B"];
35603560 const ignoredmodels = ["tinyllama","debug-","-1b","-270m"]; //blacklisted model names
3561+ const hardcoded_think_closers = ["</think>","<channel|>"];
35613562
35623563 const instructstartplaceholder = "\n{{[INPUT]}}\n";
35633564 const instructendplaceholder = "\n{{[OUTPUT]}}\n";
@@ -5868,14 +5869,14 @@ Current version indicated by LITEVER below.
58685869 const safeStop = escapeRegExp(localsettings.stop_thinking_tag);
58695870 return `${safeStart}([\\s\\S]*?)${safeStop}`;
58705871 }
5871- function get_orphaned_thinking_regex()
5872+ function get_orphaned_thinking_regex(tag )
58725873 {
5873- if(!localsettings.start_thinking_tag || !localsettings.stop_thinking_tag )
5874+ if(!tag )
58745875 {
58755876 return "";
58765877 }
58775878 const safeStart = escapeRegExp(get_instructendplaceholder());
5878- const safeStop = escapeRegExp(localsettings.stop_thinking_tag );
5879+ const safeStop = escapeRegExp(tag );
58795880 return `${safeStart}([\\s\\S]*?)${safeStop}`;
58805881 }
58815882
@@ -6095,12 +6096,12 @@ Current version indicated by LITEVER below.
60956096 let promptEtIndex = prompt.lastIndexOf(et);
60966097 if(prompt && promptEtIndex!=-1 && localsettings.instruct_gentag)
60976098 {
6098- prompt = replaceLast(prompt,et,localsettings.instruct_gentag);
6099+ prompt = replaceLast(prompt,et,localsettings.instruct_gentag.replaceAll("\\n", "\n") );
60996100 replaceDone = true;
61006101 }
61016102 if(!replaceDone && memory && memoryEtIndex!=-1 && localsettings.instruct_gentag)
61026103 {
6103- memory = replaceLast(memory,et,localsettings.instruct_gentag);
6104+ memory = replaceLast(memory,et,localsettings.instruct_gentag.replaceAll("\\n", "\n") );
61046105 replaceDone = true;
61056106 }
61066107 }
@@ -7475,7 +7476,7 @@ Current version indicated by LITEVER below.
74757476 pending_toolcall_objs.push(pending_toolcall_last_obj);
74767477 pending_toolcall_last_obj = null;
74777478 }
7478- if((synchro_polled_response=="" || (synchro_polled_response.includes("<think>") && synchro_polled_response.includes("</think>"))) && last_stop_reason=="tool_calls" && pending_toolcall_objs!=null && pending_toolcall_objs.length>0)
7479+ if(last_stop_reason=="tool_calls" && pending_toolcall_objs!=null && pending_toolcall_objs.length>0)
74797480 {
74807481 //a tool call was triggered instead
74817482 synchro_polled_resptoolcalls = [];
@@ -9569,10 +9570,7 @@ Current version indicated by LITEVER below.
95699570 }
95709571
95719572 if (localsettings.eos_ban_mode == 0) {
9572- if (localsettings.opmode == 1) {
9573- return true; //story mode always ban
9574- }
9575- else if (localsettings.opmode == 3 && !localsettings.allow_continue_chat) {
9573+ if (localsettings.opmode == 3 && !localsettings.allow_continue_chat) {
95769574 return false; //chat mode always unban unless cont allowed
95779575 }
95789576 else if (!input_was_empty) //if user input is not empty, ALWAYS unban EOS.
@@ -17979,13 +17977,23 @@ Current version indicated by LITEVER below.
1797917977 }
1798017978 else
1798117979 {
17982- if(localsettings.handle_mismatched_think && !inputtxt.includes( localsettings.start_thinking_tag) && inputtxt.includes(localsettings.stop_thinking_tag ))
17980+ if(localsettings.opmode==4 && localsettings.handle_mismatched_think && ! inputtxt.includes(localsettings.start_thinking_tag ))
1798317981 {
17984- let chunks = inputtxt.split(localsettings.stop_thinking_tag);
17985- if(chunks.length==2) //exactly 2 parts
17982+ let orphans = hardcoded_think_closers.slice();
17983+ orphans.push(localsettings.stop_thinking_tag);
17984+ for(let t=0;t<orphans.length;++t)
1798617985 {
17987- matches.push(chunks[0]);
17988- inputtxt = `%ExpandBtn%${chunks[1]}`;
17986+ let currtag = orphans[t];
17987+ if(currtag && inputtxt.includes(currtag))
17988+ {
17989+ let chunks = inputtxt.split(currtag);
17990+ if(chunks.length==2) //exactly 2 parts
17991+ {
17992+ matches.push(chunks[0]);
17993+ inputtxt = `%ExpandBtn%${chunks[1]}`;
17994+ break;
17995+ }
17996+ }
1798917997 }
1799017998 }
1799117999 }
@@ -18001,7 +18009,9 @@ Current version indicated by LITEVER below.
1800118009 let matchiter = 0;
1800218010 inputtxt = inputtxt.replace(/%ExpandBtn%(?:\n{0,2})?/g, function (m) {
1800318011 let curr = matches[matchiter];
18004- let expandedhtml = `<span><button type="button" title="Show Thoughts" class="btn btn-primary" style="font-size:12px;padding:2px 2px;" onclick="toggle_hide_thinking(this)">Show Thoughts (${curr.length} characters)</button><span class="color_lightgreen hidden"><br>${escape_html(curr)}\n</span><br></span>`;
18012+ curr = escape_html(curr);
18013+ curr = unescape_html_alternate(curr);
18014+ let expandedhtml = `<span><button type="button" title="Show Thoughts" class="btn btn-primary" style="font-size:12px;padding:2px 2px;" onclick="toggle_hide_thinking(this)">Show Thoughts (${curr.length} characters)</button><span class="color_lightgreen hidden"><br>${(curr)}\n</span><br></span>`;
1800518015 if(!curr || curr.trim()=="" || curr.trim()=="/nothink" || curr.trim()==`${localsettings.start_thinking_tag}${localsettings.stop_thinking_tag}`)
1800618016 {
1800718017 expandedhtml = `<span><button type="button" title="No Thoughts" class="btn btn-primary" style="font-size:12px;padding:2px 2px;" onclick="">No Thoughts</button><br></span>`;
@@ -19840,11 +19850,21 @@ Current version indicated by LITEVER below.
1984019850 truncated_context = truncated_context.replace(pat, "");
1984119851
1984219852 //fallback, check for orphaned think tags and remove those as well
19843- if(localsettings.opmode==4 && localsettings.stop_thinking_tag && truncated_context.includes(localsettings.stop_thinking_tag) )
19853+ if(localsettings.opmode==4)
1984419854 {
19845- let endmatcher = get_instructendplaceholder();
19846- let pat = new RegExp(get_orphaned_thinking_regex(), "gm");
19847- truncated_context = truncated_context.replace(pat, endmatcher);
19855+ let orphans = hardcoded_think_closers.slice();
19856+ orphans.push(localsettings.stop_thinking_tag);
19857+ for(let t=0;t<orphans.length;++t)
19858+ {
19859+ let currtag = orphans[t];
19860+ if(localsettings.opmode==4 && currtag && truncated_context.includes(currtag))
19861+ {
19862+ let endmatcher = get_instructendplaceholder();
19863+ let pat = new RegExp(get_orphaned_thinking_regex(currtag), "gm");
19864+ truncated_context = truncated_context.replace(pat, endmatcher);
19865+ break;
19866+ }
19867+ }
1984819868 }
1984919869 }
1985019870 else if(localsettings.strip_thinking_mode==1) //strip except recent
@@ -19857,11 +19877,21 @@ Current version indicated by LITEVER below.
1985719877 let pat = new RegExp(get_thinking_regex(), "gm"); // Remove all thinking before splitpoint
1985819878 beforePart = beforePart.replace(pat, "");
1985919879
19860- //fallback, check for orphaned think tags and remove those as well
19861- if(localsettings.opmode==4 && localsettings.stop_thinking_tag && beforePart.includes(localsettings.stop_thinking_tag))
19880+ if(localsettings.opmode==4)
1986219881 {
19863- let pat = new RegExp(get_orphaned_thinking_regex(), "gm");
19864- beforePart = beforePart.replace(pat, endmatcher);
19882+ //fallback, check for orphaned think tags and remove those as well
19883+ let orphans = hardcoded_think_closers.slice();
19884+ orphans.push(localsettings.stop_thinking_tag);
19885+ for(let t=0;t<orphans.length;++t)
19886+ {
19887+ let currtag = orphans[t];
19888+ if(localsettings.opmode==4 && currtag && beforePart.includes(currtag))
19889+ {
19890+ let pat = new RegExp(get_orphaned_thinking_regex(currtag), "gm");
19891+ beforePart = beforePart.replace(pat, endmatcher);
19892+ break;
19893+ }
19894+ }
1986519895 }
1986619896
1986719897 truncated_context = beforePart + afterPart; // Combine and done
@@ -20524,22 +20554,8 @@ Current version indicated by LITEVER below.
2052420554 {
2052520555 seqs.push(me + "\:");
2052620556 }
20527- if(localsettings.chatopponent!="")
20528- {
20529- //NOTE: we do not add our opponents name as a stop sequence IF thinking is forced
20530- //the model just gets too confused and is likely to repeat the tag.
20531- if(localsettings.think_injected!=1)
20532- {
20533- let m_opps = localsettings.chatopponent.split("||$||");
20534- for(let i=0;i<m_opps.length;++i)
20535- {
20536- if(m_opps[i] && m_opps[i].trim()!="")
20537- {
20538- seqs.push(m_opps[i] + "\:");
20539- }
20540- }
20541- }
20542- }
20557+ //NOTE: we do not add our opponents name as a stop sequence
20558+ //the model just gets too confused and is likely to repeat the tag.
2054320559 }
2054420560 }
2054520561 //special case for GPT-OSS, never use it as a stop sequence or stuff gets messed
@@ -20979,6 +20995,14 @@ Current version indicated by LITEVER below.
2097920995 mhistory.splice(1, 1);
2098020996 }
2098120997
20998+ //if the final turn is the assistant chatname only, we shift that into the user turn, that helps support models that reject prefills
20999+ if(mhistory.length>2 && !mhistory[mhistory.length-1].myturn && mhistory[mhistory.length-2].myturn &&
21000+ mhistory[mhistory.length-2].msg && mhistory[mhistory.length-1].msg == `${localsettings.chatopponent}:`)
21001+ {
21002+ mhistory[mhistory.length-2].msg += `\n(Continue ${localsettings.chatopponent}'s reply')`;
21003+ mhistory.pop();
21004+ }
21005+
2098221006 if(mhistory.length>0 && mainoaibody.length>1 && mainoaibody[1].type && mainoaibody[1].type!="text")
2098321007 {
2098421008 mhistory[0].msg = [{type: 'text', text: mhistory[0].msg}];
@@ -21109,7 +21133,7 @@ Current version indicated by LITEVER below.
2110921133 //pollinations always uses the exact same url for text gen regardless
2111021134 if(targetep.toLowerCase().includes("text.pollinations.ai"))
2111121135 {
21112- targetep = apply_proxy_url(pollinations_text_endpoint);
21136+ targetep = apply_proxy_url(pollinations_text_endpoint,true );
2111321137 oai_payload.private = true;
2111421138 oai_payload.referrer = "koboldai";
2111521139 oai_payload.seed = Math.floor(Math.random() * 99999999);
@@ -22480,7 +22504,7 @@ Current version indicated by LITEVER below.
2248022504
2248122505 //allow trim incomplete sentences
2248222506 //do not trim if instruct mode AND stop token reached
22483- let donottrim = ((localsettings.opmode == 4||localsettings.opmode == 3) && last_stop_reason=="stop");
22507+ let donottrim = (last_stop_reason=="stop");
2248422508 if (!donottrim && localsettings.trimsentences == true) {
2248522509 //also, to prevent a trim from bisecting a chat name, if a response contains a chatname, do not trim
2248622510 donottrim = false;
@@ -22732,11 +22756,11 @@ Current version indicated by LITEVER below.
2273222756 gentxt = gentxt.slice(et2.length);
2273322757 found = gentxt.indexOf(et2);
2273422758 }
22735- if (found != -1) //if found, truncate to it
22736- {
22737- splitresponse = gentxt.split(et2);
22738- gentxt = splitresponse[0];
22739- }
22759+ // if (found != -1) //if found, truncate to it
22760+ // {
22761+ // splitresponse = gentxt.split(et2);
22762+ // gentxt = splitresponse[0];
22763+ // }
2274022764 }
2274122765 }
2274222766 }
@@ -29783,13 +29807,13 @@ Current version indicated by LITEVER below.
2978329807
2978429808 <div style="display:flex;width:100%;">
2978529809 <div class="settinglabel settingcell">
29786- <div title="Sampler Order" class="justifyleft" style="width:100%">Sampler Order <span class="helpicon">?<span class="helptext">
29810+ <div class="justifyleft" style="width:100%">Sampler Order <span class="helpicon">?<span class="helptext">
2978729811 The order by which all 7 samplers are applied, separated by commas. 0=top_k, 1=top_a, 2=top_p, 3=tfs, 4=typ, 5=temp, 6=rep_pen</span></span></div>
2978829812 <div class="justifyleft" style="width:100%;">
2978929813 <input title="Sampler Order List" class="settinglabel miniinput" type="text" placeholder="CSV" value="" id="sampler_order" onblur="validate_samplers()"></div>
2979029814 </div>
2979129815 <div class="settinglabel settingcell">
29792- <div title="Top N Sigma" class="justifyleft" style="width:100%">T.NSigma <span class="helpicon">?<span class="helptext">
29816+ <div class="justifyleft" style="width:100%">T.NSigma <span class="helpicon">?<span class="helptext">
2979329817 Top N-Sigma. 0 to deactivate. Range 0 to 5. Not supported on Horde.</span></span></div>
2979429818 <div id="nsigmasupporteddiv" style="display:flex;">
2979529819 <div class="justifyleft" style="width:100%">
@@ -29831,7 +29855,7 @@ Current version indicated by LITEVER below.
2983129855 </div>
2983229856 </div>
2983329857 <div class="settinglabel settingcell">
29834- <div title="XTC" class="justifyleft" style="width:100%">XTC <span class="helpicon">?<span class="helptext">
29858+ <div class="justifyleft" style="width:100%">XTC <span class="helpicon">?<span class="helptext">
2983529859 Enables Exclude Top Choices (XTC) Sampling. May not be available depending on backend, not supported on Horde.</span></span></div>
2983629860 <div class="justifyleft" style="width:100%">
2983729861 <div id="xtcsupporteddiv" style="display:flex;">
@@ -29853,7 +29877,7 @@ Current version indicated by LITEVER below.
2985329877
2985429878 <div style="display:flex;width:100%;">
2985529879 <div class="settinglabel settingcell">
29856- <div title="Adaptive-P" class="justifyleft" style="width:100%">Adapt.P. <span class="helpicon">?<span class="helptext">
29880+ <div class="justifyleft" style="width:100%">Adapt.P. <span class="helpicon">?<span class="helptext">
2985729881 Enables Adaptive-P Sampling. Target ranges 0.0 to 1.0, 0 to deactivate. Decay ranges from 0.0 to 1.0. Not supported on Horde.</span></span></div>
2985829882 <div class="justifyleft" style="width:100%">
2985929883 <div id="adaptpsupporteddiv" style="display:flex;">
@@ -29872,7 +29896,7 @@ Current version indicated by LITEVER below.
2987229896 </div>
2987329897 </div>
2987429898 <div class="settinglabel settingcell">
29875- <div title="Mirostat" class="justifyleft" style="width:100%">Mirostat <span class="helpicon">?<span class="helptext">
29899+ <div class="justifyleft" style="width:100%">Mirostat <span class="helpicon">?<span class="helptext">
2987629900 Replaces your samplers with mirostat, an alternative sampling method. May not be available depending on backend, not supported on Horde.</span></span></div>
2987729901 <div class="justifyleft" style="width:100%">
2987829902 <div id="mirosupporteddiv" style="display:flex;">
@@ -31450,8 +31474,8 @@ Current version indicated by LITEVER below.
3145031474 <div>
3145131475 <div style="vertical-align: middle;">
3145231476 <div>
31453- <span class="color_red">Also Reset Memory and World Info? </span>
31454- <input type="checkbox" id="new_session_erase_memory" style="vertical-align: top ;">
31477+ <span class="color_red"><b> Also Reset Memory and World Info? </b> </span>
31478+ <input type="checkbox" id="new_session_erase_memory" style="vertical-align: text-bottom ;">
3145531479 </div>
3145631480 </div>
3145731481 </div>
0 commit comments