From 86a486be8fb34d5329ce5e94b5e247db808b29db Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Thu, 17 Aug 2023 17:40:38 +0300 Subject: [PATCH] Adjust Novel instruction prompts for quiet generation --- public/script.js | 5 +++++ public/scripts/nai-settings.js | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/public/script.js b/public/script.js index dbd823e87..9c83563a9 100644 --- a/public/script.js +++ b/public/script.js @@ -104,6 +104,7 @@ import { loadNovelSettings, nai_settings, setNovelData, + adjustNovelInstructionPrompt, } from "./scripts/nai-settings.js"; import { @@ -2320,6 +2321,10 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject, abortController = new AbortController(); } + if (main_api == 'novel' && quiet_prompt) { + quiet_prompt = adjustNovelInstructionPrompt(quiet_prompt); + } + // OpenAI doesn't need instruct mode. Use OAI main prompt instead. const isInstruct = power_user.instruct.enabled && main_api !== 'openai'; const isImpersonate = type == "impersonate"; diff --git a/public/scripts/nai-settings.js b/public/scripts/nai-settings.js index 98284e786..a41daab06 100644 --- a/public/scripts/nai-settings.js +++ b/public/scripts/nai-settings.js @@ -572,6 +572,18 @@ function calculateLogitBias() { })); } +/** + * Transforms instruction into compatible format for Novel AI. + * 1. Instruction must begin and end with curly braces followed and preceded by a space. + * 2. Instruction must not contain square brackets as it serves different purpose in NAI. + * @param {string} prompt Original instruction prompt + * @returns Processed prompt + */ +export function adjustNovelInstructionPrompt(prompt) { + const stripedPrompt = prompt.replace(/[\[\]]/g, '').trim(); + return `{ ${stripedPrompt} }`; +} + export async function generateNovelWithStreaming(generate_data, signal) { const response = await fetch('/generate_novelai', { headers: getRequestHeaders(),