mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Revert async forEach executor
This commit is contained in:
@ -1432,28 +1432,26 @@ class PromptManager {
|
|||||||
|
|
||||||
const { prefix } = this.configuration;
|
const { prefix } = this.configuration;
|
||||||
|
|
||||||
const that = this;
|
|
||||||
|
|
||||||
let listItem = await renderTemplateAsync('promptManagerListHeader', { prefix });
|
let listItem = await renderTemplateAsync('promptManagerListHeader', { prefix });
|
||||||
|
|
||||||
this.getPromptsForCharacter(this.activeCharacter).forEach(async function(prompt) {
|
this.getPromptsForCharacter(this.activeCharacter).forEach(prompt => {
|
||||||
if (!prompt) return;
|
if (!prompt) return;
|
||||||
|
|
||||||
const listEntry = that.getPromptOrderEntry(that.activeCharacter, prompt.identifier);
|
const listEntry = this.getPromptOrderEntry(this.activeCharacter, prompt.identifier);
|
||||||
const enabledClass = listEntry.enabled ? '' : `${prefix}prompt_manager_prompt_disabled`;
|
const enabledClass = listEntry.enabled ? '' : `${prefix}prompt_manager_prompt_disabled`;
|
||||||
const draggableClass = `${prefix}prompt_manager_prompt_draggable`;
|
const draggableClass = `${prefix}prompt_manager_prompt_draggable`;
|
||||||
const markerClass = prompt.marker ? `${prefix}prompt_manager_marker` : '';
|
const markerClass = prompt.marker ? `${prefix}prompt_manager_marker` : '';
|
||||||
const tokens = that.tokenHandler?.getCounts()[prompt.identifier] ?? 0;
|
const tokens = this.tokenHandler?.getCounts()[prompt.identifier] ?? 0;
|
||||||
|
|
||||||
// Warn the user if the chat history goes below certain token thresholds.
|
// Warn the user if the chat history goes below certain token thresholds.
|
||||||
let warningClass = '';
|
let warningClass = '';
|
||||||
let warningTitle = '';
|
let warningTitle = '';
|
||||||
|
|
||||||
const tokenBudget = that.serviceSettings.openai_max_context - that.serviceSettings.openai_max_tokens;
|
const tokenBudget = this.serviceSettings.openai_max_context - this.serviceSettings.openai_max_tokens;
|
||||||
if (that.tokenUsage > tokenBudget * 0.8 &&
|
if (this.tokenUsage > tokenBudget * 0.8 &&
|
||||||
'chatHistory' === prompt.identifier) {
|
'chatHistory' === prompt.identifier) {
|
||||||
const warningThreshold = that.configuration.warningTokenThreshold;
|
const warningThreshold = this.configuration.warningTokenThreshold;
|
||||||
const dangerThreshold = that.configuration.dangerTokenThreshold;
|
const dangerThreshold = this.configuration.dangerTokenThreshold;
|
||||||
|
|
||||||
if (tokens <= dangerThreshold) {
|
if (tokens <= dangerThreshold) {
|
||||||
warningClass = 'fa-solid tooltip fa-triangle-exclamation text_danger';
|
warningClass = 'fa-solid tooltip fa-triangle-exclamation text_danger';
|
||||||
@ -1467,7 +1465,7 @@ class PromptManager {
|
|||||||
const calculatedTokens = tokens ? tokens : '-';
|
const calculatedTokens = tokens ? tokens : '-';
|
||||||
|
|
||||||
let detachSpanHtml = '';
|
let detachSpanHtml = '';
|
||||||
if (that.isPromptDeletionAllowed(prompt)) {
|
if (this.isPromptDeletionAllowed(prompt)) {
|
||||||
detachSpanHtml = `
|
detachSpanHtml = `
|
||||||
<span title="Remove" class="prompt-manager-detach-action caution fa-solid fa-chain-broken"></span>
|
<span title="Remove" class="prompt-manager-detach-action caution fa-solid fa-chain-broken"></span>
|
||||||
`;
|
`;
|
||||||
@ -1476,7 +1474,7 @@ class PromptManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let editSpanHtml = '';
|
let editSpanHtml = '';
|
||||||
if (that.isPromptEditAllowed(prompt)) {
|
if (this.isPromptEditAllowed(prompt)) {
|
||||||
editSpanHtml = `
|
editSpanHtml = `
|
||||||
<span title="edit" class="prompt-manager-edit-action fa-solid fa-pencil"></span>
|
<span title="edit" class="prompt-manager-edit-action fa-solid fa-pencil"></span>
|
||||||
`;
|
`;
|
||||||
@ -1485,7 +1483,7 @@ class PromptManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let toggleSpanHtml = '';
|
let toggleSpanHtml = '';
|
||||||
if (that.isPromptToggleAllowed(prompt)) {
|
if (this.isPromptToggleAllowed(prompt)) {
|
||||||
toggleSpanHtml = `
|
toggleSpanHtml = `
|
||||||
<span class="prompt-manager-toggle-action ${listEntry.enabled ? 'fa-solid fa-toggle-on' : 'fa-solid fa-toggle-off'}"></span>
|
<span class="prompt-manager-toggle-action ${listEntry.enabled ? 'fa-solid fa-toggle-on' : 'fa-solid fa-toggle-off'}"></span>
|
||||||
`;
|
`;
|
||||||
@ -1498,7 +1496,7 @@ class PromptManager {
|
|||||||
const isImportantPrompt = !prompt.marker && prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE && prompt.forbid_overrides;
|
const isImportantPrompt = !prompt.marker && prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE && prompt.forbid_overrides;
|
||||||
const isUserPrompt = !prompt.marker && !prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE;
|
const isUserPrompt = !prompt.marker && !prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE;
|
||||||
const isInjectionPrompt = !prompt.marker && prompt.injection_position === INJECTION_POSITION.ABSOLUTE;
|
const isInjectionPrompt = !prompt.marker && prompt.injection_position === INJECTION_POSITION.ABSOLUTE;
|
||||||
const isOverriddenPrompt = Array.isArray(that.overriddenPrompts) && that.overriddenPrompts.includes(prompt.identifier);
|
const isOverriddenPrompt = Array.isArray(this.overriddenPrompts) && this.overriddenPrompts.includes(prompt.identifier);
|
||||||
const importantClass = isImportantPrompt ? `${prefix}prompt_manager_important` : '';
|
const importantClass = isImportantPrompt ? `${prefix}prompt_manager_important` : '';
|
||||||
listItem += `
|
listItem += `
|
||||||
<li class="${prefix}prompt_manager_prompt ${draggableClass} ${enabledClass} ${markerClass} ${importantClass}" data-pm-identifier="${prompt.identifier}">
|
<li class="${prefix}prompt_manager_prompt ${draggableClass} ${enabledClass} ${markerClass} ${importantClass}" data-pm-identifier="${prompt.identifier}">
|
||||||
@ -1508,7 +1506,7 @@ class PromptManager {
|
|||||||
${isImportantPrompt ? '<span class="fa-fw fa-solid fa-star" title="Important Prompt"></span>' : ''}
|
${isImportantPrompt ? '<span class="fa-fw fa-solid fa-star" title="Important Prompt"></span>' : ''}
|
||||||
${isUserPrompt ? '<span class="fa-fw fa-solid fa-user" title="User Prompt"></span>' : ''}
|
${isUserPrompt ? '<span class="fa-fw fa-solid fa-user" title="User Prompt"></span>' : ''}
|
||||||
${isInjectionPrompt ? '<span class="fa-fw fa-solid fa-syringe" title="In-Chat Injection"></span>' : ''}
|
${isInjectionPrompt ? '<span class="fa-fw fa-solid fa-syringe" title="In-Chat Injection"></span>' : ''}
|
||||||
${that.isPromptInspectionAllowed(prompt) ? `<a class="prompt-manager-inspect-action">${encodedName}</a>` : encodedName}
|
${this.isPromptInspectionAllowed(prompt) ? `<a class="prompt-manager-inspect-action">${encodedName}</a>` : encodedName}
|
||||||
${isInjectionPrompt ? `<small class="prompt-manager-injection-depth">@ ${prompt.injection_depth}</small>` : ''}
|
${isInjectionPrompt ? `<small class="prompt-manager-injection-depth">@ ${prompt.injection_depth}</small>` : ''}
|
||||||
${isOverriddenPrompt ? '<small class="fa-solid fa-address-card prompt-manager-overridden" title="Pulled from a character card"></small>' : ''}
|
${isOverriddenPrompt ? '<small class="fa-solid fa-address-card prompt-manager-overridden" title="Pulled from a character card"></small>' : ''}
|
||||||
</span>
|
</span>
|
||||||
|
Reference in New Issue
Block a user