Skip to content

Commit

Permalink
fixed markdown having styled text
Browse files Browse the repository at this point in the history
  • Loading branch information
Concedo authored and Concedo committed Feb 16, 2024
1 parent 55032c0 commit 5031ee4
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6391,7 +6391,7 @@
{
let isOpenrouter = (document.getElementById("customapidropdown").value==5);
let dropdown = (isOpenrouter?document.getElementById("custom_openrouter_model"):document.getElementById("custom_oai_model"));
let non_completions = (dropdown.value.includes("text-davinci-003") || dropdown.value.includes("text-davinci-002")
let non_completions = (dropdown.value.includes("davinci-002") || dropdown.value.includes("text-davinci-003") || dropdown.value.includes("text-davinci-002")
|| dropdown.value.includes("text-davinci-001") || dropdown.value.includes("gpt-3.5-turbo-instruct") || dropdown.value == "davinci");
if(isOpenrouter || dropdown.selectedIndex==dropdown.options.length-1)
{
Expand Down Expand Up @@ -12503,7 +12503,12 @@
newbodystr += getStreamingText();
} // Add the pending stream if it's needed. This will add any streamed text to a new bubble for the AI.
newbodystr += contextDict.closeTag + '</p></div></div>'; // Lastly, append the closing div so our body's raw form is completed.
if (aestheticInstructUISettings.use_markdown) { // If markdown is enabled, style the content of each bubble as well.
if (aestheticInstructUISettings.use_markdown) {

let md = applyStylizedCodeBlocks(); // apply the code-block styling, if markdown is used.
newbodystr = md[0];
let codestashes = md[1];
// If markdown is enabled, style the content of each bubble as well.
let internalHTMLparts = []; // We'll cache the embedded HTML parts here to keep them intact.
for (let role of aestheticTextStyleRoles) { // ..starting by the "speech" and *actions* for each role.
let styleRole = aestheticInstructUISettings.use_uniform_colors ? 'uniform' : role; // Uniform role is preferred if it's active on the settings.
Expand All @@ -12516,7 +12521,10 @@
});
}
internalHTMLparts.forEach((part, index) => { newbodystr = newbodystr.replace(`<internal_html_${index}>`, part); }); // Bring back the embedded HTML parts.
newbodystr = applyStylizedCodeBlocks(); // Then, apply the code-block styling, if markdown is used.
for(let i=0;i<codestashes.length;++i)
{
newbodystr = newbodystr.replace(`%CodeStash${i}%`,codestashes[i]);
}
}
newbodystr = newbodystr.replace(/\[<\|p\|.+?\|p\|>\]/g, function (m) {
// m here means the whole matched string
Expand Down Expand Up @@ -12557,16 +12565,21 @@
}
function applyStylizedCodeBlocks() {
let blocks = newbodystr.split(/(```[\s\S]*?\n[\s\S]*?```)/g);
let codestashes = [];
for (var i = 0; i < blocks.length; i++) {
if (blocks[i].startsWith('```')) {
blocks[i] = blocks[i].replace(/```[\s\S]*?\n([\s\S]*?)```/g,
function (m,m2) {return `</p><pre style='min-width:80%;white-space:pre-wrap;margin:0px 30px 0px 20px;background-color:${as.code_block_background};color:${as.code_block_foreground}'>${m2.replace(/[“”]/g, "\"")}</pre><p>`});
function (m,m2) {
let idx = codestashes.length;
codestashes.push(`<pre style='min-width:80%;white-space:pre-wrap;margin:0px 30px 0px 20px;background-color:${as.code_block_background};color:${as.code_block_foreground}'>${m2.replace(/[“”]/g, "\"")}</pre>`);
return `</p>%CodeStash${idx}%<p>`
});
}
else {
blocks[i] = blocks[i].replaceAll('```', '`').replaceAll('``', '`').replace(/`(.*?)`/g, function (m,m2) {return `<code style='background-color:black'>${m2.replace(/[“”]/g, "\"")}</code>`;}); //remove fancy quotes too
}
}
return blocks.join('');
return [blocks.join(''),codestashes];
}
function transformInputToAestheticStyle(bodyStr, isPreview) { // Trim unnecessary empty space and new lines, and append * or " to each bubble if start/end sequence ends with * or ", to preserve styling.
bodyStr = bodyStr.replaceAll(you + '\n', you).replaceAll(you + ' ', you).replaceAll(you, style('you') + `${you.endsWith('*') ? '*' : ''}` + `${you.endsWith('"') ? '"' : ''}`);
Expand Down Expand Up @@ -12950,10 +12963,7 @@
Model Choice:<br>
<select style="padding:4px;display:inline;width:calc(100% - 220px)" class="form-control" id="custom_oai_model" onchange="oai_model_change()">
<option value="gpt-3.5-turbo-instruct" selected="selected">gpt-3.5-turbo-instruct</option>
<option value="text-davinci-003">text-davinci-003</option>
<option value="text-davinci-002">text-davinci-002</option>
<option value="text-davinci-001">text-davinci-001</option>
<option value="davinci">davinci</option>
<option value="davinci-002">davinci-002</option>
<option value="gpt-3.5-turbo">gpt-3.5-turbo</option>
<option value="gpt-3.5-turbo-16k">gpt-3.5-turbo-16k</option>
<option value="gpt-4">gpt-4</option>
Expand Down

0 comments on commit 5031ee4

Please sign in to comment.