mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge branch 'dev' of https://github.com/SillyLossy/TavernAI into dev
This commit is contained in:
@@ -38,6 +38,7 @@ import {
|
||||
resetSelectedGroup,
|
||||
select_group_chats,
|
||||
regenerateGroup,
|
||||
group_generation_id,
|
||||
} from "./scripts/group-chats.js";
|
||||
|
||||
import {
|
||||
@@ -2232,6 +2233,7 @@ function saveReply(type, getMessage, this_mes_is_name) {
|
||||
} else {
|
||||
console.log('entering chat update routine for non-swipe post');
|
||||
chat[chat.length] = {};
|
||||
chat[chat.length - 1]['extra'] = {};
|
||||
chat[chat.length - 1]['name'] = name2;
|
||||
chat[chat.length - 1]['is_user'] = false;
|
||||
chat[chat.length - 1]['is_name'] = this_mes_is_name;
|
||||
@@ -2247,6 +2249,7 @@ function saveReply(type, getMessage, this_mes_is_name) {
|
||||
}
|
||||
chat[chat.length - 1]['is_name'] = true;
|
||||
chat[chat.length - 1]['force_avatar'] = avatarImg;
|
||||
chat[chat.length - 1]['extra']['gen_id'] = group_generation_id;
|
||||
}
|
||||
|
||||
saveImageToMessage(img, chat[chat.length - 1]);
|
||||
|
@@ -48,6 +48,7 @@ export {
|
||||
selected_group,
|
||||
is_group_automode_enabled,
|
||||
is_group_generating,
|
||||
group_generation_id,
|
||||
groups,
|
||||
saveGroupChat,
|
||||
generateGroupWrapper,
|
||||
@@ -64,6 +65,7 @@ let is_group_generating = false; // Group generation flag
|
||||
let is_group_automode_enabled = false;
|
||||
let groups = [];
|
||||
let selected_group = null;
|
||||
let group_generation_id = null;
|
||||
|
||||
const group_activation_strategy = {
|
||||
NATURAL: 0,
|
||||
@@ -88,10 +90,18 @@ async function _save(group) {
|
||||
|
||||
// Group chats
|
||||
async function regenerateGroup() {
|
||||
let generationId = getLastMessageGenerationId();
|
||||
|
||||
while (chat.length > 0) {
|
||||
const lastMes = chat[chat.length - 1];
|
||||
const this_generationId = lastMes.extra?.gen_id;
|
||||
|
||||
if (lastMes.is_user || lastMes.is_system) {
|
||||
// for new generations after the update
|
||||
if ((generationId && this_generationId) && generationId !== this_generationId) {
|
||||
break;
|
||||
}
|
||||
// legacy for generations before the update
|
||||
else if (lastMes.is_user || lastMes.is_system) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -130,6 +140,23 @@ async function getGroupChat(id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const mes = getFirstCharacterMessage(character);
|
||||
chat.push(mes);
|
||||
addOneMessage(mes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (group) {
|
||||
let metadata = group.chat_metadata ?? {};
|
||||
updateChatMetadata(metadata, true);
|
||||
}
|
||||
|
||||
await saveGroupChat(id, true);
|
||||
}
|
||||
}
|
||||
|
||||
function getFirstCharacterMessage(character) {
|
||||
const mes = {};
|
||||
mes["is_user"] = false;
|
||||
mes["is_system"] = false;
|
||||
@@ -143,19 +170,7 @@ async function getGroupChat(id) {
|
||||
character.avatar != "none"
|
||||
? getThumbnailUrl('avatar', character.avatar)
|
||||
: default_avatar;
|
||||
chat.push(mes);
|
||||
addOneMessage(mes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (group) {
|
||||
let metadata = group.chat_metadata ?? {};
|
||||
updateChatMetadata(metadata, true);
|
||||
}
|
||||
|
||||
await saveGroupChat(id);
|
||||
}
|
||||
return mes;
|
||||
}
|
||||
|
||||
function resetSelectedGroup() {
|
||||
@@ -163,7 +178,7 @@ function resetSelectedGroup() {
|
||||
is_group_generating = false;
|
||||
}
|
||||
|
||||
async function saveGroupChat(id) {
|
||||
async function saveGroupChat(id, shouldSaveGroup) {
|
||||
const response = await fetch("/savegroupchat", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -173,7 +188,7 @@ async function saveGroupChat(id) {
|
||||
body: JSON.stringify({ id: id, chat: [...chat] }),
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
if (shouldSaveGroup && response.ok) {
|
||||
await editGroup(id);
|
||||
}
|
||||
}
|
||||
@@ -303,6 +318,8 @@ async function generateGroupWrapper(by_auto_mode, type = null) {
|
||||
$("#chat").append(typingIndicator);
|
||||
}
|
||||
|
||||
// id of this specific batch for regeneration purposes
|
||||
group_generation_id = Date.now();
|
||||
const lastMessage = chat[chat.length - 1];
|
||||
let messagesBefore = chat.length;
|
||||
let lastMessageText = lastMessage.mes;
|
||||
@@ -422,6 +439,17 @@ async function generateGroupWrapper(by_auto_mode, type = null) {
|
||||
}
|
||||
}
|
||||
|
||||
function getLastMessageGenerationId() {
|
||||
let generationId = null;
|
||||
if (chat.length > 0) {
|
||||
const lastMes = chat[chat.length - 1];
|
||||
if (!lastMes.is_user && !lastMes.is_system && lastMes.extra) {
|
||||
generationId = lastMes.extra.gen_id;
|
||||
}
|
||||
}
|
||||
return generationId;
|
||||
}
|
||||
|
||||
function activateImpersonate(members) {
|
||||
const randomIndex = Math.floor(Math.random() * members.length);
|
||||
const activatedNames = [members[randomIndex]];
|
||||
|
Reference in New Issue
Block a user