mirror of
https://github.com/LostRuins/koboldcpp.git
synced 2026-05-17 04:09:19 +00:00
updated lite
This commit is contained in:
parent
7a2f653451
commit
301eae8c2c
1 changed files with 62 additions and 24 deletions
|
|
@ -7778,22 +7778,60 @@ Current version indicated by LITEVER below.
|
|||
function stashLatex(text) { //this function preserves the contents of multiline latex blocks so they don't get corrupted by markdown
|
||||
const latexBlocks = [];
|
||||
let counter = 0;
|
||||
|
||||
const stash = (match) => {
|
||||
const key = `%%LATEXBLK${counter++}%%`;
|
||||
latexBlocks.push({ key, value: match });
|
||||
return key;
|
||||
};
|
||||
|
||||
// 1. Blockquote-wrapped $$ blocks (existing)
|
||||
text = text.replace(/(^> \$\$\n([\s\S]*?)\n\$\$)/gm, (match) => {
|
||||
const key = `%%LATEXBLK${counter++}%%`;
|
||||
latexBlocks.push({ key, value: match.slice(2) });
|
||||
return key;
|
||||
});
|
||||
text = text.replace(/(^ {0,6}\\\[\n([\s\S]*?)\n {0,6}\\\] {0,2}$|^\$\$\n([\s\S]*?)\n\$\$$|^ {2}\$\$\n {2}([\s\S]*?)\n {2}\$\$$|\$\$([^\n]+?)\$\$|\\\(([^\n]+?)\\\)|\\\[([^\n]+?)\\\])/gm, (match, p1, p2, p3, p4, p5, p6, p7) => {
|
||||
|
||||
// 2. All block-level latex (existing)
|
||||
text = text.replace(/(^ {0,6}\\\[\n([\s\S]*?)\n {0,6}\\\] {0,2}$|^\$\$\n([\s\S]*?)\n\$\$$|^ {2}\$\$\n {2}([\s\S]*?)\n {2}\$\$$|\$\$([^\n]+?)\$\$|\\\(([^\n]+?)\\\)|\\\[([^\n]+?)\\\])/gm,
|
||||
(match) => stash(match)
|
||||
);
|
||||
|
||||
// 3. Inline: $word$ or $letter$ — mirrors replaceLatex patterns
|
||||
text = text.replace(/(^|[^\\])\$(\S[^$\n]*?\S)\$(?!\w)/g, (match, prefix, inner) => {
|
||||
if (inner.startsWith('$')) return match; // buggy match guard
|
||||
if (inner.replace(/\s+/g, '').match(/^\$+$/)) return match; // only dollar signs
|
||||
const key = `%%LATEXBLK${counter++}%%`;
|
||||
latexBlocks.push({ key, value: match });
|
||||
return key;
|
||||
latexBlocks.push({ key, value: `$${inner}$` });
|
||||
return prefix + key;
|
||||
});
|
||||
return { "text":text, "blocks":latexBlocks };
|
||||
|
||||
// 4. Inline: single letter/number $x$
|
||||
text = text.replace(/(^|[^\\])\$([A-Za-z0-9])\$(?!\d)/g, (match, prefix, inner) => {
|
||||
const key = `%%LATEXBLK${counter++}%%`;
|
||||
latexBlocks.push({ key, value: `$${inner}$` });
|
||||
return prefix + key;
|
||||
});
|
||||
|
||||
// 5. Inline: $ content $ (space-padded variant)
|
||||
text = text.replace(/(^|[^\\])\$ (\S[^$\n]*?) \$(?!\d)/g, (match, prefix, inner) => {
|
||||
if (inner.replace(/\s+/g, '').match(/^\$+$/)) return match;
|
||||
const key = `%%LATEXBLK${counter++}%%`;
|
||||
latexBlocks.push({ key, value: `$ ${inner} $` });
|
||||
return prefix + key;
|
||||
});
|
||||
|
||||
return { text, blocks: latexBlocks };
|
||||
}
|
||||
function unstashLatex(text, latexBlocks) {
|
||||
function unstashLatex(text, latexBlocks, render) {
|
||||
for(let i=0;i<latexBlocks.length;++i)
|
||||
{
|
||||
text = literalReplace(text,latexBlocks[i].key,latexBlocks[i].value);
|
||||
let val = latexBlocks[i].value;
|
||||
if(render)
|
||||
{
|
||||
val = replaceLatex(val);
|
||||
}
|
||||
text = literalReplace(text,latexBlocks[i].key,val);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
|
@ -8010,16 +8048,16 @@ Current version indicated by LITEVER below.
|
|||
md = md.replace(/<\/code\><\/pre\>\n<pre\><code\>/g, "\n");
|
||||
if(renderLatex)
|
||||
{
|
||||
if(stashLatexRes!=null)
|
||||
{
|
||||
md = unstashLatex(md,stashLatexRes.blocks);
|
||||
}
|
||||
//to aid the latex renderer, we temporarily add newlines between some blocks
|
||||
md = md.replace(/<\/li><li>/gm, "</li>\n<li>");
|
||||
md = md.replace(/<\/tr><tr class/gm, "</tr>\n<tr class");
|
||||
md = replaceLatex(md);
|
||||
md = replaceLatex(md); //catch all the latex that wasn't stashed
|
||||
md = md.replace(/<\/li>\n<li>/gm, "</li><li>");
|
||||
md = md.replace(/<\/tr>\n<tr class/gm, "</tr><tr class");
|
||||
if(stashLatexRes!=null)
|
||||
{
|
||||
md = unstashLatex(md,stashLatexRes.blocks,true); //for each stashed block, render it
|
||||
}
|
||||
}
|
||||
md = md.replace(/<\/ul>\n/gm, "</ul>").replace(/<\/ol>\n/gm, "</ol>");
|
||||
md = md.replace(/\\([`_~\*\+\-\.\^\\\<\>\(\)\[\]])/gm, "$1");
|
||||
|
|
@ -17169,7 +17207,7 @@ Current version indicated by LITEVER below.
|
|||
switch(themeid)
|
||||
{
|
||||
case "0": return "The classic simple Kobold theme everyone loves."; break;
|
||||
case "1": return "A compact instant messenger styled chat theme."; break;
|
||||
case "1": return "A compact instant-messenger-styled chat theme."; break;
|
||||
case "2": return "Customizable aesthetic theme with character portraits."; break;
|
||||
case "3": return "Clean, minimalistic, corporate AI assistant theme."; break;
|
||||
default: return ""; break;
|
||||
|
|
@ -17263,7 +17301,7 @@ Current version indicated by LITEVER below.
|
|||
case "1": document.getElementById("opmodedesc").innerText = "Let the AI co-write a story."; break;
|
||||
case "2": document.getElementById("opmodedesc").innerText = "Participate in turn-based interactive adventures."; break;
|
||||
case "3": document.getElementById("opmodedesc").innerText = "Roleplay with a virtual chatbot AI."; break;
|
||||
case "4": document.getElementById("opmodedesc").innerText = "Give the AI instructions, questions, or do tasks."; break;
|
||||
case "4": document.getElementById("opmodedesc").innerText = "Give the AI instructions, questions, or tasks."; break;
|
||||
default: document.getElementById("opmodedesc").innerText = ""; break;
|
||||
}
|
||||
|
||||
|
|
@ -29537,7 +29575,7 @@ Current version indicated by LITEVER below.
|
|||
<h3 style="margin-top: 4px;">Usage Mode</h3>
|
||||
<div>
|
||||
<div class="settinglabel">
|
||||
<div class="justifyleft">Usage mode <span class="helpicon">?<span class="helptext">Story Mode is best for novel style writing. Adventure Mode is best for Interactive Fiction RPGs. Chat Mode is best for chat conversations with the AI. Instruct mode is for giving the AI ChatGPT styled tasks.</span></span></div>
|
||||
<div class="justifyleft">Usage mode <span class="helpicon">?<span class="helptext">Story Mode is best for novel-style writing. Adventure Mode is best for Interactive Fiction RPGs. Chat Mode is best for chat conversations with the AI. Instruct mode is for giving the AI ChatGPT-styled tasks.</span></span></div>
|
||||
<div style="margin:0px 0 0 auto;">
|
||||
<select title="Usage Mode Selection" class="form-control" id="opmode" onchange="toggle_opmode()">
|
||||
<option value="4">Instruct Mode</option>
|
||||
|
|
@ -29653,7 +29691,7 @@ Current version indicated by LITEVER below.
|
|||
</div>
|
||||
<div class="settinglabel">
|
||||
<div class="justifyleft">Separate end tags <span class="helpicon">?<span
|
||||
class="helptext">Allows using separate Instruction and Response End Tags, instead of combing them with the start tag. Don't change this halfway through a story!</span></span></div>
|
||||
class="helptext">Allows using separate Instruction and Response End Tags, instead of combining them with the start tag. Don't change this halfway through a story!</span></span></div>
|
||||
<input type="checkbox" title="Separate End Tags" id="separate_end_tags" class="push-right" onchange="toggle_separate_end_tags()">
|
||||
</div>
|
||||
<div class="settinglabel">
|
||||
|
|
@ -29682,12 +29720,12 @@ Current version indicated by LITEVER below.
|
|||
</div>
|
||||
</div>
|
||||
<div class="settinglabel">
|
||||
<div class="justifyleft">Allow continue user turns <span class="helpicon">?<span
|
||||
<div class="justifyleft">Allow continuing user turns <span class="helpicon">?<span
|
||||
class="helptext">In instruct mode, allows the AI to continue generating the user's turn when pressing Generate More.</span></span></div>
|
||||
<input title="Legacy Savefile" type="checkbox" id="allow_continue_user_turn" class="push-right">
|
||||
</div>
|
||||
<div class="settinglabel">
|
||||
<div class="justifyleft">Allow continue AI replies <span class="helpicon">?<span
|
||||
<div class="justifyleft">Allow continuing AI replies <span class="helpicon">?<span
|
||||
class="helptext">Allow the AI to continue incomplete past responses, which can be extended by pressing submit again. Not recommended for newbies.</span></span></div>
|
||||
<input type="checkbox" title="Continue Bot Replies" id="allow_continue_chat" class="push-right">
|
||||
</div>
|
||||
|
|
@ -29807,23 +29845,23 @@ Current version indicated by LITEVER below.
|
|||
</div>
|
||||
</div>
|
||||
<div class="settinglabel">
|
||||
<div class="justifyleft">Enable markdown <span class="helpicon">?<span
|
||||
class="helptext">Allows the UI to use markdown formatting such as quotes and code blocks.</span></span></div>
|
||||
<div class="justifyleft">Enable Markdown <span class="helpicon">?<span
|
||||
class="helptext">Allows the UI to use Markdown formatting, such as quotes and code blocks.</span></span></div>
|
||||
<input type="checkbox" title="Enabled Markdown" id="instruct_has_markdown" class="push-right">
|
||||
</div>
|
||||
<div class="settinglabel">
|
||||
<div class="justifyleft">Render markdown while streaming <span class="helpicon">?<span
|
||||
class="helptext">Attempt to render markdown when streaming. May result in wonky output or lag on older devices.</span></span></div>
|
||||
<div class="justifyleft">Render Markdown while streaming <span class="helpicon">?<span
|
||||
class="helptext">Attempt to render Markdown when streaming. May result in wonky output or lag on older devices.</span></span></div>
|
||||
<input title="Show Local Endpoint Selector" type="checkbox" id="render_streaming_markdown" class="push-right">
|
||||
</div>
|
||||
<div class="settinglabel">
|
||||
<div class="justifyleft">Enable LaTeX <span class="helpicon">?<span
|
||||
class="helptext">Allows the UI to render LaTeX within markdown formatting (Needs Markdown).</span></span></div>
|
||||
class="helptext">Allows the UI to render LaTeX within Markdown formatting (Needs Markdown).</span></span></div>
|
||||
<input type="checkbox" title="Enable LaTeX (Needs Markdown)" id="instruct_has_latex" class="push-right">
|
||||
</div>
|
||||
<div class="settinglabel">
|
||||
<div class="justifyleft">Show Nametags <span class="helpicon">?<span
|
||||
class="helptext">Controls if user and AI nametags are shown or hidden. Recommended.</span></span></div>
|
||||
class="helptext">Controls whether user and AI nametags are shown or hidden. Recommended.</span></span></div>
|
||||
<input title="Show Nametags" type="checkbox" id="show_nametags" class="push-right">
|
||||
</div>
|
||||
<div class="settinglabel">
|
||||
|
|
@ -29851,7 +29889,7 @@ Current version indicated by LITEVER below.
|
|||
</div>
|
||||
<div class="settinglabel">
|
||||
<div class="justifyleft">Max Displayed Text Characters <span class="helpicon">?<span
|
||||
class="helptext">If set above 0, will limit the number of text characters rendered to display (any earlier text will still be submitted but stay hidden).</span></span></div>
|
||||
class="helptext">If set above 0, will limit the number of text characters rendered to display. (Any earlier text will still be submitted but stay hidden.)</span></span></div>
|
||||
<input class="push-right" title="Max Displayed Text Characters" type="text" inputmode="decimal" value="0" style="width:10ch" id="max_display_chars">
|
||||
</div>
|
||||
<div class="settinglabel">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue