import { saveSettingsDebounced, systemUserName, hideSwipeButtons, showSwipeButtons, callPopup, getRequestHeaders, event_types, eventSource, appendImageToMessage, generateQuietPrompt, this_chid, } from "../../../script.js"; import { getApiUrl, getContext, extension_settings, doExtrasFetch, modules } from "../../extensions.js"; import { selected_group } from "../../group-chats.js"; import { stringFormat, initScrollHeight, resetScrollHeight, timestampToMoment, getCharaFilename, saveBase64AsFile } from "../../utils.js"; import { humanizedDateTime } from "../../RossAscends-mods.js"; export { MODULE_NAME }; // Wraps a string into monospace font-face span const m = x => `${x}`; // Joins an array of strings with ' / ' const j = a => a.join(' / '); // Wraps a string into paragraph block const p = a => `
${a}
` const MODULE_NAME = 'sd'; const UPDATE_INTERVAL = 1000; const postHeaders = { 'Content-Type': 'application/json', 'Bypass-Tunnel-Reminder': 'bypass', }; const generationMode = { CHARACTER: 0, USER: 1, SCENARIO: 2, RAW_LAST: 3, NOW: 4, FACE: 5, FREE: 6, BACKGROUND: 7, } const modeLabels = { [generationMode.CHARACTER]: 'Character ("Yourself")', [generationMode.FACE]: 'Portrait ("Your Face")', [generationMode.USER]: 'User ("Me")', [generationMode.SCENARIO]: 'Scenario ("The Whole Story")', [generationMode.NOW]: 'Last Message', [generationMode.RAW_LAST]: 'Raw Last Message', [generationMode.BACKGROUND]: 'Background', } const triggerWords = { [generationMode.CHARACTER]: ['you'], [generationMode.USER]: ['me'], [generationMode.SCENARIO]: ['scene'], [generationMode.RAW_LAST]: ['raw_last'], [generationMode.NOW]: ['last'], [generationMode.FACE]: ['face'], [generationMode.BACKGROUND]: ['background'], } const promptTemplates = { /*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.", */ [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,']", //face-specific prompt [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,']", //prompt for only the last message [generationMode.USER]: "[Pause your roleplay 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 roleplay as {{char}} when writing this description, and do not attempt to continue the story.]", [generationMode.SCENARIO]: "[Pause your roleplay 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 roleplay while writing this description.]", [generationMode.NOW]: `[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. Only mention characters by using pronouns ('he','his','she','her','it','its') or neutral nouns ('male', 'the man', 'female', 'the woman'). Ignore non-visible things such as feelings, personality traits, thoughts, and spoken dialog. Add keywords in this precise order: a keyword to describe the location of the scene, a keyword to mention how many characters of each gender or type are present in the scene (minimum of two characters: {{user}} and {{char}}, example: '2 men ' or '1 man 1 woman ', '1 man 3 robots'), 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', a single keyword or phrase to describe the primary act taking place in the last chat message, keywords to describe {{char}}'s physical appearance and facial expression, keywords to describe {{char}}'s actions, keywords to describe {{user}}'s physical appearance and actions. If character actions involve direct physical interaction with another character, mention specifically which body parts interacting and how. A correctly formatted example response would be: '(location),(character list by gender),(primary action), (relative character position) POV, (character 1's description and actions), (character 2's description and actions)']`, [generationMode.RAW_LAST]: "[Pause your roleplay and provide ONLY the last chat message string back to me verbatim. Do not write anything after the string. Do not roleplay at all in your response. Do not continue the roleplay story.]", [generationMode.BACKGROUND]: "[Pause your roleplay 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 roleplay as {{user}} when writing this description, and do not attempt to continue the story.]", } const helpString = [ `${m('(argument)')} – requests SD to make an image. Supported arguments:`, '