Idle Response / Continuous Generation (#1132)

* Initial idle stuff

* Much closer, can now quietly send as user to get a char response.

* Tweaks

* Better, reset the count of getting a message back, don't send while prompt is waiting.

* Allow selecting who is being prompted

* Comments and cleaup

* Remove char name for the moment (needs something here probably)

* Add random time period and "Always add character's name to prompt" respect

* Tooltips

* Load/unload listeners

* Reduce log spam

* Add inline prompt inclusion

* Add full loud prompting

* Comments

* Fix instruct newline (I think)

* Don't reset count on continue

* add quietToLoud for script.js

* add quietToLoud for slashcommands.js

* Keep instruct directives

* Removed some logging, don't do the Novel formatting if Q2L

* Logspam begone.

* Removed a bit more logging

* Add alignment style

* Reformat files. Add comments

* Reorder extensions

* Fix repeat logic to prompt once then only repeat the number specified

* Make repeat count more clear

---------

Co-authored-by: RossAscends <124905043+RossAscends@users.noreply.github.com>
Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
This commit is contained in:
city-unit
2023-09-17 15:00:10 -04:00
committed by GitHub
parent ef8c347a95
commit 0033090a93
14 changed files with 517 additions and 40 deletions

View File

@ -1862,16 +1862,30 @@ function getStoppingStrings(isImpersonate) {
return result.filter(onlyUnique);
}
// Background prompt generation
export async function generateQuietPrompt(quiet_prompt) {
/**
* Background generation based on the provided prompt.
* @param {string} quiet_prompt Instruction prompt for the AI
* @param {boolean} quietToLoud Whether a message should be sent in a foreground (loud) or background (quiet) mode
* @returns
*/
export async function generateQuietPrompt(quiet_prompt, quietToLoud) {
return await new Promise(
async function promptPromise(resolve, reject) {
try {
await Generate('quiet', { resolve, reject, quiet_prompt, force_name2: true, });
if (quietToLoud === true) {
try {
await Generate('quiet', { resolve, reject, quiet_prompt, quietToLoud: true, force_name2: true, });
}
catch {
reject();
}
}
catch {
reject();
else {
try {
await Generate('quiet', { resolve, reject, quiet_prompt, quietToLoud: false, force_name2: true, });
}
catch {
reject();
}
}
});
}
@ -2289,7 +2303,7 @@ class StreamingProcessor {
}
}
async function Generate(type, { automatic_trigger, force_name2, resolve, reject, quiet_prompt, force_chid, signal } = {}, dryRun = false) {
async function Generate(type, { automatic_trigger, force_name2, resolve, reject, quiet_prompt, quietToLoud, force_chid, signal } = {}, dryRun = false) {
//console.log('Generate entered');
setGenerationProgress(0);
generation_started = new Date();
@ -2371,9 +2385,11 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
}
}
//#########QUIET PROMPT STUFF##############
//this function just gives special care to novel quiet instruction prompts
if (quiet_prompt) {
quiet_prompt = substituteParams(quiet_prompt);
quiet_prompt = main_api == 'novel' ? adjustNovelInstructionPrompt(quiet_prompt) : quiet_prompt;
quiet_prompt = main_api == 'novel' && !quietToLoud ? adjustNovelInstructionPrompt(quiet_prompt) : quiet_prompt;
}
if (true === dryRun ||
@ -2712,9 +2728,14 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
}
function modifyLastPromptLine(lastMesString) {
//#########QUIET PROMPT STUFF PT2##############
// Add quiet generation prompt at depth 0
if (quiet_prompt && quiet_prompt.length) {
// here name1 is forced for all quiet prompts..why?
const name = name1;
//checks if we are in instruct, if so, formats the chat as such, otherwise just adds the quiet prompt
const quietAppend = isInstruct ? formatInstructModeChat(name, quiet_prompt, false, true, '', name1, name2, false) : `\n${quiet_prompt}`;
//This begins to fix quietPrompts (particularly /sysgen) for instruct
@ -2723,14 +2744,24 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
//TODO: respect output_sequence vs last_output_sequence settings
//TODO: decide how to prompt this to clarify who is talking 'Narrator', 'System', etc.
if (isInstruct) {
lastMesString += '\n' + quietAppend + power_user.instruct.output_sequence + '\n';
lastMesString += '\n' + quietAppend; // + power_user.instruct.output_sequence + '\n';
} else {
lastMesString += quietAppend;
}
// Bail out early
return lastMesString;
// Ross: bailing out early prevents quiet prompts from respecting other instruct prompt toggles
// for sysgen, SD, and summary this is desireable as it prevents the AI from responding as char..
// but for idle prompting, we want the flexibility of the other prompt toggles, and to respect them as per settings in the extension
// need a detection for what the quiet prompt is being asked for...
// Bail out early?
if (quietToLoud !== true) {
return lastMesString;
}
}
// Get instruct mode line
if (isInstruct && !isContinue) {
const name = isImpersonate ? name1 : name2;
@ -2752,7 +2783,6 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
if (!lastMesString.endsWith('\n')) {
lastMesString += '\n';
}
lastMesString += `${name2}:`;
}