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,
|
resetSelectedGroup,
|
||||||
select_group_chats,
|
select_group_chats,
|
||||||
regenerateGroup,
|
regenerateGroup,
|
||||||
|
group_generation_id,
|
||||||
} from "./scripts/group-chats.js";
|
} from "./scripts/group-chats.js";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -2232,6 +2233,7 @@ function saveReply(type, getMessage, this_mes_is_name) {
|
|||||||
} else {
|
} else {
|
||||||
console.log('entering chat update routine for non-swipe post');
|
console.log('entering chat update routine for non-swipe post');
|
||||||
chat[chat.length] = {};
|
chat[chat.length] = {};
|
||||||
|
chat[chat.length - 1]['extra'] = {};
|
||||||
chat[chat.length - 1]['name'] = name2;
|
chat[chat.length - 1]['name'] = name2;
|
||||||
chat[chat.length - 1]['is_user'] = false;
|
chat[chat.length - 1]['is_user'] = false;
|
||||||
chat[chat.length - 1]['is_name'] = this_mes_is_name;
|
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]['is_name'] = true;
|
||||||
chat[chat.length - 1]['force_avatar'] = avatarImg;
|
chat[chat.length - 1]['force_avatar'] = avatarImg;
|
||||||
|
chat[chat.length - 1]['extra']['gen_id'] = group_generation_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
saveImageToMessage(img, chat[chat.length - 1]);
|
saveImageToMessage(img, chat[chat.length - 1]);
|
||||||
|
@@ -48,6 +48,7 @@ export {
|
|||||||
selected_group,
|
selected_group,
|
||||||
is_group_automode_enabled,
|
is_group_automode_enabled,
|
||||||
is_group_generating,
|
is_group_generating,
|
||||||
|
group_generation_id,
|
||||||
groups,
|
groups,
|
||||||
saveGroupChat,
|
saveGroupChat,
|
||||||
generateGroupWrapper,
|
generateGroupWrapper,
|
||||||
@@ -64,6 +65,7 @@ let is_group_generating = false; // Group generation flag
|
|||||||
let is_group_automode_enabled = false;
|
let is_group_automode_enabled = false;
|
||||||
let groups = [];
|
let groups = [];
|
||||||
let selected_group = null;
|
let selected_group = null;
|
||||||
|
let group_generation_id = null;
|
||||||
|
|
||||||
const group_activation_strategy = {
|
const group_activation_strategy = {
|
||||||
NATURAL: 0,
|
NATURAL: 0,
|
||||||
@@ -88,10 +90,18 @@ async function _save(group) {
|
|||||||
|
|
||||||
// Group chats
|
// Group chats
|
||||||
async function regenerateGroup() {
|
async function regenerateGroup() {
|
||||||
|
let generationId = getLastMessageGenerationId();
|
||||||
|
|
||||||
while (chat.length > 0) {
|
while (chat.length > 0) {
|
||||||
const lastMes = chat[chat.length - 1];
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,6 +140,23 @@ async function getGroupChat(id) {
|
|||||||
continue;
|
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 = {};
|
const mes = {};
|
||||||
mes["is_user"] = false;
|
mes["is_user"] = false;
|
||||||
mes["is_system"] = false;
|
mes["is_system"] = false;
|
||||||
@@ -143,19 +170,7 @@ async function getGroupChat(id) {
|
|||||||
character.avatar != "none"
|
character.avatar != "none"
|
||||||
? getThumbnailUrl('avatar', character.avatar)
|
? getThumbnailUrl('avatar', character.avatar)
|
||||||
: default_avatar;
|
: default_avatar;
|
||||||
chat.push(mes);
|
return mes;
|
||||||
addOneMessage(mes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (group) {
|
|
||||||
let metadata = group.chat_metadata ?? {};
|
|
||||||
updateChatMetadata(metadata, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
await saveGroupChat(id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetSelectedGroup() {
|
function resetSelectedGroup() {
|
||||||
@@ -163,7 +178,7 @@ function resetSelectedGroup() {
|
|||||||
is_group_generating = false;
|
is_group_generating = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveGroupChat(id) {
|
async function saveGroupChat(id, shouldSaveGroup) {
|
||||||
const response = await fetch("/savegroupchat", {
|
const response = await fetch("/savegroupchat", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
@@ -173,7 +188,7 @@ async function saveGroupChat(id) {
|
|||||||
body: JSON.stringify({ id: id, chat: [...chat] }),
|
body: JSON.stringify({ id: id, chat: [...chat] }),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.ok) {
|
if (shouldSaveGroup && response.ok) {
|
||||||
await editGroup(id);
|
await editGroup(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -303,6 +318,8 @@ async function generateGroupWrapper(by_auto_mode, type = null) {
|
|||||||
$("#chat").append(typingIndicator);
|
$("#chat").append(typingIndicator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// id of this specific batch for regeneration purposes
|
||||||
|
group_generation_id = Date.now();
|
||||||
const lastMessage = chat[chat.length - 1];
|
const lastMessage = chat[chat.length - 1];
|
||||||
let messagesBefore = chat.length;
|
let messagesBefore = chat.length;
|
||||||
let lastMessageText = lastMessage.mes;
|
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) {
|
function activateImpersonate(members) {
|
||||||
const randomIndex = Math.floor(Math.random() * members.length);
|
const randomIndex = Math.floor(Math.random() * members.length);
|
||||||
const activatedNames = [members[randomIndex]];
|
const activatedNames = [members[randomIndex]];
|
||||||
|
Reference in New Issue
Block a user