diff --git a/public/scripts/PromptManager.js b/public/scripts/PromptManager.js index e3d5cf8f1..c6b8aecd9 100644 --- a/public/scripts/PromptManager.js +++ b/public/scripts/PromptManager.js @@ -1,5 +1,5 @@ import {DraggablePromptListModule as DraggableList} from "./DraggableList.js"; -import {eventSource, substituteParams} from "../script.js"; +import {event_types, eventSource, substituteParams} from "../script.js"; import {IdentifierNotFoundError, TokenHandler} from "./openai.js"; class Prompt { @@ -35,6 +35,14 @@ class PromptCollection { this.collection.push(...prompts); } + set(prompt, position) { + if(!(prompt instanceof Prompt)) { + throw new Error('Only Prompt instances can be added to PromptCollection'); + } + + this.collection[position] = prompt; + } + get(identifier) { const index = this.index(identifier); if (0 > index) return null; @@ -66,6 +74,9 @@ function PromptManagerModule() { this.tokenHandler = null; this.error = null; + this.tryGenerate = () => { }; + this.saveServiceSettings = () => { }; + this.handleToggle = () => { }; this.handleEdit = () => { }; this.handleDetach = () => { }; @@ -73,8 +84,6 @@ function PromptManagerModule() { this.handleNewPrompt = () => { }; this.handleDeletePrompt = () => { }; this.handleAppendPrompt = () => { }; - this.saveServiceSettings = () => { }; - this.tryGenerate = () => { }; this.handleAdvancedSettingsToggle = () => { }; } @@ -193,6 +202,24 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti this.saveServiceSettings().then(() => this.render()); }); + // Apply character specific overrides for prompts + eventSource.on(event_types.OAI_BEFORE_CHATCOMPLETION, (prompts) => { + const systemPromptOverride = this.activeCharacter.data.system_prompt ?? null; + if (systemPromptOverride) { + const override = prompts.get('main'); + override.content = systemPromptOverride; + prompts.set(override, prompts.index('main')); + } + + const jailbreakPromptOverride = this.activeCharacter.data.system_prompt ?? null; + if (jailbreakPromptOverride) { + const override = prompts.get('jailbreak'); + override.content = jailbreakPromptOverride; + prompts.set(override, prompts.index('jailbreak')); + } + }); + + // Trigger re-render when token settings are changed document.getElementById('openai_max_context').addEventListener('change', (event) => { if (this.activeCharacter) this.render(); }); diff --git a/public/scripts/openai.js b/public/scripts/openai.js index 2bdbf14ae..b8b0c507f 100644 --- a/public/scripts/openai.js +++ b/public/scripts/openai.js @@ -575,6 +575,7 @@ async function prepareOpenAIMessages({ try { populateChatCompletion(prompts, chatCompletion, {bias, quietPrompt, type}); } catch (error) { + toastr.error('An error occurred while counting tokens.') if (error instanceof TokenBudgetExceededError) { chatCompletion.log('Token budget exceeded.'); promptManager.error = 'Not enough free tokens for mandatory prompts. Raise your token Limit or disable custom prompts.'; diff --git a/public/style.css b/public/style.css index e1f211f27..e7b74384f 100644 --- a/public/style.css +++ b/public/style.css @@ -208,6 +208,18 @@ table.responsiveTable { padding: 0.25em; } +.text_warning { + color: var(--orangered); +} + +.text_danger { + color: var(--fullred); +} + +.tooltip { + cursor: help; +} + .mes_text p { margin-top: 0; margin-bottom: 10px; @@ -5491,3 +5503,4 @@ body.waifuMode .zoomed_avatar { line-height: 14px; } +