This commit is contained in:
SillyLossy
2023-05-04 23:32:12 +03:00
2 changed files with 37 additions and 18 deletions

View File

@@ -1021,11 +1021,17 @@ function addCopyToCodeBlocks(messageElement) {
function addOneMessage(mes, { type = "normal", insertAfter = null, scroll = true } = {}) { function addOneMessage(mes, { type = "normal", insertAfter = null, scroll = true } = {}) {
var messageText = mes["mes"]; var messageText = mes["mes"];
var characterName = name1;
if (mes.name === name1) {
var characterName = name1; //set to user's name by default
} else { var characterName = mes.name }
var avatarImg = "User Avatars/" + user_avatar; var avatarImg = "User Avatars/" + user_avatar;
const isSystem = mes.is_system; const isSystem = mes.is_system;
const title = mes.title; const title = mes.title;
generatedPromtCache = ""; generatedPromtCache = "";
//for non-user mesages
if (!mes["is_user"]) { if (!mes["is_user"]) {
if (mes.force_avatar) { if (mes.force_avatar) {
avatarImg = mes.force_avatar; avatarImg = mes.force_avatar;
@@ -1041,8 +1047,11 @@ function addOneMessage(mes, { type = "normal", insertAfter = null, scroll = true
avatarImg = default_avatar; avatarImg = default_avatar;
} }
} }
//old processing:
//if messge is from sytem, use the name provided in the message JSONL to proceed,
//if not system message, use name2 (char's name) to proceed
//characterName = mes.is_system || mes.force_avatar ? mes.name : name2;
characterName = mes.is_system || mes.force_avatar ? mes.name : name2;
} }
if (count_view_mes == 0) { if (count_view_mes == 0) {
@@ -1091,7 +1100,6 @@ function addOneMessage(mes, { type = "normal", insertAfter = null, scroll = true
} }
newMessage.find('.avatar img').on('error', function () { newMessage.find('.avatar img').on('error', function () {
/* $(this).attr("src", "/img/user-slash-solid.svg"); */
$(this).hide(); $(this).hide();
$(this).parent().html(`<div class="missing-avatar fa-solid fa-user-slash"></div>`); $(this).parent().html(`<div class="missing-avatar fa-solid fa-user-slash"></div>`);
}); });
@@ -1165,8 +1173,11 @@ function substituteParams(content, _name1, _name2) {
function getStoppingStrings(isImpersonate, addSpace) { function getStoppingStrings(isImpersonate, addSpace) {
const charString = `\n${name2}:`; const charString = `\n${name2}:`;
const userString = is_pygmalion ? `\nYou:` : `\n${name1}:`; const youString = `\nYou:`;
const result = isImpersonate ? [charString] : [userString]; const userString = `\n${name1}:`;
const result = isImpersonate ? [charString] : [youString];
result.push(userString);
// Add other group members as the stopping strings // Add other group members as the stopping strings
if (selected_group) { if (selected_group) {
@@ -1541,8 +1552,8 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
$("#send_textarea").val('').trigger('input'); $("#send_textarea").val('').trigger('input');
} else { } else {
textareaText = ""; textareaText = "";
if (chat.length && chat[chat.length - 1]['is_user']) {//If last message from You if (chat.length && chat[chat.length - 1]['is_user']) {
//do nothing? why does this check exist?
} }
else if (type !== 'quiet' && type !== "swipe" && !isImpersonate) { else if (type !== 'quiet' && type !== "swipe" && !isImpersonate) {
chat.length = chat.length - 1; chat.length = chat.length - 1;
@@ -1597,6 +1608,8 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
//********************************* //*********************************
//PRE FORMATING STRING //PRE FORMATING STRING
//********************************* //*********************************
//for normal messages sent from user..
if (textareaText != "" && !automatic_trigger && type !== 'quiet') { if (textareaText != "" && !automatic_trigger && type !== 'quiet') {
chat[chat.length] = {}; chat[chat.length] = {};
chat[chat.length - 1]['name'] = name1; chat[chat.length - 1]['name'] = name1;
@@ -1682,7 +1695,8 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
let charName = selected_group ? coreChat[j].name : name2; let charName = selected_group ? coreChat[j].name : name2;
let this_mes_ch_name = ''; let this_mes_ch_name = '';
if (coreChat[j]['is_user']) { if (coreChat[j]['is_user']) {
this_mes_ch_name = name1; //this_mes_ch_name = name1;
this_mes_ch_name = coreChat[j]['name'];
} else { } else {
this_mes_ch_name = charName; this_mes_ch_name = charName;
} }
@@ -2424,6 +2438,8 @@ function cleanUpMessage(getMessage, isImpersonate) {
} }
const stoppingStrings = getStoppingStrings(isImpersonate, false); const stoppingStrings = getStoppingStrings(isImpersonate, false);
//console.log('stopping on these strings: ');
//console.log(stoppingStrings);
for (const stoppingString of stoppingStrings) { for (const stoppingString of stoppingStrings) {
if (stoppingString.length) { if (stoppingString.length) {
@@ -2660,14 +2676,16 @@ async function saveChat(chat_name, withMetadata) {
alert('Trying to save group chat with regular saveChat function. Aborting to prevent corruption.'); alert('Trying to save group chat with regular saveChat function. Aborting to prevent corruption.');
throw new Error('Group chat saved from saveChat'); throw new Error('Group chat saved from saveChat');
} }
/*
if (item.is_user) { if (item.is_user) {
var str = item.mes.replace(`${name1}:`, `${name1}:`); //var str = item.mes.replace(`${name1}:`, `${name1}:`);
chat[i].mes = str; //chat[i].mes = str;
chat[i].name = name1; //chat[i].name = name1;
} else if (i !== chat.length - 1 && chat[i].swipe_id !== undefined) { } else if (i !== chat.length - 1 && chat[i].swipe_id !== undefined) {
// delete chat[i].swipes; // delete chat[i].swipes;
// delete chat[i].swipe_id; // delete chat[i].swipe_id;
} }
*/
}); });
var save_chat = [ var save_chat = [
{ {
@@ -2775,8 +2793,8 @@ function getChatResult() {
for (let i = 0; i < chat.length; i++) { for (let i = 0; i < chat.length; i++) {
const item = chat[i]; const item = chat[i];
if (item["is_user"]) { if (item["is_user"]) {
item['mes'] = item['mes'].replace(default_user_name + ':', name1 + ':'); //item['mes'] = item['mes'].replace(default_user_name + ':', name1 + ':');
item['name'] = name1; //item['name'] = name1;
} }
} }
} else { } else {
@@ -3190,8 +3208,11 @@ async function saveSettings(type) {
}, null, 4), }, null, 4),
beforeSend: function () { beforeSend: function () {
if (type == "change_name") { if (type == "change_name") {
//let nameBeforeChange = name1;
name1 = $("#your_name").val(); name1 = $("#your_name").val();
// console.log('beforeSend name1 = '+name1); //$(`.mes[ch_name="${nameBeforeChange}"]`).attr('ch_name' === name1);
//console.log('beforeSend name1 = ' + nameBeforeChange);
//console.log('new name: ' + name1);
} }
}, },
cache: false, cache: false,
@@ -3201,8 +3222,6 @@ async function saveSettings(type) {
success: function (data) { success: function (data) {
//online_status = data.result; //online_status = data.result;
if (type == "change_name") { if (type == "change_name") {
clearChat(); clearChat();
printMessages(); printMessages();
} }

View File

@@ -174,8 +174,8 @@ code {
word-wrap: break-word; word-wrap: break-word;
border: 1px solid var(--white30a); border: 1px solid var(--white30a);
border-radius: 5px; border-radius: 5px;
background-color: var(--black70a);
padding: 0 3px;
max-width: calc(100svw - 95px); max-width: calc(100svw - 95px);
line-height: var(--mainFontSize); line-height: var(--mainFontSize);
} }