Fix for chat completion prompts
This commit is contained in:
parent
014ef0cc4f
commit
792c077267
|
@ -45,6 +45,7 @@ module.exports = {
|
|||
Readability: 'readonly',
|
||||
isProbablyReaderable: 'readonly',
|
||||
ePub: 'readonly',
|
||||
diff_match_patch: 'readonly',
|
||||
},
|
||||
},
|
||||
],
|
||||
|
|
|
@ -4927,35 +4927,39 @@ async function promptItemize(itemizedPrompts, requestedMesId) {
|
|||
}
|
||||
|
||||
const params = await itemizedParams(itemizedPrompts, thisPromptSet);
|
||||
const flatten = (rawPrompt) => Array.isArray(rawPrompt) ? rawPrompt.map(x => x.content).join('\n') : rawPrompt;
|
||||
|
||||
const template = params.this_main_api == 'openai'
|
||||
? await renderTemplateAsync('itemizationChat', params)
|
||||
: await renderTemplateAsync('itemizationText', params);
|
||||
|
||||
const popup = new Popup(template, POPUP_TYPE.TEXT);
|
||||
|
||||
/** @type {HTMLElement} */
|
||||
const diffPrevPrompt = popup.dlg.querySelector('#diffPrevPrompt');
|
||||
if (priorPromptArrayItemForRawPromptDisplay) {
|
||||
popup.dlg.querySelector('#diffPrevPrompt').style.display='';
|
||||
popup.dlg.querySelector('#diffPrevPrompt').addEventListener('click', function () {
|
||||
var dmp = new diff_match_patch();
|
||||
var text1 = itemizedPrompts[priorPromptArrayItemForRawPromptDisplay].rawPrompt;
|
||||
var text2 = itemizedPrompts[PromptArrayItemForRawPromptDisplay].rawPrompt;
|
||||
diffPrevPrompt.style.display = '';
|
||||
diffPrevPrompt.addEventListener('click', function () {
|
||||
const dmp = new diff_match_patch();
|
||||
const text1 = flatten(itemizedPrompts[priorPromptArrayItemForRawPromptDisplay].rawPrompt);
|
||||
const text2 = flatten(itemizedPrompts[PromptArrayItemForRawPromptDisplay].rawPrompt);
|
||||
|
||||
dmp.Diff_Timeout = 2.0;
|
||||
|
||||
var d = dmp.diff_main(text1, text2);
|
||||
var ds = dmp.diff_prettyHtml(d);
|
||||
|
||||
const d = dmp.diff_main(text1, text2);
|
||||
let ds = dmp.diff_prettyHtml(d);
|
||||
// make it readable
|
||||
ds = ds.replaceAll("background:#e6ffe6;", "background:#b9f3b9; color:black;");
|
||||
ds = ds.replaceAll("background:#ffe6e6;", "background:#f5b4b4; color:black;");
|
||||
ds = ds.replaceAll("¶", "");
|
||||
ds = "<div style='display:block;'>" + ds + "</div>";
|
||||
ds = ds.replaceAll('background:#e6ffe6;', 'background:#b9f3b9; color:black;');
|
||||
ds = ds.replaceAll('background:#ffe6e6;', 'background:#f5b4b4; color:black;');
|
||||
ds = ds.replaceAll('¶', '');
|
||||
const container = document.createElement('div');
|
||||
container.innerHTML = DOMPurify.sanitize(ds);
|
||||
const rawPromptWrapper = document.getElementById('rawPromptWrapper');
|
||||
rawPromptWrapper.innerHTML = ds;
|
||||
rawPromptWrapper.replaceChildren(container);
|
||||
$('#rawPromptPopup').slideToggle();
|
||||
});
|
||||
} else {
|
||||
popup.dlg.querySelector('#diffPrevPrompt').style.display='none';
|
||||
diffPrevPrompt.style.display = 'none';
|
||||
}
|
||||
popup.dlg.querySelector('#copyPromptToClipboard').addEventListener('click', function () {
|
||||
let rawPrompt = itemizedPrompts[PromptArrayItemForRawPromptDisplay].rawPrompt;
|
||||
|
@ -4975,16 +4979,11 @@ async function promptItemize(itemizedPrompts, requestedMesId) {
|
|||
console.log(itemizedPrompts);
|
||||
console.log(itemizedPrompts[PromptArrayItemForRawPromptDisplay].rawPrompt);
|
||||
|
||||
let rawPrompt = itemizedPrompts[PromptArrayItemForRawPromptDisplay].rawPrompt;
|
||||
let rawPromptValues = rawPrompt;
|
||||
|
||||
if (Array.isArray(rawPrompt)) {
|
||||
rawPromptValues = rawPrompt.map(x => x.content).join('\n');
|
||||
}
|
||||
const rawPrompt = flatten(itemizedPrompts[PromptArrayItemForRawPromptDisplay].rawPrompt);
|
||||
|
||||
//let DisplayStringifiedPrompt = JSON.stringify(itemizedPrompts[PromptArrayItemForRawPromptDisplay].rawPrompt).replace(/\n+/g, '<br>');
|
||||
const rawPromptWrapper = document.getElementById('rawPromptWrapper');
|
||||
rawPromptWrapper.innerText = rawPromptValues;
|
||||
rawPromptWrapper.innerText = rawPrompt;
|
||||
$('#rawPromptPopup').slideToggle();
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue