mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Swipes and regenerations in groups should be working now
This commit is contained in:
@@ -52,6 +52,7 @@ export {
|
|||||||
substituteParams,
|
substituteParams,
|
||||||
sendSystemMessage,
|
sendSystemMessage,
|
||||||
addOneMessage,
|
addOneMessage,
|
||||||
|
deleteLastMessage,
|
||||||
resetChatState,
|
resetChatState,
|
||||||
select_rm_info,
|
select_rm_info,
|
||||||
setCharacterId,
|
setCharacterId,
|
||||||
@@ -721,6 +722,12 @@ function clearChat() {
|
|||||||
$("#chat").html("");
|
$("#chat").html("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deleteLastMessage() {
|
||||||
|
count_view_mes--;
|
||||||
|
chat.length = chat.length - 1;
|
||||||
|
$('#chat').children('.mes').last().remove();
|
||||||
|
}
|
||||||
|
|
||||||
function messageFormating(mes, ch_name, isSystem, forceAvatar) {
|
function messageFormating(mes, ch_name, isSystem, forceAvatar) {
|
||||||
if (this_chid != undefined && !isSystem)
|
if (this_chid != undefined && !isSystem)
|
||||||
mes = mes.replaceAll("<", "<").replaceAll(">", ">"); //for welcome message
|
mes = mes.replaceAll("<", "<").replaceAll(">", ">"); //for welcome message
|
||||||
@@ -979,7 +986,7 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (selected_group && !is_group_generating) {
|
if (selected_group && !is_group_generating) {
|
||||||
generateGroupWrapper(false);
|
generateGroupWrapper(false, type = type);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1524,7 +1531,7 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length
|
|||||||
|
|
||||||
}
|
}
|
||||||
// clean-up group message from excessive generations
|
// clean-up group message from excessive generations
|
||||||
if (type == 'group_chat' && selected_group) {
|
if (selected_group) {
|
||||||
getMessage = cleanGroupMessage(getMessage);
|
getMessage = cleanGroupMessage(getMessage);
|
||||||
}
|
}
|
||||||
let this_mes_is_name = true;
|
let this_mes_is_name = true;
|
||||||
@@ -1562,7 +1569,7 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length
|
|||||||
getMessage = $.trim(getMessage);
|
getMessage = $.trim(getMessage);
|
||||||
chat[chat.length - 1]['mes'] = getMessage;
|
chat[chat.length - 1]['mes'] = getMessage;
|
||||||
|
|
||||||
if (type === 'group_chat') {
|
if (selected_group) {
|
||||||
console.log('entering chat update for groups');
|
console.log('entering chat update for groups');
|
||||||
let avatarImg = 'img/fluffy.png';
|
let avatarImg = 'img/fluffy.png';
|
||||||
if (characters[this_chid].avatar != 'none') {
|
if (characters[this_chid].avatar != 'none') {
|
||||||
@@ -1576,13 +1583,6 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length
|
|||||||
|
|
||||||
$("#send_but").css("display", "inline");
|
$("#send_but").css("display", "inline");
|
||||||
$("#loading_mes").css("display", "none");
|
$("#loading_mes").css("display", "none");
|
||||||
|
|
||||||
if (type == 'group_chat' && selected_group) {
|
|
||||||
saveGroupChat(selected_group);
|
|
||||||
} /* else {
|
|
||||||
console.log('saving message for non group chat');
|
|
||||||
saveChat();
|
|
||||||
} */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1597,7 +1597,12 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length
|
|||||||
showSwipeButtons();
|
showSwipeButtons();
|
||||||
}
|
}
|
||||||
console.log('/savechat called by /Generate');
|
console.log('/savechat called by /Generate');
|
||||||
|
|
||||||
|
if (selected_group) {
|
||||||
|
saveGroupChat(selected_group);
|
||||||
|
} else {
|
||||||
saveChat();
|
saveChat();
|
||||||
|
}
|
||||||
//let final_message_length = encode(JSON.stringify(getMessage)).length;
|
//let final_message_length = encode(JSON.stringify(getMessage)).length;
|
||||||
//console.log('AI Response: +'+getMessage+ '('+final_message_length+' tokens)');
|
//console.log('AI Response: +'+getMessage+ '('+final_message_length+' tokens)');
|
||||||
|
|
||||||
@@ -2821,11 +2826,14 @@ $(document).ready(function () {
|
|||||||
Generate('swipe');
|
Generate('swipe');
|
||||||
} else {
|
} else {
|
||||||
if (parseInt(chat[chat.length - 1]['swipe_id']) !== chat[chat.length - 1]['swipes'].length) {
|
if (parseInt(chat[chat.length - 1]['swipe_id']) !== chat[chat.length - 1]['swipes'].length) {
|
||||||
|
if (selected_group) {
|
||||||
|
saveGroupChat(selected_group);
|
||||||
|
} else {
|
||||||
saveChat();
|
saveChat();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -2914,8 +2922,12 @@ $(document).ready(function () {
|
|||||||
easing: animation_rm_easing,
|
easing: animation_rm_easing,
|
||||||
queue: false,
|
queue: false,
|
||||||
complete: function () {
|
complete: function () {
|
||||||
|
if (selected_group) {
|
||||||
|
saveGroupChat(selected_group);
|
||||||
|
} else {
|
||||||
saveChat();
|
saveChat();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -3617,12 +3629,12 @@ $(document).ready(function () {
|
|||||||
else if (id == "option_regenerate") {
|
else if (id == "option_regenerate") {
|
||||||
if (is_send_press == false) {
|
if (is_send_press == false) {
|
||||||
//hideSwipeButtons();
|
//hideSwipeButtons();
|
||||||
is_send_press = true;
|
|
||||||
|
|
||||||
if (selected_group) {
|
if (selected_group) {
|
||||||
regenerateGroup();
|
regenerateGroup();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
is_send_press = true;
|
||||||
Generate("regenerate");
|
Generate("regenerate");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -32,6 +32,7 @@ import {
|
|||||||
selectRightMenuWithAnimation,
|
selectRightMenuWithAnimation,
|
||||||
setRightTabSelectedClass,
|
setRightTabSelectedClass,
|
||||||
default_ch_mes,
|
default_ch_mes,
|
||||||
|
deleteLastMessage,
|
||||||
} from "../script.js";
|
} from "../script.js";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@@ -72,7 +73,17 @@ async function _save(group) {
|
|||||||
|
|
||||||
// Group chats
|
// Group chats
|
||||||
async function regenerateGroup() {
|
async function regenerateGroup() {
|
||||||
// placeholder
|
while (chat.length > 0) {
|
||||||
|
const lastMes = chat[chat.length - 1];
|
||||||
|
|
||||||
|
if (lastMes.is_user || lastMes.is_system) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteLastMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
generateGroupWrapper();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getGroupChat(id) {
|
async function getGroupChat(id) {
|
||||||
@@ -237,7 +248,7 @@ function getGroupAvatar(group) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function generateGroupWrapper(by_auto_mode) {
|
async function generateGroupWrapper(by_auto_mode, type=null) {
|
||||||
if (online_status === "no_connection") {
|
if (online_status === "no_connection") {
|
||||||
is_group_generating = false;
|
is_group_generating = false;
|
||||||
setSendButtonState(false);
|
setSendButtonState(false);
|
||||||
@@ -271,26 +282,29 @@ async function generateGroupWrapper(by_auto_mode) {
|
|||||||
$("#chat").append(typingIndicator);
|
$("#chat").append(typingIndicator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const lastMessage = chat[chat.length - 1];
|
||||||
let messagesBefore = chat.length;
|
let messagesBefore = chat.length;
|
||||||
|
let lastMessageText = lastMessage.mes;
|
||||||
let activationText = "";
|
let activationText = "";
|
||||||
if (userInput && userInput.length && !by_auto_mode) {
|
if (userInput && userInput.length && !by_auto_mode) {
|
||||||
activationText = userInput;
|
activationText = userInput;
|
||||||
messagesBefore++;
|
messagesBefore++;
|
||||||
} else {
|
} else {
|
||||||
const lastMessage = chat[chat.length - 1];
|
|
||||||
if (lastMessage && !lastMessage.is_system) {
|
if (lastMessage && !lastMessage.is_system) {
|
||||||
activationText = lastMessage.mes;
|
activationText = lastMessage.mes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const activatedMembers = activateMembers(group.members, activationText);
|
const activatedMembers = type !== "swipe" ? activateMembers(group.members, activationText) : activateSwipe(group.members);
|
||||||
// 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" ? "group_chat" : "swipe";
|
||||||
setCharacterId(chId);
|
setCharacterId(chId);
|
||||||
setCharacterName(characters[chId].name)
|
setCharacterName(characters[chId].name)
|
||||||
|
|
||||||
await Generate("group_chat", by_auto_mode);
|
await Generate(generateType, by_auto_mode);
|
||||||
|
|
||||||
|
if (type !== "swipe") {
|
||||||
// update indicator and scroll down
|
// update indicator and scroll down
|
||||||
typingIndicator
|
typingIndicator
|
||||||
.find(".typing_indicator_name")
|
.find(".typing_indicator_name")
|
||||||
@@ -299,12 +313,18 @@ async function generateGroupWrapper(by_auto_mode) {
|
|||||||
typingIndicator.show(250, function () {
|
typingIndicator.show(250, function () {
|
||||||
typingIndicator.get(0).scrollIntoView({ behavior: "smooth" });
|
typingIndicator.get(0).scrollIntoView({ behavior: "smooth" });
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
// check if message generated already
|
// if not swipe - check if message generated already
|
||||||
if (chat.length == messagesBefore) {
|
if (type !== "swipe" && chat.length == messagesBefore) {
|
||||||
await delay(10);
|
await delay(100);
|
||||||
} else {
|
}
|
||||||
|
// if swipe - see if message changed
|
||||||
|
else if (type === "swipe" && lastMessageText === chat[chat.length - 1].mes) {
|
||||||
|
await delay(100);
|
||||||
|
}
|
||||||
|
else {
|
||||||
messagesBefore++;
|
messagesBefore++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -322,6 +342,15 @@ async function generateGroupWrapper(by_auto_mode) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function activateSwipe(members) {
|
||||||
|
const name = chat[chat.length -1].name;
|
||||||
|
const activatedNames = members.includes(name) ? [name] : [];
|
||||||
|
const memberIds = activatedNames
|
||||||
|
.map((x) => characters.findIndex((y) => y.name === x))
|
||||||
|
.filter((x) => x !== -1);
|
||||||
|
return memberIds;
|
||||||
|
}
|
||||||
|
|
||||||
function activateMembers(members, input) {
|
function activateMembers(members, input) {
|
||||||
let activatedNames = [];
|
let activatedNames = [];
|
||||||
|
|
||||||
|
@@ -748,7 +748,7 @@ img[src*="user-slash-solid.svg"] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.menu_button .svg_icon {
|
.menu_button .svg_icon {
|
||||||
height: 24px;
|
height: 22px;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
margin: 5px;
|
margin: 5px;
|
||||||
filter: invert(1) brightness(75%);
|
filter: invert(1) brightness(75%);
|
||||||
@@ -824,7 +824,7 @@ img[src*="user-slash-solid.svg"] {
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
width: 98%;
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#character_search_bar {
|
#character_search_bar {
|
||||||
|
Reference in New Issue
Block a user