Swipes and regenerations in groups should be working now

This commit is contained in:
SillyLossy
2023-03-18 21:55:10 +02:00
parent 0fe838223f
commit bf5b2a5c40
3 changed files with 75 additions and 34 deletions

View File

@@ -52,6 +52,7 @@ export {
substituteParams,
sendSystemMessage,
addOneMessage,
deleteLastMessage,
resetChatState,
select_rm_info,
setCharacterId,
@@ -721,6 +722,12 @@ function clearChat() {
$("#chat").html("");
}
function deleteLastMessage() {
count_view_mes--;
chat.length = chat.length - 1;
$('#chat').children('.mes').last().remove();
}
function messageFormating(mes, ch_name, isSystem, forceAvatar) {
if (this_chid != undefined && !isSystem)
mes = mes.replaceAll("<", "&lt;").replaceAll(">", "&gt;"); //for welcome message
@@ -979,7 +986,7 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length
}
if (selected_group && !is_group_generating) {
generateGroupWrapper(false);
generateGroupWrapper(false, type = type);
return;
}
@@ -1524,7 +1531,7 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length
}
// clean-up group message from excessive generations
if (type == 'group_chat' && selected_group) {
if (selected_group) {
getMessage = cleanGroupMessage(getMessage);
}
let this_mes_is_name = true;
@@ -1562,7 +1569,7 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length
getMessage = $.trim(getMessage);
chat[chat.length - 1]['mes'] = getMessage;
if (type === 'group_chat') {
if (selected_group) {
console.log('entering chat update for groups');
let avatarImg = 'img/fluffy.png';
if (characters[this_chid].avatar != 'none') {
@@ -1576,13 +1583,6 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length
$("#send_but").css("display", "inline");
$("#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();
}
console.log('/savechat called by /Generate');
saveChat();
if (selected_group) {
saveGroupChat(selected_group);
} else {
saveChat();
}
//let final_message_length = encode(JSON.stringify(getMessage)).length;
//console.log('AI Response: +'+getMessage+ '('+final_message_length+' tokens)');
@@ -2821,8 +2826,11 @@ $(document).ready(function () {
Generate('swipe');
} else {
if (parseInt(chat[chat.length - 1]['swipe_id']) !== chat[chat.length - 1]['swipes'].length) {
saveChat();
if (selected_group) {
saveGroupChat(selected_group);
} else {
saveChat();
}
}
}
}
@@ -2914,7 +2922,11 @@ $(document).ready(function () {
easing: animation_rm_easing,
queue: false,
complete: function () {
saveChat();
if (selected_group) {
saveGroupChat(selected_group);
} else {
saveChat();
}
}
});
}
@@ -3617,12 +3629,12 @@ $(document).ready(function () {
else if (id == "option_regenerate") {
if (is_send_press == false) {
//hideSwipeButtons();
is_send_press = true;
if (selected_group) {
regenerateGroup();
}
else {
is_send_press = true;
Generate("regenerate");
}
}

View File

@@ -32,6 +32,7 @@ import {
selectRightMenuWithAnimation,
setRightTabSelectedClass,
default_ch_mes,
deleteLastMessage,
} from "../script.js";
export {
@@ -72,7 +73,17 @@ async function _save(group) {
// Group chats
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) {
@@ -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") {
is_group_generating = false;
setSendButtonState(false);
@@ -271,40 +282,49 @@ async function generateGroupWrapper(by_auto_mode) {
$("#chat").append(typingIndicator);
}
const lastMessage = chat[chat.length - 1];
let messagesBefore = chat.length;
let lastMessageText = lastMessage.mes;
let activationText = "";
if (userInput && userInput.length && !by_auto_mode) {
activationText = userInput;
messagesBefore++;
} else {
const lastMessage = chat[chat.length - 1];
if (lastMessage && !lastMessage.is_system) {
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
for (const chId of activatedMembers) {
const generateType = type !== "swipe" ? "group_chat" : "swipe";
setCharacterId(chId);
setCharacterName(characters[chId].name)
await Generate("group_chat", by_auto_mode);
await Generate(generateType, by_auto_mode);
// update indicator and scroll down
typingIndicator
.find(".typing_indicator_name")
.text(characters[chId].name);
$("#chat").append(typingIndicator);
typingIndicator.show(250, function () {
typingIndicator.get(0).scrollIntoView({ behavior: "smooth" });
});
if (type !== "swipe") {
// update indicator and scroll down
typingIndicator
.find(".typing_indicator_name")
.text(characters[chId].name);
$("#chat").append(typingIndicator);
typingIndicator.show(250, function () {
typingIndicator.get(0).scrollIntoView({ behavior: "smooth" });
});
}
while (true) {
// check if message generated already
if (chat.length == messagesBefore) {
await delay(10);
} else {
// if not swipe - check if message generated already
if (type !== "swipe" && chat.length == messagesBefore) {
await delay(100);
}
// if swipe - see if message changed
else if (type === "swipe" && lastMessageText === chat[chat.length - 1].mes) {
await delay(100);
}
else {
messagesBefore++;
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) {
let activatedNames = [];

View File

@@ -748,7 +748,7 @@ img[src*="user-slash-solid.svg"] {
}
.menu_button .svg_icon {
height: 24px;
height: 22px;
vertical-align: middle;
margin: 5px;
filter: invert(1) brightness(75%);
@@ -824,7 +824,7 @@ img[src*="user-slash-solid.svg"] {
display: flex;
flex-direction: row;
align-items: center;
width: 98%;
margin-bottom: 10px;
}
#character_search_bar {