refactor: prompt itemization split to multiple functions

This commit is contained in:
Matěj Račinský 2024-04-28 14:09:10 +02:00
parent a73cb9ad3d
commit 754cdc4d58
1 changed files with 36 additions and 23 deletions

View File

@ -293,6 +293,9 @@ export {
isOdd, isOdd,
countOccurrences, countOccurrences,
renderTemplate, renderTemplate,
itemizedPrompts,
findItemizedPromptSet,
itemizedParams,
}; };
/** /**
@ -4601,29 +4604,7 @@ async function DupeChar() {
} }
} }
async function promptItemize(itemizedPrompts, requestedMesId) { async function itemizedParams(itemizedPrompts, thisPromptSet) {
console.log('PROMPT ITEMIZE ENTERED');
var incomingMesId = Number(requestedMesId);
console.debug(`looking for MesId ${incomingMesId}`);
var thisPromptSet = undefined;
for (var i = 0; i < itemizedPrompts.length; i++) {
console.log(`looking for ${incomingMesId} vs ${itemizedPrompts[i].mesId}`);
if (itemizedPrompts[i].mesId === incomingMesId) {
console.log(`found matching mesID ${i}`);
thisPromptSet = i;
PromptArrayItemForRawPromptDisplay = i;
console.log(`wanting to raw display of ArrayItem: ${PromptArrayItemForRawPromptDisplay} which is mesID ${incomingMesId}`);
console.log(itemizedPrompts[thisPromptSet]);
}
}
if (thisPromptSet === undefined) {
console.log(`couldnt find the right mesId. looked for ${incomingMesId}`);
console.log(itemizedPrompts);
return null;
}
const params = { const params = {
charDescriptionTokens: await getTokenCountAsync(itemizedPrompts[thisPromptSet].charDescription), charDescriptionTokens: await getTokenCountAsync(itemizedPrompts[thisPromptSet].charDescription),
charPersonalityTokens: await getTokenCountAsync(itemizedPrompts[thisPromptSet].charPersonality), charPersonalityTokens: await getTokenCountAsync(itemizedPrompts[thisPromptSet].charPersonality),
@ -4722,6 +4703,38 @@ async function promptItemize(itemizedPrompts, requestedMesId) {
params.allAnchorsTokensPercentage = ((params.allAnchorsTokens / (params.totalTokensInPrompt)) * 100).toFixed(2); params.allAnchorsTokensPercentage = ((params.allAnchorsTokens / (params.totalTokensInPrompt)) * 100).toFixed(2);
params.selectedTokenizer = getFriendlyTokenizerName(params.this_main_api).tokenizerName; params.selectedTokenizer = getFriendlyTokenizerName(params.this_main_api).tokenizerName;
} }
return params;
}
function findItemizedPromptSet(itemizedPrompts, incomingMesId) {
var thisPromptSet = undefined;
for (var i = 0; i < itemizedPrompts.length; i++) {
console.log(`looking for ${incomingMesId} vs ${itemizedPrompts[i].mesId}`);
if (itemizedPrompts[i].mesId === incomingMesId) {
console.log(`found matching mesID ${i}`);
thisPromptSet = i;
PromptArrayItemForRawPromptDisplay = i;
console.log(`wanting to raw display of ArrayItem: ${PromptArrayItemForRawPromptDisplay} which is mesID ${incomingMesId}`);
console.log(itemizedPrompts[thisPromptSet]);
}
}
return thisPromptSet;
}
async function promptItemize(itemizedPrompts, requestedMesId) {
console.log('PROMPT ITEMIZE ENTERED');
var incomingMesId = Number(requestedMesId);
console.debug(`looking for MesId ${incomingMesId}`);
var thisPromptSet = findItemizedPromptSet(itemizedPrompts, incomingMesId);
if (thisPromptSet === undefined) {
console.log(`couldnt find the right mesId. looked for ${incomingMesId}`);
console.log(itemizedPrompts);
return null;
}
const params = await itemizedParams(itemizedPrompts, thisPromptSet);
if (params.this_main_api == 'openai') { if (params.this_main_api == 'openai') {
const template = await renderTemplateAsync('itemizationChat', params); const template = await renderTemplateAsync('itemizationChat', params);