From 5f9fd017ea85584d450f9bd5e090a9264b2ced61 Mon Sep 17 00:00:00 2001 From: BlipRanger <1860540+BlipRanger@users.noreply.github.com> Date: Sun, 9 Jul 2023 16:50:16 -0400 Subject: [PATCH 1/4] Unclear where this needs to be. --- public/script.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/public/script.js b/public/script.js index 534c97cf4..d6b8e042e 100644 --- a/public/script.js +++ b/public/script.js @@ -1298,7 +1298,6 @@ function addOneMessage(mes, { type = "normal", insertAfter = null, scroll = true var messageText = mes["mes"]; const momentDate = timestampToMoment(mes.send_date); const timestamp = momentDate.isValid() ? momentDate.format('LL LT') : ''; - saveGeneratorToMessage(mes); if (mes?.extra?.display_text) { @@ -3677,6 +3676,7 @@ function saveReply(type, getMessage, this_mes_is_name, title) { chat[chat.length - 1]['gen_started'] = generation_started; chat[chat.length - 1]['gen_finished'] = generationFinished; chat[chat.length - 1]['send_date'] = getMessageTimeStamp(); + saveGeneratorToMessage(chat[chat.length - 1]); addOneMessage(chat[chat.length - 1], { type: 'swipe' }); } else { chat[chat.length - 1]['mes'] = getMessage; @@ -3688,6 +3688,7 @@ function saveReply(type, getMessage, this_mes_is_name, title) { chat[chat.length - 1]['gen_started'] = generation_started; chat[chat.length - 1]['gen_finished'] = generationFinished; chat[chat.length - 1]['send_date'] = getMessageTimeStamp(); + saveGeneratorToMessage(chat[chat.length - 1]); addOneMessage(chat[chat.length - 1], { type: 'swipe' }); } else if (type === 'appendFinal') { console.debug("Trying to appendFinal.") @@ -3696,6 +3697,7 @@ function saveReply(type, getMessage, this_mes_is_name, title) { chat[chat.length - 1]['gen_started'] = generation_started; chat[chat.length - 1]['gen_finished'] = generationFinished; chat[chat.length - 1]['send_date'] = getMessageTimeStamp(); + saveGeneratorToMessage(chat[chat.length - 1]); addOneMessage(chat[chat.length - 1], { type: 'swipe' }); } else { @@ -3727,6 +3729,7 @@ function saveReply(type, getMessage, this_mes_is_name, title) { } saveImageToMessage(img, chat[chat.length - 1]); + saveGeneratorToMessage(chat[chat.length - 1]); addOneMessage(chat[chat.length - 1]); } const item = chat[chat.length - 1]; From ad001ea263d112a02059a54609ca0802dd48a12e Mon Sep 17 00:00:00 2001 From: BlipRanger <1860540+BlipRanger@users.noreply.github.com> Date: Sun, 9 Jul 2023 19:57:42 -0400 Subject: [PATCH 2/4] Actually copy extra instead of referencing the same object --- public/script.js | 60 +++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/public/script.js b/public/script.js index d6b8e042e..56750489b 100644 --- a/public/script.js +++ b/public/script.js @@ -1151,7 +1151,7 @@ function messageFormatting(mes, ch_name, isSystem, isUser) { regexPlacement = regex_placement.SENDAS; } else { regexPlacement = regex_placement.AI_OUTPUT; - } + } mes = getRegexedString(mes, regexPlacement, { isMarkdown: true }); } @@ -3667,7 +3667,6 @@ function saveReply(type, getMessage, this_mes_is_name, title) { const generationFinished = new Date(); const img = extractImageFromMessage(getMessage); getMessage = img.getMessage; - if (type === 'swipe') { chat[chat.length - 1]['swipes'].length++; if (chat[chat.length - 1]['swipe_id'] === chat[chat.length - 1]['swipes'].length - 1) { @@ -3676,7 +3675,8 @@ function saveReply(type, getMessage, this_mes_is_name, title) { chat[chat.length - 1]['gen_started'] = generation_started; chat[chat.length - 1]['gen_finished'] = generationFinished; chat[chat.length - 1]['send_date'] = getMessageTimeStamp(); - saveGeneratorToMessage(chat[chat.length - 1]); + chat[chat.length - 1]['extra']['api'] = main_api; + chat[chat.length - 1]['extra']['model'] = getGeneratorInfo(); addOneMessage(chat[chat.length - 1], { type: 'swipe' }); } else { chat[chat.length - 1]['mes'] = getMessage; @@ -3688,7 +3688,8 @@ function saveReply(type, getMessage, this_mes_is_name, title) { chat[chat.length - 1]['gen_started'] = generation_started; chat[chat.length - 1]['gen_finished'] = generationFinished; chat[chat.length - 1]['send_date'] = getMessageTimeStamp(); - saveGeneratorToMessage(chat[chat.length - 1]); + chat[chat.length - 1]["extra"]["api"] = main_api; + chat[chat.length - 1]["extra"]["model"] = getGeneratorInfo(); addOneMessage(chat[chat.length - 1], { type: 'swipe' }); } else if (type === 'appendFinal') { console.debug("Trying to appendFinal.") @@ -3697,7 +3698,8 @@ function saveReply(type, getMessage, this_mes_is_name, title) { chat[chat.length - 1]['gen_started'] = generation_started; chat[chat.length - 1]['gen_finished'] = generationFinished; chat[chat.length - 1]['send_date'] = getMessageTimeStamp(); - saveGeneratorToMessage(chat[chat.length - 1]); + chat[chat.length - 1]["extra"]["api"] = main_api; + chat[chat.length - 1]["extra"]["model"] = getGeneratorInfo(); addOneMessage(chat[chat.length - 1], { type: 'swipe' }); } else { @@ -3708,6 +3710,8 @@ function saveReply(type, getMessage, this_mes_is_name, title) { chat[chat.length - 1]['is_user'] = false; chat[chat.length - 1]['is_name'] = this_mes_is_name; chat[chat.length - 1]['send_date'] = getMessageTimeStamp(); + chat[chat.length - 1]["extra"]["api"] = main_api; + chat[chat.length - 1]["extra"]["model"] = getGeneratorInfo(); if (power_user.trim_spaces) { getMessage = getMessage.trim(); } @@ -3729,21 +3733,32 @@ function saveReply(type, getMessage, this_mes_is_name, title) { } saveImageToMessage(img, chat[chat.length - 1]); - saveGeneratorToMessage(chat[chat.length - 1]); addOneMessage(chat[chat.length - 1]); } + const item = chat[chat.length - 1]; - if (item['swipe_info'] === undefined) { - item['swipe_info'] = []; + if (item["swipe_info"] === undefined) { + item["swipe_info"] = []; + console.log("Create empty swipe info array"); } - if (item['swipe_id'] !== undefined) { - item['swipes'][item['swipes'].length - 1] = item['mes']; - item['swipe_info'][item['swipes'].length - 1] = { 'send_date': item['send_date'], 'gen_started': item['gen_started'], 'gen_finished': item['gen_finished'], 'extra': item['extra'] }; + if (item["swipe_id"] !== undefined) { + item["swipes"][item["swipes"].length - 1] = item["mes"]; + item["swipe_info"][item["swipes"].length - 1] = { + send_date: item["send_date"], + gen_started: item["gen_started"], + gen_finished: item["gen_finished"], + extra: JSON.parse(JSON.stringify(item["extra"])), + }; } else { - item['swipe_id'] = 0; - item['swipes'] = []; - item['swipes'][0] = chat[chat.length - 1]['mes']; - item['swipe_info'][0] = { 'send_date': chat[chat.length - 1]['send_date'], 'gen_started': chat[chat.length - 1]['gen_started'], 'gen_finished': chat[chat.length - 1]['gen_finished'], 'extra': item['extra'] }; + item["swipe_id"] = 0; + item["swipes"] = []; + item["swipes"][0] = chat[chat.length - 1]["mes"]; + item["swipe_info"][0] = { + send_date: chat[chat.length - 1]["send_date"], + gen_started: chat[chat.length - 1]["gen_started"], + gen_finished: chat[chat.length - 1]["gen_finished"], + extra: JSON.parse(JSON.stringify(chat[chat.length - 1]["extra"])), + }; } return { type, getMessage }; } @@ -3758,7 +3773,7 @@ function saveImageToMessage(img, mes) { } } -function saveGeneratorToMessage(mes) { +function getGeneratorInfo(mes) { let model = ''; switch (main_api) { case 'kobold': @@ -3780,12 +3795,7 @@ function saveGeneratorToMessage(mes) { model = poe_settings.bot; break; } - - if (mes && typeof mes.extra !== 'object') { - mes.extra = {}; - } - mes.extra.api = main_api; - mes.extra.model = model; + return model } function extractImageFromMessage(getMessage) { @@ -6278,7 +6288,7 @@ function swipe_left() { // when we swipe left..but no generation. const this_mes_block_height = this_mes_block[0].scrollHeight; chat[chat.length - 1]['mes'] = chat[chat.length - 1]['swipes'][chat[chat.length - 1]['swipe_id']]; chat[chat.length - 1]['send_date'] = chat[chat.length - 1].swipe_info[chat[chat.length - 1]['swipe_id']]?.send_date || chat[chat.length - 1].send_date; //load the last mes box with the latest generation - chat[chat.length - 1]['extra'] = chat[chat.length - 1].swipe_info[chat[chat.length - 1]['swipe_id']]?.extra || chat[chat.length - 1].extra; + chat[chat.length - 1]['extra'] = JSON.parse(JSON.stringify(chat[chat.length - 1].swipe_info[chat[chat.length - 1]['swipe_id']]?.extra || chat[chat.length - 1].extra)); if (chat[chat.length - 1].extra) { // if message has memory attached - remove it to allow regen @@ -6394,7 +6404,9 @@ const swipe_right = () => { chat[chat.length - 1]['swipes'] = []; // empty the array chat[chat.length - 1]['swipe_info'] = []; chat[chat.length - 1]['swipes'][0] = chat[chat.length - 1]['mes']; //assign swipe array with last message from chat - chat[chat.length - 1]['swipe_info'][0] = { 'send_date': chat[chat.length - 1]['send_date'], 'gen_started': chat[chat.length - 1]['gen_started'], 'gen_finished': chat[chat.length - 1]['gen_finished'], 'extra': chat[chat.length - 1]['extra'] }; //assign swipe info array with last message from chat + chat[chat.length - 1]['swipe_info'][0] = { 'send_date': chat[chat.length - 1]['send_date'], 'gen_started': chat[chat.length - 1]['gen_started'], 'gen_finished': chat[chat.length - 1]['gen_finished'], 'extra': JSON.parse(JSON.stringify(chat[chat.length - 1]['extra'])) }; + console.log('swipe_info: ' + chat[chat.length - 1]['swipe_info'][0]); + //assign swipe info array with last message from chat } chat[chat.length - 1]['swipe_id']++; //make new slot in array if (chat[chat.length - 1].extra) { From 35688c3eb3152cc661e35bc0cdcb996ded2d78e2 Mon Sep 17 00:00:00 2001 From: BlipRanger <1860540+BlipRanger@users.noreply.github.com> Date: Sun, 9 Jul 2023 20:15:35 -0400 Subject: [PATCH 3/4] Cleanup/Rename for generation info --- public/script.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/public/script.js b/public/script.js index 56750489b..0a43d1e1e 100644 --- a/public/script.js +++ b/public/script.js @@ -3676,7 +3676,7 @@ function saveReply(type, getMessage, this_mes_is_name, title) { chat[chat.length - 1]['gen_finished'] = generationFinished; chat[chat.length - 1]['send_date'] = getMessageTimeStamp(); chat[chat.length - 1]['extra']['api'] = main_api; - chat[chat.length - 1]['extra']['model'] = getGeneratorInfo(); + chat[chat.length - 1]['extra']['model'] = getGeneratingModel(); addOneMessage(chat[chat.length - 1], { type: 'swipe' }); } else { chat[chat.length - 1]['mes'] = getMessage; @@ -3689,7 +3689,7 @@ function saveReply(type, getMessage, this_mes_is_name, title) { chat[chat.length - 1]['gen_finished'] = generationFinished; chat[chat.length - 1]['send_date'] = getMessageTimeStamp(); chat[chat.length - 1]["extra"]["api"] = main_api; - chat[chat.length - 1]["extra"]["model"] = getGeneratorInfo(); + chat[chat.length - 1]["extra"]["model"] = getGeneratingModel(); addOneMessage(chat[chat.length - 1], { type: 'swipe' }); } else if (type === 'appendFinal') { console.debug("Trying to appendFinal.") @@ -3699,7 +3699,7 @@ function saveReply(type, getMessage, this_mes_is_name, title) { chat[chat.length - 1]['gen_finished'] = generationFinished; chat[chat.length - 1]['send_date'] = getMessageTimeStamp(); chat[chat.length - 1]["extra"]["api"] = main_api; - chat[chat.length - 1]["extra"]["model"] = getGeneratorInfo(); + chat[chat.length - 1]["extra"]["model"] = getGeneratingModel(); addOneMessage(chat[chat.length - 1], { type: 'swipe' }); } else { @@ -3711,7 +3711,7 @@ function saveReply(type, getMessage, this_mes_is_name, title) { chat[chat.length - 1]['is_name'] = this_mes_is_name; chat[chat.length - 1]['send_date'] = getMessageTimeStamp(); chat[chat.length - 1]["extra"]["api"] = main_api; - chat[chat.length - 1]["extra"]["model"] = getGeneratorInfo(); + chat[chat.length - 1]["extra"]["model"] = getGeneratingModel(); if (power_user.trim_spaces) { getMessage = getMessage.trim(); } @@ -3739,7 +3739,6 @@ function saveReply(type, getMessage, this_mes_is_name, title) { const item = chat[chat.length - 1]; if (item["swipe_info"] === undefined) { item["swipe_info"] = []; - console.log("Create empty swipe info array"); } if (item["swipe_id"] !== undefined) { item["swipes"][item["swipes"].length - 1] = item["mes"]; @@ -3773,7 +3772,7 @@ function saveImageToMessage(img, mes) { } } -function getGeneratorInfo(mes) { +function getGeneratingModel(mes) { let model = ''; switch (main_api) { case 'kobold': @@ -6405,7 +6404,6 @@ const swipe_right = () => { chat[chat.length - 1]['swipe_info'] = []; chat[chat.length - 1]['swipes'][0] = chat[chat.length - 1]['mes']; //assign swipe array with last message from chat chat[chat.length - 1]['swipe_info'][0] = { 'send_date': chat[chat.length - 1]['send_date'], 'gen_started': chat[chat.length - 1]['gen_started'], 'gen_finished': chat[chat.length - 1]['gen_finished'], 'extra': JSON.parse(JSON.stringify(chat[chat.length - 1]['extra'])) }; - console.log('swipe_info: ' + chat[chat.length - 1]['swipe_info'][0]); //assign swipe info array with last message from chat } chat[chat.length - 1]['swipe_id']++; //make new slot in array @@ -8526,4 +8524,4 @@ $(document).ready(function () { } } } -}) +}) \ No newline at end of file From d5c38077a4493c06f229731b21cc064af72c0055 Mon Sep 17 00:00:00 2001 From: BlipRanger <1860540+BlipRanger@users.noreply.github.com> Date: Sun, 9 Jul 2023 21:22:29 -0400 Subject: [PATCH 4/4] Missed a spot --- public/script.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/public/script.js b/public/script.js index 0a43d1e1e..11bbd2430 100644 --- a/public/script.js +++ b/public/script.js @@ -1920,7 +1920,7 @@ class StreamingProcessor { if (this.type == 'swipe' && Array.isArray(chat[messageId]['swipes'])) { chat[messageId]['swipes'][chat[messageId]['swipe_id']] = processedText; - chat[messageId]['swipe_info'][chat[messageId]['swipe_id']] = { 'send_date': chat[messageId]['send_date'], 'gen_started': chat[messageId]['gen_started'], 'gen_finished': chat[messageId]['gen_finished'], 'extra': chat[messageId]['extra'] }; + chat[messageId]['swipe_info'][chat[messageId]['swipe_id']] = { 'send_date': chat[messageId]['send_date'], 'gen_started': chat[messageId]['gen_started'], 'gen_finished': chat[messageId]['gen_finished'], 'extra': JSON.parse(JSON.stringify(chat[messageId]['extra'])) }; } let formattedText = messageFormatting( @@ -2002,7 +2002,7 @@ class StreamingProcessor { if (this.type !== 'swipe' && this.type !== 'impersonate') { if (Array.isArray(chat[messageId]['swipes']) && chat[messageId]['swipes'].length === 1 && chat[messageId]['swipe_id'] === 0) { chat[messageId]['swipes'][0] = chat[messageId]['mes']; - chat[messageId]['swipe_info'][0] = { 'send_date': chat[messageId]['send_date'], 'gen_started': chat[messageId]['gen_started'], 'gen_finished': chat[messageId]['gen_finished'], 'extra': chat[messageId]['extra'] }; + chat[messageId]['swipe_info'][0] = { 'send_date': chat[messageId]['send_date'], 'gen_started': chat[messageId]['gen_started'], 'gen_finished': chat[messageId]['gen_finished'], 'extra': JSON.parse(JSON.stringify(chat[messageId]['extra'])) }; } } } @@ -6428,7 +6428,7 @@ const swipe_right = () => { } else if (parseInt(chat[chat.length - 1]['swipe_id']) < chat[chat.length - 1]['swipes'].length) { //otherwise, if the id is less than the number of swipes chat[chat.length - 1]['mes'] = chat[chat.length - 1]['swipes'][chat[chat.length - 1]['swipe_id']]; //load the last mes box with the latest generation chat[chat.length - 1]['send_date'] = chat[chat.length - 1]?.swipe_info[chat[chat.length - 1]['swipe_id']]?.send_date || chat[chat.length - 1]['send_date']; //update send date - chat[chat.length - 1]['extra'] = chat[chat.length - 1].swipe_info[chat[chat.length - 1]['swipe_id']]?.extra || chat[chat.length - 1].extra; + chat[chat.length - 1]['extra'] = JSON.parse(JSON.stringify(chat[chat.length - 1].swipe_info[chat[chat.length - 1]['swipe_id']]?.extra || chat[chat.length - 1].extra)); run_swipe_right = true; //then prepare to do normal right swipe to show next message }