mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge pull request #681 from BlipRanger/dev
This commit is contained in:
@@ -1298,7 +1298,6 @@ function addOneMessage(mes, { type = "normal", insertAfter = null, scroll = true
|
|||||||
var messageText = mes["mes"];
|
var messageText = mes["mes"];
|
||||||
const momentDate = timestampToMoment(mes.send_date);
|
const momentDate = timestampToMoment(mes.send_date);
|
||||||
const timestamp = momentDate.isValid() ? momentDate.format('LL LT') : '';
|
const timestamp = momentDate.isValid() ? momentDate.format('LL LT') : '';
|
||||||
saveGeneratorToMessage(mes);
|
|
||||||
|
|
||||||
|
|
||||||
if (mes?.extra?.display_text) {
|
if (mes?.extra?.display_text) {
|
||||||
@@ -1921,7 +1920,7 @@ class StreamingProcessor {
|
|||||||
|
|
||||||
if (this.type == 'swipe' && Array.isArray(chat[messageId]['swipes'])) {
|
if (this.type == 'swipe' && Array.isArray(chat[messageId]['swipes'])) {
|
||||||
chat[messageId]['swipes'][chat[messageId]['swipe_id']] = processedText;
|
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(
|
let formattedText = messageFormatting(
|
||||||
@@ -2003,7 +2002,7 @@ class StreamingProcessor {
|
|||||||
if (this.type !== 'swipe' && this.type !== 'impersonate') {
|
if (this.type !== 'swipe' && this.type !== 'impersonate') {
|
||||||
if (Array.isArray(chat[messageId]['swipes']) && chat[messageId]['swipes'].length === 1 && chat[messageId]['swipe_id'] === 0) {
|
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]['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'])) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3668,7 +3667,6 @@ function saveReply(type, getMessage, this_mes_is_name, title) {
|
|||||||
const generationFinished = new Date();
|
const generationFinished = new Date();
|
||||||
const img = extractImageFromMessage(getMessage);
|
const img = extractImageFromMessage(getMessage);
|
||||||
getMessage = img.getMessage;
|
getMessage = img.getMessage;
|
||||||
|
|
||||||
if (type === 'swipe') {
|
if (type === 'swipe') {
|
||||||
chat[chat.length - 1]['swipes'].length++;
|
chat[chat.length - 1]['swipes'].length++;
|
||||||
if (chat[chat.length - 1]['swipe_id'] === chat[chat.length - 1]['swipes'].length - 1) {
|
if (chat[chat.length - 1]['swipe_id'] === chat[chat.length - 1]['swipes'].length - 1) {
|
||||||
@@ -3677,6 +3675,8 @@ function saveReply(type, getMessage, this_mes_is_name, title) {
|
|||||||
chat[chat.length - 1]['gen_started'] = generation_started;
|
chat[chat.length - 1]['gen_started'] = generation_started;
|
||||||
chat[chat.length - 1]['gen_finished'] = generationFinished;
|
chat[chat.length - 1]['gen_finished'] = generationFinished;
|
||||||
chat[chat.length - 1]['send_date'] = getMessageTimeStamp();
|
chat[chat.length - 1]['send_date'] = getMessageTimeStamp();
|
||||||
|
chat[chat.length - 1]['extra']['api'] = main_api;
|
||||||
|
chat[chat.length - 1]['extra']['model'] = getGeneratingModel();
|
||||||
addOneMessage(chat[chat.length - 1], { type: 'swipe' });
|
addOneMessage(chat[chat.length - 1], { type: 'swipe' });
|
||||||
} else {
|
} else {
|
||||||
chat[chat.length - 1]['mes'] = getMessage;
|
chat[chat.length - 1]['mes'] = getMessage;
|
||||||
@@ -3688,6 +3688,8 @@ function saveReply(type, getMessage, this_mes_is_name, title) {
|
|||||||
chat[chat.length - 1]['gen_started'] = generation_started;
|
chat[chat.length - 1]['gen_started'] = generation_started;
|
||||||
chat[chat.length - 1]['gen_finished'] = generationFinished;
|
chat[chat.length - 1]['gen_finished'] = generationFinished;
|
||||||
chat[chat.length - 1]['send_date'] = getMessageTimeStamp();
|
chat[chat.length - 1]['send_date'] = getMessageTimeStamp();
|
||||||
|
chat[chat.length - 1]["extra"]["api"] = main_api;
|
||||||
|
chat[chat.length - 1]["extra"]["model"] = getGeneratingModel();
|
||||||
addOneMessage(chat[chat.length - 1], { type: 'swipe' });
|
addOneMessage(chat[chat.length - 1], { type: 'swipe' });
|
||||||
} else if (type === 'appendFinal') {
|
} else if (type === 'appendFinal') {
|
||||||
console.debug("Trying to appendFinal.")
|
console.debug("Trying to appendFinal.")
|
||||||
@@ -3696,6 +3698,8 @@ function saveReply(type, getMessage, this_mes_is_name, title) {
|
|||||||
chat[chat.length - 1]['gen_started'] = generation_started;
|
chat[chat.length - 1]['gen_started'] = generation_started;
|
||||||
chat[chat.length - 1]['gen_finished'] = generationFinished;
|
chat[chat.length - 1]['gen_finished'] = generationFinished;
|
||||||
chat[chat.length - 1]['send_date'] = getMessageTimeStamp();
|
chat[chat.length - 1]['send_date'] = getMessageTimeStamp();
|
||||||
|
chat[chat.length - 1]["extra"]["api"] = main_api;
|
||||||
|
chat[chat.length - 1]["extra"]["model"] = getGeneratingModel();
|
||||||
addOneMessage(chat[chat.length - 1], { type: 'swipe' });
|
addOneMessage(chat[chat.length - 1], { type: 'swipe' });
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -3706,6 +3710,8 @@ function saveReply(type, getMessage, this_mes_is_name, title) {
|
|||||||
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;
|
||||||
chat[chat.length - 1]['send_date'] = getMessageTimeStamp();
|
chat[chat.length - 1]['send_date'] = getMessageTimeStamp();
|
||||||
|
chat[chat.length - 1]["extra"]["api"] = main_api;
|
||||||
|
chat[chat.length - 1]["extra"]["model"] = getGeneratingModel();
|
||||||
if (power_user.trim_spaces) {
|
if (power_user.trim_spaces) {
|
||||||
getMessage = getMessage.trim();
|
getMessage = getMessage.trim();
|
||||||
}
|
}
|
||||||
@@ -3729,18 +3735,29 @@ function saveReply(type, getMessage, this_mes_is_name, title) {
|
|||||||
saveImageToMessage(img, chat[chat.length - 1]);
|
saveImageToMessage(img, chat[chat.length - 1]);
|
||||||
addOneMessage(chat[chat.length - 1]);
|
addOneMessage(chat[chat.length - 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const item = chat[chat.length - 1];
|
const item = chat[chat.length - 1];
|
||||||
if (item['swipe_info'] === undefined) {
|
if (item["swipe_info"] === undefined) {
|
||||||
item['swipe_info'] = [];
|
item["swipe_info"] = [];
|
||||||
}
|
}
|
||||||
if (item['swipe_id'] !== undefined) {
|
if (item["swipe_id"] !== undefined) {
|
||||||
item['swipes'][item['swipes'].length - 1] = item['mes'];
|
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'] };
|
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 {
|
} else {
|
||||||
item['swipe_id'] = 0;
|
item["swipe_id"] = 0;
|
||||||
item['swipes'] = [];
|
item["swipes"] = [];
|
||||||
item['swipes'][0] = chat[chat.length - 1]['mes'];
|
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_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 };
|
return { type, getMessage };
|
||||||
}
|
}
|
||||||
@@ -3755,7 +3772,7 @@ function saveImageToMessage(img, mes) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveGeneratorToMessage(mes) {
|
function getGeneratingModel(mes) {
|
||||||
let model = '';
|
let model = '';
|
||||||
switch (main_api) {
|
switch (main_api) {
|
||||||
case 'kobold':
|
case 'kobold':
|
||||||
@@ -3777,12 +3794,7 @@ function saveGeneratorToMessage(mes) {
|
|||||||
model = poe_settings.bot;
|
model = poe_settings.bot;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
return model
|
||||||
if (mes && typeof mes.extra !== 'object') {
|
|
||||||
mes.extra = {};
|
|
||||||
}
|
|
||||||
mes.extra.api = main_api;
|
|
||||||
mes.extra.model = model;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractImageFromMessage(getMessage) {
|
function extractImageFromMessage(getMessage) {
|
||||||
@@ -6275,7 +6287,7 @@ function swipe_left() { // when we swipe left..but no generation.
|
|||||||
const this_mes_block_height = this_mes_block[0].scrollHeight;
|
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]['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]['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 (chat[chat.length - 1].extra) {
|
||||||
// if message has memory attached - remove it to allow regen
|
// if message has memory attached - remove it to allow regen
|
||||||
@@ -6391,7 +6403,8 @@ const swipe_right = () => {
|
|||||||
chat[chat.length - 1]['swipes'] = []; // empty the array
|
chat[chat.length - 1]['swipes'] = []; // empty the array
|
||||||
chat[chat.length - 1]['swipe_info'] = [];
|
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]['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'])) };
|
||||||
|
//assign swipe info array with last message from chat
|
||||||
}
|
}
|
||||||
chat[chat.length - 1]['swipe_id']++; //make new slot in array
|
chat[chat.length - 1]['swipe_id']++; //make new slot in array
|
||||||
if (chat[chat.length - 1].extra) {
|
if (chat[chat.length - 1].extra) {
|
||||||
@@ -6415,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
|
} 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]['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]['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
|
run_swipe_right = true; //then prepare to do normal right swipe to show next message
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user