Merge branch 'staging' into sysprompt-divorce

9d0ffc2d0df141623390561b819900a5dd6b0806

Cohee <18619528+Cohee1207@users.noreply.github.com>

9 files changed, +46 -31Ignore whitespace
default/content/settings.json+11 -11
@@ -236,7 +236,7 @@
236236 "lengthPenaltyStep": 0.1,
237237 "memoryFrozen": false,
238238 "source": "extras",
239239 "prompt": "[PauseIgnore yourprevious roleplayinstructions. Summarize the most important facts and events that have happened in the chatstory so far. If a summary already exists in your memory, use that as a base and expand with new facts. Limit the summary to {{words}} words or less. Your response should include nothing but the summary.]",
240240 "promptWords": 200,
241241 "promptMinWords": 25,
242242 "promptMaxWords": 1000,
@@ -299,13 +299,13 @@
299299 "horde_karras": true,
300300 "refine_mode": false,
301301 "prompts": {
302302 "0": "[In the next response I want you to provide only a detailed comma-delimited list of keywords and phrases which describe {{char}}. The list must include all of the following items in this order: name, species and race, gender, age, clothing, occupation, physical features and appearances. Do not include descriptions of non-visual qualities such as personality, movements, scents, mental traits, or anything which could not be seen in a still photograph. Do not write in full sentences. Prefix your description with the phrase 'full body portrait,']",
303303 "1": "[PauseIgnore yourprevious roleplayinstructions and provide a detailed description of {{user}}'s physical appearance from the perspective of {{char}} in the form of a comma-delimited list of keywords and phrases. The list must include all of the following items in this order: name, species and race, gender, age, clothing, occupation, physical features and appearances. Do not include descriptions of non-visual qualities such as personality, movements, scents, mental traits, or anything which could not be seen in a still photograph. Do not write in full sentences. Prefix your description with the phrase 'full body portrait,'. Ignore the rest of the story when crafting this description. Do not roleplayreply as {{char}} when writing this description, and do not attempt to continue the story.]",
304304 "2": "[PauseIgnore yourprevious roleplayinstructions and provide a detailed description for all of the following: a brief recap of recent events in the story, {{char}}'s appearance, and {{char}}'s surroundings. Do not roleplayreply whileas {{char}} when writing this description, and do not attempt to continue the story.]",
305305 "3": "[PauseIgnore yourprevious roleplayinstructions and provide ONLY the last chat message string back to me verbatim. Do not write anything after the string. Do not roleplayreply atas all{{char}} inwhen yourwriting response.this Dodescription, and do not attempt to continue the roleplay story.]",
306- "4": "[Pause your roleplay. Your next response must be formatted as a single comma-delimited list of concise keywords. The list will describe of the visual details included in the last chat message.\n\n Only mention characters by using pronouns ('he','his','she','her','it','its') or neutral nouns ('male', 'the man', 'female', 'the woman').\n\n Ignore non-visible things such as feelings, personality traits, thoughts, and spoken dialog.\n\n Add keywords in this precise order:\n a keyword to describe the location of the scene,\n a keyword to mention how many characters of each gender or type are present in the scene (minimum of two characters:\n {{user}} and {{char}}, example: '2 men ' or '1 man 1 woman ', '1 man 3 robots'),\n\n keywords to describe the relative physical positioning of the characters to each other (if a commonly known term for the positioning is known use it instead of describing the positioning in detail) + 'POV',\n\n a single keyword or phrase to describe the primary act taking place in the last chat message,\n\n keywords to describe {{char}}'s physical appearance and facial expression,\n keywords to describe {{char}}'s actions,\n keywords to describe {{user}}'s physical appearance and actions.\n\n If character actions involve direct physical interaction with another character, mention specifically which body parts interacting and how.\n\n A correctly formatted example response would be:\n '(location),(character list by gender),(primary action), (relative character position) POV, (character 1's description and actions), (character 2's description and actions)']",
306+ "4": "Ignore previous instructions. Your next response must be formatted as a single comma-delimited list of concise keywords. The list will describe of the visual details included in the last chat message.\n\n Only mention characters by using pronouns ('he','his','she','her','it','its') or neutral nouns ('male', 'the man', 'female', 'the woman').\n\n Ignore non-visible things such as feelings, personality traits, thoughts, and spoken dialog.\n\n Add keywords in this precise order:\n a keyword to describe the location of the scene,\n a keyword to mention how many characters of each gender or type are present in the scene (minimum of two characters:\n {{user}} and {{char}}, example: '2 men ' or '1 man 1 woman ', '1 man 3 robots'),\n\n keywords to describe the relative physical positioning of the characters to each other (if a commonly known term for the positioning is known use it instead of describing the positioning in detail) + 'POV',\n\n a single keyword or phrase to describe the primary act taking place in the last chat message,\n\n keywords to describe {{char}}'s physical appearance and facial expression,\n keywords to describe {{char}}'s actions,\n keywords to describe {{user}}'s physical appearance and actions.\n\n If character actions involve direct physical interaction with another character, mention specifically which body parts interacting and how.\n\n A correctly formatted example response would be:\n '(location),(character list by gender),(primary action), (relative character position) POV, (character 1's description and actions), (character 2's description and actions)'",
307307 "5": "[In the next response I want you to provide only a detailed comma-delimited list of keywords and phrases which describe {{char}}. The list must include all of the following items in this order: name, species and race, gender, age, facial features and expressions, occupation, hair and hair accessories (if any), what they are wearing on their upper body (if anything). Do not describe anything below their neck. Do not include descriptions of non-visual qualities such as personality, movements, scents, mental traits, or anything which could not be seen in a still photograph. Do not write in full sentences. Prefix your description with the phrase 'close up facial portrait,']",
308308 "7": "[PauseIgnore yourprevious roleplayinstructions and provide a detailed description of {{char}}'s surroundings in the form of a comma-delimited list of keywords and phrases. The list must include all of the following items in this order: location, time of day, weather, lighting, and any other relevant details. Do not include descriptions of characters and non-visual qualities such as names, personality, movements, scents, mental traits, or anything which could not be seen in a still photograph. Do not write in full sentences. Prefix your description with the phrase 'background,'. Ignore the rest of the story when crafting this description. Do not roleplayreply as {{user}} when writing this description, and do not attempt to continue the story.]"
309309 },
310310 "character_prompts": {}
311311 },
@@ -319,9 +319,9 @@
319319 "objective": {
320320 "customPrompts": {
321321 "default": {
322322 "createTask": "PauseIgnore yourprevious roleplayinstructions and generate a list of tasks to complete an objective. Your next response must be formatted as a numbered list of plain text entries. Do not include anything but the numbered list. The list must be prioritized in the order that tasks must be completed.\n\nThe objective that you must make a numbered task list for is: [{{objective}}].\nThe tasks created should take into account the character traits of {{char}}. These tasks may or may not involve {{user}} directly. Be sure to include the objective as the final task.\n\nGiven an example objective of 'Make me a four course dinner', here is an example output:\n1. Determine what the courses will be\n2. Find recipes for each course\n3. Go shopping for supplies with {{user}}\n4. Cook the food\n5. Get {{user}} to set the table\n6. Serve the food\n7. Enjoy eating the meal with {{user}}\n ",
323323 "checkTaskCompleted": "PauseIgnore yourprevious roleplayinstructions. Determine if this task is completed: [{{task}}].\nTo do this, examine the most recent messages. Your response must only contain either true or false, nothing other words.\nExample output:\ntrue\n ",
324324 "currentTask": "Your current task is [{{task}}]. Balance existing roleplaystory with completing this task."
325325 }
326326 }
327327 },
public/script.js+9 -1
@@ -211,7 +211,7 @@ import {
211211 selectContextPreset,
212212} from './scripts/instruct-mode.js';
213213import { initLocales, t, translate } from './scripts/i18n.js';
214214import { getFriendlyTokenizerName, getTokenCount, getTokenCountAsync, getTokenizerModel, initTokenizers, saveTokenCache, TOKENIZER_SUPPORTED_KEY } from './scripts/tokenizers.js';
215215import {
216216 user_avatar,
217217 getUserAvatars,
@@ -413,6 +413,7 @@ export const event_types = {
413413 MESSAGE_FILE_EMBEDDED: 'message_file_embedded',
414414 IMPERSONATE_READY: 'impersonate_ready',
415415 CHAT_CHANGED: 'chat_id_changed',
416+ GENERATION_ENTERED: 'generation_entered',
416417 GENERATION_STARTED: 'generation_started',
417418 GENERATION_STOPPED: 'generation_stopped',
418419 GENERATION_ENDED: 'generation_ended',
@@ -1217,6 +1218,9 @@ async function getStatusTextgen() {
12171218 // Determine instruct mode preset
12181219 autoSelectInstructPreset(online_status);
12191220
1221+ const supportsTokenization = response.headers.get('x-supports-tokenization') === 'true';
1222+ supportsTokenization ? sessionStorage.setItem(TOKENIZER_SUPPORTED_KEY, 'true') : sessionStorage.removeItem(TOKENIZER_SUPPORTED_KEY);
1223+
12201224 // We didn't get a 200 status code, but the endpoint has an explanation. Which means it DID connect, but I digress.
12211225 if (online_status === 'no_connection' && data.response) {
12221226 toastr.error(data.response, 'API Error', { timeOut: 5000, preventDuplicates: true });
@@ -3341,6 +3345,9 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
33413345 setGenerationProgress(0);
33423346 generation_started = new Date();
33433347
3348+ // Occurs every time, even if the generation is aborted due to slash commands execution
3349+ await eventSource.emit(event_types.GENERATION_ENTERED, type, { automatic_trigger, force_name2, quiet_prompt, quietToLoud, skipWIAN, force_chid, signal, quietImage }, dryRun);
3350+
33443351 // Don't recreate abort controller if signal is passed
33453352 if (!(abortController && signal)) {
33463353 abortController = new AbortController();
@@ -3360,6 +3367,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
33603367 }
33613368 }
33623369
3370+ // Occurs only if the generation is not aborted due to slash commands execution
33633371 await eventSource.emit(event_types.GENERATION_STARTED, type, { automatic_trigger, force_name2, quiet_prompt, quietToLoud, skipWIAN, force_chid, signal, quietImage }, dryRun);
33643372
33653373 if (main_api == 'kobold' && kai_settings.streaming_kobold && !kai_flags.can_use_streaming) {
public/scripts/backgrounds.js+1 -1
@@ -313,7 +313,7 @@ async function onDeleteBackgroundClick(e) {
313313 }
314314}
315315
316316const autoBgPrompt = 'PauseIgnore yourprevious roleplayinstructions and choose a location ONLY from the provided list that is the most suitable for the current scene. Do not output any other text:\n{0}';
317317
318318async function autoBackgroundCommand() {
319319 /** @type {HTMLElement[]} */
public/scripts/extensions/expressions/index.js+1 -1
@@ -20,7 +20,7 @@ const STREAMING_UPDATE_INTERVAL = 10000;
2020const TALKINGCHECK_UPDATE_INTERVAL = 500;
2121const DEFAULT_FALLBACK_EXPRESSION = 'joy';
2222const FUNCTION_NAME = 'set_emotion';
2323const DEFAULT_LLM_PROMPT = 'PauseIgnore yourprevious roleplayinstructions. Classify the emotion of the last message. Output just one word, e.g. "joy" or "anger". Choose only one of the following labels: {{labels}}';
2424const DEFAULT_EXPRESSIONS = [
2525 'talkinghead',
2626 'admiration',
public/scripts/extensions/memory/index.js+1 -1
@@ -102,7 +102,7 @@ const prompt_builders = {
102102 RAW_NON_BLOCKING: 2,
103103};
104104
105105const defaultPrompt = '[PauseIgnore yourprevious roleplayinstructions. Summarize the most important facts and events in the story so far. If a summary already exists in your memory, use that as a base and expand with new facts. Limit the summary to {{words}} words or less. Your response should include nothing but the summary.]';
106106const defaultTemplate = '[Summary: {{summary}}]';
107107
108108const defaultSettings = {
public/scripts/extensions/stable-diffusion/index.js+6 -7
@@ -125,15 +125,14 @@ const messageTrigger = {
125125const promptTemplates = {
126126 // Not really a prompt template, rather an outcome message template
127127 [generationMode.MESSAGE]: '[{{char}} sends a picture that contains: {{prompt}}].',
128- /*OLD: [generationMode.CHARACTER]: "Pause your roleplay and provide comma-delimited list of phrases and keywords which describe {{char}}'s physical appearance and clothing. Ignore {{char}}'s personality traits, and chat history when crafting this description. End your response once the comma-delimited list is complete. Do not roleplay when writing this description, and do not attempt to continue the story.", */
129128 [generationMode.CHARACTER]: 'In the next response I want you to provide only a detailed comma-delimited list of keywords and phrases which describe {{char}}. The list must include all of the following items in this order: name, species and race, gender, age, clothing, occupation, physical features and appearances. Do not include descriptions of non-visual qualities such as personality, movements, scents, mental traits, or anything which could not be seen in a still photograph. Do not write in full sentences. Prefix your description with the phrase \'full body portrait,\'',
130129 //face-specific prompt
131130 [generationMode.FACE]: 'In the next response I want you to provide only a detailed comma-delimited list of keywords and phrases which describe {{char}}. The list must include all of the following items in this order: name, species and race, gender, age, facial features and expressions, occupation, hair and hair accessories (if any), what they are wearing on their upper body (if anything). Do not describe anything below their neck. Do not include descriptions of non-visual qualities such as personality, movements, scents, mental traits, or anything which could not be seen in a still photograph. Do not write in full sentences. Prefix your description with the phrase \'close up facial portrait,\'',
132131 //prompt for only the last message
133132 [generationMode.USER]: 'PauseIgnore yourprevious roleplayinstructions and provide a detailed description of {{user}}\'s physical appearance from the perspective of {{char}} in the form of a comma-delimited list of keywords and phrases. The list must include all of the following items in this order: name, species and race, gender, age, clothing, occupation, physical features and appearances. Do not include descriptions of non-visual qualities such as personality, movements, scents, mental traits, or anything which could not be seen in a still photograph. Do not write in full sentences. Prefix your description with the phrase \'full body portrait,\'. Ignore the rest of the story when crafting this description. Do not roleplayreply as {{char}} when writing this description, and do not attempt to continue the story.',
134133 [generationMode.SCENARIO]: 'PauseIgnore yourprevious roleplayinstructions and provide a detailed description for all of the following: a brief recap of recent events in the story, {{char}}\'s appearance, and {{char}}\'s surroundings. Do not roleplayreply as {{char}} while writing this description.',
135134
136135 [generationMode.NOW]: `PauseIgnore yourprevious roleplayinstructions. Your next response must be formatted as a single comma-delimited list of concise keywords. The list will describe of the visual details included in the last chat message.
137136
138137 Only mention characters by using pronouns ('he','his','she','her','it','its') or neutral nouns ('male', 'the man', 'female', 'the woman').
139138
@@ -157,12 +156,12 @@ const promptTemplates = {
157156 A correctly formatted example response would be:
158157 '(location),(character list by gender),(primary action), (relative character position) POV, (character 1's description and actions), (character 2's description and actions)'`,
159158
160159 [generationMode.RAW_LAST]: 'PauseIgnore yourprevious roleplayinstructions and provide ONLY the last chat message string back to me verbatim. Do not write anything after the string. Do not roleplayreply atas all{{char}} inwhen yourwriting response.this Dodescription, and do not attempt to continue the roleplay story.',
161160 [generationMode.BACKGROUND]: 'PauseIgnore yourprevious roleplayinstructions and provide a detailed description of {{char}}\'s surroundings in the form of a comma-delimited list of keywords and phrases. The list must include all of the following items in this order: location, time of day, weather, lighting, and any other relevant details. Do not include descriptions of characters and non-visual qualities such as names, personality, movements, scents, mental traits, or anything which could not be seen in a still photograph. Do not write in full sentences. Prefix your description with the phrase \'background,\'. Ignore the rest of the story when crafting this description. Do not roleplayreply as {{userchar}} when writing this description, and do not attempt to continue the story.',
162161 [generationMode.FACE_MULTIMODAL]: 'Provide an exhaustive comma-separated list of tags describing the appearance of the character on this image in great detail. Start with "close-up portrait".',
163162 [generationMode.CHARACTER_MULTIMODAL]: 'Provide an exhaustive comma-separated list of tags describing the appearance of the character on this image in great detail. Start with "full body portrait".',
164163 [generationMode.USER_MULTIMODAL]: 'Provide an exhaustive comma-separated list of tags describing the appearance of the character on this image in great detail. Start with "full body portrait".',
165164 [generationMode.FREE_EXTENDED]: 'PauseIgnore yourprevious roleplayinstructions and provide an exhaustive comma-separated list of tags describing the appearance of "{0}" in great detail. Start with {{charPrefix}} (sic) if the subject is associated with {{char}}.',
166165};
167166
168167const defaultPrefix = 'best quality, absurdres, aesthetic,';
public/scripts/extensions/vectors/index.js+1 -1
@@ -56,7 +56,7 @@ const settings = {
5656 summarize: false,
5757 summarize_sent: false,
5858 summary_source: 'main',
5959 summary_prompt: 'PauseIgnore yourprevious roleplayinstructions. Summarize the most important parts of the message. Limit yourself to 250 words or less. Your response should include nothing but the summary.',
6060 force_chunk_delimiter: '',
6161
6262 // For chats
public/scripts/tokenizers.js+15 -8
@@ -10,7 +10,8 @@ import { getCurrentDreamGenModelTokenizer, getCurrentOpenRouterModelTokenizer, o
1010const { OOBA, TABBY, KOBOLDCPP, VLLM, APHRODITE, LLAMACPP, OPENROUTER, DREAMGEN } = textgen_types;
1111
1212export const CHARACTERS_PER_TOKEN_RATIO = 3.35;
1313export const TOKENIZER_WARNING_KEY = 'tokenizationWarningShown';
14+export const TOKENIZER_SUPPORTED_KEY = 'tokenizationSupported';
1415
1516export const tokenizers = {
1617 NONE: 0,
@@ -280,8 +281,9 @@ export function getTokenizerBestMatch(forApi) {
280281 // - Kobold must pass a version check
281282 // - Tokenizer haven't reported an error previously
282283 const hasTokenizerError = sessionStorage.getItem(TOKENIZER_WARNING_KEY);
284+ const hasValidEndpoint = sessionStorage.getItem(TOKENIZER_SUPPORTED_KEY);
283285 const isConnected = online_status !== 'no_connection';
284286 const isTokenizerSupported = TEXTGEN_TOKENIZERS.includes(textgen_settings.type) && (textgen_settings.type !== OOBA || hasValidEndpoint);
285287
286288 if (!hasTokenizerError && isConnected) {
287289 if (forApi === 'kobold' && kai_flags.can_use_tokenization) {
@@ -923,15 +925,20 @@ function countTokensFromTextgenAPI(str, resolve) {
923925
924926function apiFailureTokenCount(str) {
925927 console.error('Error counting tokens');
928+ let shouldTryAgain = false;
926929
927930 if (!sessionStorage.getItem(TOKENIZER_WARNING_KEY)) {
928- toastr.warning(
931+ const bestMatchBefore = getTokenizerBestMatch(main_api);
929- 'Your selected API doesn\'t support the tokenization endpoint. Using estimated counts.',
930- 'Error counting tokens',
931- { timeOut: 10000, preventDuplicates: true },
932- );
933-
934932 sessionStorage.setItem(TOKENIZER_WARNING_KEY, String(true));
933+ const bestMatchAfter = getTokenizerBestMatch(main_api);
934+ if ([tokenizers.API_TEXTGENERATIONWEBUI, tokenizers.API_KOBOLD].includes(bestMatchBefore) && bestMatchBefore !== bestMatchAfter) {
935+ shouldTryAgain = true;
936+ }
937+ }
938+
939+ // Only try again if we guarantee not to be looped by the same error
940+ if (shouldTryAgain && power_user.tokenizer === tokenizers.BEST_MATCH) {
941+ return getTokenCount(str);
935942 }
936943
937944 return guesstimate(str);
src/endpoints/backends/text-completions.js+1 -0
@@ -186,6 +186,7 @@ router.post('/status', jsonParser, async function (request, response) {
186186
187187 const modelName = modelInfo?.model_name;
188188 result = modelName || result;
189+ response.setHeader('x-supports-tokenization', 'true');
189190 }
190191 } catch (error) {
191192 console.error(`Failed to get Ooba model info: ${error}`);