mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
SD generation for groups
This commit is contained in:
@ -193,7 +193,7 @@ let converter;
|
|||||||
reloadMarkdownProcessor();
|
reloadMarkdownProcessor();
|
||||||
|
|
||||||
/* let bg_menu_toggle = false; */
|
/* let bg_menu_toggle = false; */
|
||||||
const systemUserName = "SillyTavern System";
|
export const systemUserName = "SillyTavern System";
|
||||||
let default_user_name = "You";
|
let default_user_name = "You";
|
||||||
let name1 = default_user_name;
|
let name1 = default_user_name;
|
||||||
let name2 = "SillyTavern System";
|
let name2 = "SillyTavern System";
|
||||||
@ -1528,7 +1528,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (selected_group && !is_group_generating) {
|
if (selected_group && !is_group_generating) {
|
||||||
generateGroupWrapper(false, type);
|
generateGroupWrapper(false, type, null, { resolve, reject, quiet_prompt });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,10 @@
|
|||||||
import { substituteParams, saveSettingsDebounced } from "../../../script.js";
|
import {
|
||||||
|
substituteParams,
|
||||||
|
saveSettingsDebounced,
|
||||||
|
systemUserName,
|
||||||
|
hideSwipeButtons,
|
||||||
|
showSwipeButtons
|
||||||
|
} from "../../../script.js";
|
||||||
import { getApiUrl, getContext, extension_settings, defaultRequestArgs } from "../../extensions.js";
|
import { getApiUrl, getContext, extension_settings, defaultRequestArgs } from "../../extensions.js";
|
||||||
import { stringFormat } from "../../utils.js";
|
import { stringFormat } from "../../utils.js";
|
||||||
|
|
||||||
@ -6,6 +12,8 @@ import { stringFormat } from "../../utils.js";
|
|||||||
const m = x => `<span class="monospace">${x}</span>`;
|
const m = x => `<span class="monospace">${x}</span>`;
|
||||||
// Joins an array of strings with ' / '
|
// Joins an array of strings with ' / '
|
||||||
const j = a => a.join(' / ');
|
const j = a => a.join(' / ');
|
||||||
|
// Wraps a string into paragraph block
|
||||||
|
const p = a => `<p>${a}</p>`
|
||||||
|
|
||||||
const postHeaders = {
|
const postHeaders = {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@ -26,10 +34,10 @@ const triggerWords = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const quietPrompts = {
|
const quietPrompts = {
|
||||||
[generationMode.CHARACTER]: "Please provide a detailed description of {{char}}'s appearance",
|
[generationMode.CHARACTER]: "[Please provide a detailed description of {{char}}'s appearance]",
|
||||||
[generationMode.USER]: "Please provide a detailed description of {{user}}'s appearance",
|
[generationMode.USER]: "[Please provide a detailed description of {{user}}'s appearance]",
|
||||||
[generationMode.SCENARIO]: 'Please provide a detailed description of your surroundings and what you are doing right now',
|
[generationMode.SCENARIO]: '[Please provide a detailed description of your surroundings and what you are doing right now]',
|
||||||
[generationMode.FREE]: 'Please provide a detailed and vivid description of {0}',
|
[generationMode.FREE]: '[Please provide a detailed and vivid description of {0}]',
|
||||||
}
|
}
|
||||||
|
|
||||||
const helpString = [
|
const helpString = [
|
||||||
@ -234,6 +242,7 @@ async function generatePicture(_, trigger) {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
context.deactivateSendButtons();
|
context.deactivateSendButtons();
|
||||||
|
hideSwipeButtons();
|
||||||
|
|
||||||
const url = new URL(getApiUrl());
|
const url = new URL(getApiUrl());
|
||||||
url.pathname = '/api/image';
|
url.pathname = '/api/image';
|
||||||
@ -258,11 +267,13 @@ async function generatePicture(_, trigger) {
|
|||||||
const base64Image = `data:image/jpeg;base64,${data.image}`;
|
const base64Image = `data:image/jpeg;base64,${data.image}`;
|
||||||
sendMessage(prompt, base64Image);
|
sendMessage(prompt, base64Image);
|
||||||
}
|
}
|
||||||
} catch {
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
throw new Error('SD prompt text generation failed.')
|
throw new Error('SD prompt text generation failed.')
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
context.activateSendButtons();
|
context.activateSendButtons();
|
||||||
|
showSwipeButtons();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,11 +281,12 @@ async function sendMessage(prompt, image) {
|
|||||||
const context = getContext();
|
const context = getContext();
|
||||||
const messageText = `[${context.name2} sends a picture that contains: ${prompt}]`;
|
const messageText = `[${context.name2} sends a picture that contains: ${prompt}]`;
|
||||||
const message = {
|
const message = {
|
||||||
name: context.name2,
|
name: context.groupId ? systemUserName : context.name2,
|
||||||
|
is_system: context.groupId ? true : false,
|
||||||
is_user: false,
|
is_user: false,
|
||||||
is_name: true,
|
is_name: true,
|
||||||
send_date: Date.now(),
|
send_date: Date.now(),
|
||||||
mes: messageText,
|
mes: context.groupId ? p(messageText) : messageText,
|
||||||
extra: {
|
extra: {
|
||||||
image: image,
|
image: image,
|
||||||
title: prompt,
|
title: prompt,
|
||||||
|
@ -375,7 +375,7 @@ function getGroupAvatar(group) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function generateGroupWrapper(by_auto_mode, type = null, force_chid = null) {
|
async function generateGroupWrapper(by_auto_mode, type = null, force_chid = null, params = {}) {
|
||||||
if (online_status === "no_connection") {
|
if (online_status === "no_connection") {
|
||||||
is_group_generating = false;
|
is_group_generating = false;
|
||||||
setSendButtonState(false);
|
setSendButtonState(false);
|
||||||
@ -423,6 +423,7 @@ async function generateGroupWrapper(by_auto_mode, type = null, force_chid = null
|
|||||||
let lastMessageText = lastMessage.mes;
|
let lastMessageText = lastMessage.mes;
|
||||||
let activationText = "";
|
let activationText = "";
|
||||||
let isUserInput = false;
|
let isUserInput = false;
|
||||||
|
let isQuietGenDone = false;
|
||||||
|
|
||||||
if (userInput && userInput.length && !by_auto_mode) {
|
if (userInput && userInput.length && !by_auto_mode) {
|
||||||
isUserInput = true;
|
isUserInput = true;
|
||||||
@ -439,6 +440,23 @@ async function generateGroupWrapper(by_auto_mode, type = null, force_chid = null
|
|||||||
|
|
||||||
if (typeof force_chid == 'number') {
|
if (typeof force_chid == 'number') {
|
||||||
activatedMembers = [force_chid];
|
activatedMembers = [force_chid];
|
||||||
|
} else if (type === "quiet") {
|
||||||
|
activatedMembers = activateSwipe(group.members);
|
||||||
|
|
||||||
|
if (activatedMembers.length === 0) {
|
||||||
|
activatedMembers = activateListOrder(group.members.slice(0, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
const resolveOriginal = params.resolve;
|
||||||
|
const rejectOriginal = params.reject;
|
||||||
|
params.resolve = function() {
|
||||||
|
isQuietGenDone = true;
|
||||||
|
resolveOriginal.apply(this, arguments);
|
||||||
|
};
|
||||||
|
params.reject = function() {
|
||||||
|
isQuietGenDone = true;
|
||||||
|
rejectOriginal.apply(this, arguments);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (type === "swipe") {
|
else if (type === "swipe") {
|
||||||
activatedMembers = activateSwipe(group.members);
|
activatedMembers = activateSwipe(group.members);
|
||||||
@ -461,11 +479,11 @@ async function generateGroupWrapper(by_auto_mode, type = null, force_chid = null
|
|||||||
|
|
||||||
// now the real generation begins: cycle through every character
|
// now the real generation begins: cycle through every character
|
||||||
for (const chId of activatedMembers) {
|
for (const chId of activatedMembers) {
|
||||||
const generateType = type == "swipe" || type == "impersonate" ? type : "group_chat";
|
const generateType = type == "swipe" || type == "impersonate" || type == "quiet" ? type : "group_chat";
|
||||||
setCharacterId(chId);
|
setCharacterId(chId);
|
||||||
setCharacterName(characters[chId].name)
|
setCharacterName(characters[chId].name)
|
||||||
|
|
||||||
await Generate(generateType, { automatic_trigger: by_auto_mode });
|
await Generate(generateType, { automatic_trigger: by_auto_mode, ...(params || {}) });
|
||||||
|
|
||||||
if (type !== "swipe" && type !== "impersonate") {
|
if (type !== "swipe" && type !== "impersonate") {
|
||||||
// update indicator and scroll down
|
// update indicator and scroll down
|
||||||
@ -520,6 +538,13 @@ async function generateGroupWrapper(by_auto_mode, type = null, force_chid = null
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (type === 'quiet') {
|
||||||
|
if (isQuietGenDone) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
await delay(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
messagesBefore++;
|
messagesBefore++;
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user