@@ -12,7 +12,7 @@ Current version indicated by LITEVER below.
1212-->
1313
1414<script>
15- const LITEVER = 255 ;
15+ const LITEVER = 256 ;
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_";
@@ -16082,18 +16082,30 @@ Current version indicated by LITEVER below.
1608216082 //insert authors note 80 tokens before the ending (320 characters).
1608316083 let anote_dist = anote_strength;
1608416084 let anote_insert_idx = truncated_context.length - anote_dist;
16085+ anote_insert_idx = clamp(anote_insert_idx, 0, truncated_context.length);
1608516086 //try to align anote with a word boundary
16086- for(let i=0;i<15;++i)
16087- {
16088- if(anote_insert_idx>=0 && anote_insert_idx<truncated_context.length
16089- && truncated_context[anote_insert_idx]!=" " && truncated_context[anote_insert_idx]!="."
16090- && truncated_context[anote_insert_idx]!="!" && truncated_context[anote_insert_idx]!="?"
16091- && truncated_context[anote_insert_idx]!="," && truncated_context[anote_insert_idx]!="\n")
16092- {
16093- ++anote_insert_idx;
16094- }else{
16087+ const maxLookahead = 30;
16088+ let best_insert_idx = anote_insert_idx;
16089+ let insert_preference = 0;
16090+ for (let i = 0; i < maxLookahead && anote_insert_idx + i < truncated_context.length; ++i) {
16091+ const char = truncated_context[anote_insert_idx + i];
16092+ if (char == "\n") {
16093+ best_insert_idx = anote_insert_idx + i + 1;
16094+ insert_preference = 3;
1609516095 break;
1609616096 }
16097+ if (insert_preference<=1 && (char == "," || char == "!" || char == "." || char == "?")) {
16098+ best_insert_idx = anote_insert_idx + i + 1;
16099+ insert_preference = 2;
16100+ }
16101+ if (insert_preference==0 && (char == " ")) {
16102+ best_insert_idx = anote_insert_idx + i + 1;
16103+ insert_preference = 1;
16104+ }
16105+ }
16106+ if(insert_preference>0)
16107+ {
16108+ anote_insert_idx = best_insert_idx;
1609716109 }
1609816110 anote_insert_idx = clamp(anote_insert_idx, 0, truncated_context.length);
1609916111 truncated_context = truncated_context.slice(0, anote_insert_idx) + truncated_anote + truncated_context.slice(anote_insert_idx);
0 commit comments