Rework title displays on Horde workers

This commit is contained in:
SillyLossy
2023-04-30 15:34:50 +03:00
parent 46b708d408
commit c5b3b175db
3 changed files with 38 additions and 24 deletions

View File

@ -952,12 +952,14 @@ function messageFormating(mes, ch_name, isSystem, forceAvatar) {
return mes; return mes;
} }
function getMessageFromTemplate(mesId, characterName, isUser, avatarImg, bias, isSystem) { function getMessageFromTemplate(mesId, characterName, isUser, avatarImg, bias, isSystem, title) {
const mes = $('#message_template .mes').clone(); const mes = $('#message_template .mes').clone();
mes.attr({ 'mesid': mesId, 'ch_name': characterName, 'is_user': isUser, 'is_system': !!isSystem }); mes.attr({ 'mesid': mesId, 'ch_name': characterName, 'is_user': isUser, 'is_system': !!isSystem });
mes.find('.avatar img').attr('src', avatarImg); mes.find('.avatar img').attr('src', avatarImg);
mes.find('.ch_name .name_text').text(characterName); mes.find('.ch_name .name_text').text(characterName);
mes.find('.mes_bias').html(bias); mes.find('.mes_bias').html(bias);
title && mes.attr('title', title);
return mes; return mes;
} }
@ -965,7 +967,7 @@ function appendImageToMessage(mes, messageElement) {
if (mes.extra?.image) { if (mes.extra?.image) {
const image = document.createElement("img"); const image = document.createElement("img");
image.src = mes.extra?.image; image.src = mes.extra?.image;
image.title = mes.title; image.title = mes.extra?.title;
image.classList.add("img_extra"); image.classList.add("img_extra");
messageElement.find(".mes_text").prepend(image); messageElement.find(".mes_text").prepend(image);
} }
@ -999,6 +1001,7 @@ function addOneMessage(mes, { type = "normal", insertAfter = null, scroll = true
var characterName = name1; var characterName = name1;
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;
generatedPromtCache = ""; generatedPromtCache = "";
if (!mes["is_user"]) { if (!mes["is_user"]) {
if (mes.force_avatar) { if (mes.force_avatar) {
@ -1030,7 +1033,7 @@ function addOneMessage(mes, { type = "normal", insertAfter = null, scroll = true
); );
const bias = messageFormating(mes.extra?.bias ?? ""); const bias = messageFormating(mes.extra?.bias ?? "");
var HTMLForEachMes = getMessageFromTemplate(count_view_mes, characterName, mes.is_user, avatarImg, bias, isSystem); var HTMLForEachMes = getMessageFromTemplate(count_view_mes, characterName, mes.is_user, avatarImg, bias, isSystem, title);
if (type !== 'swipe') { if (type !== 'swipe') {
if (!insertAfter) { if (!insertAfter) {
@ -1060,12 +1063,13 @@ function addOneMessage(mes, { type = "normal", insertAfter = null, scroll = true
}); });
if (type === 'swipe') { if (type === 'swipe') {
$("#chat").children().filter('[mesid="' + (count_view_mes - 1) + '"]').children('.mes_block').children('.mes_text').html(''); $("#chat").children().filter(`[mesid="${count_view_mes - 1}"]`).children('.mes_block').children('.mes_text').html('');
$("#chat").children().filter('[mesid="' + (count_view_mes - 1) + '"]').children('.mes_block').children('.mes_text').append(messageText); $("#chat").children().filter(`[mesid="${count_view_mes - 1}"]`).children('.mes_block').children('.mes_text').append(messageText);
$("#chat").children().filter(`[mesid="${count_view_mes - 1}"]`).attr('title', title);
//console.log(mes); //console.log(mes);
} else { } else {
$("#chat").children().filter('[mesid="' + count_view_mes + '"]').children('.mes_block').children('.mes_text').append(messageText); $("#chat").children().filter(`[mesid="${count_view_mes}"]`).children('.mes_block').children('.mes_text').append(messageText);
hideSwipeButtons(); hideSwipeButtons();
count_view_mes++; count_view_mes++;
} }
@ -2025,7 +2029,8 @@ async function Generate(type, automatic_trigger, force_name2) {
is_send_press = false; is_send_press = false;
if (!data.error) { if (!data.error) {
//const getData = await response.json(); //const getData = await response.json();
let getMessage = extractMessageFromData(data, finalPromt); let getMessage = extractMessageFromData(data);
let title = extractTitleFromData(data);
//Pygmalion run again //Pygmalion run again
// to make it continue generating so long as it's under max_amount and hasn't signaled // to make it continue generating so long as it's under max_amount and hasn't signaled
@ -2038,11 +2043,11 @@ async function Generate(type, automatic_trigger, force_name2) {
({ this_mes_is_name, getMessage } = extractNameFromMessage(getMessage, force_name2, isImpersonate)); ({ this_mes_is_name, getMessage } = extractNameFromMessage(getMessage, force_name2, isImpersonate));
if (generate_loop_counter == 0) { if (generate_loop_counter == 0) {
console.log("New message"); console.log("New message");
({ type, getMessage } = saveReply(type, getMessage, this_mes_is_name)); ({ type, getMessage } = saveReply(type, getMessage, this_mes_is_name, title));
} }
else { else {
console.log("Should append message"); console.log("Should append message");
({ type, getMessage } = saveReply('append', getMessage, this_mes_is_name)); ({ type, getMessage } = saveReply('append', getMessage, this_mes_is_name, title));
} }
generate_loop_counter++; generate_loop_counter++;
getMessage = message_already_generated; getMessage = message_already_generated;
@ -2066,10 +2071,10 @@ async function Generate(type, automatic_trigger, force_name2) {
} }
else { else {
if (!isMultigenEnabled()) { if (!isMultigenEnabled()) {
({ type, getMessage } = saveReply(type, getMessage, this_mes_is_name)); ({ type, getMessage } = saveReply(type, getMessage, this_mes_is_name, title));
} }
else { else {
({ type, getMessage } = saveReply('appendFinal', getMessage, this_mes_is_name)); ({ type, getMessage } = saveReply('appendFinal', getMessage, this_mes_is_name, title));
} }
} }
activateSendButtons(); activateSendButtons();
@ -2230,6 +2235,14 @@ function throwCircuitBreakerError() {
throw new Error('Generate circuit breaker interruption'); throw new Error('Generate circuit breaker interruption');
} }
function extractTitleFromData(data) {
if (main_api == 'kobold' && horde_settings.use_horde) {
return data.workerName;
}
return undefined;
}
function extractMessageFromData(data) { function extractMessageFromData(data) {
let getMessage = ""; let getMessage = "";
@ -2238,7 +2251,7 @@ function extractMessageFromData(data) {
} }
if (main_api == 'kobold' && horde_settings.use_horde) { if (main_api == 'kobold' && horde_settings.use_horde) {
getMessage = data; getMessage = data.text;
} }
if (main_api == 'textgenerationwebui') { if (main_api == 'textgenerationwebui') {
@ -2311,7 +2324,7 @@ function cleanUpMessage(getMessage, isImpersonate) {
return getMessage; return getMessage;
} }
function saveReply(type, getMessage, this_mes_is_name) { function saveReply(type, getMessage, this_mes_is_name, title) {
if (type != 'append' && type != 'appendFinal' && chat.length && (chat[chat.length - 1]['swipe_id'] === undefined || if (type != 'append' && type != 'appendFinal' && chat.length && (chat[chat.length - 1]['swipe_id'] === undefined ||
chat[chat.length - 1]['is_user'])) { chat[chat.length - 1]['is_user'])) {
type = 'normal'; type = 'normal';
@ -2323,19 +2336,20 @@ function saveReply(type, getMessage, this_mes_is_name) {
if (type === 'swipe') { if (type === 'swipe') {
chat[chat.length - 1]['swipes'][chat[chat.length - 1]['swipes'].length] = getMessage; chat[chat.length - 1]['swipes'][chat[chat.length - 1]['swipes'].length] = getMessage;
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) {
//console.log(getMessage); chat[chat.length - 1]['title'] = title;
chat[chat.length - 1]['mes'] = getMessage; chat[chat.length - 1]['mes'] = getMessage;
// console.log('runGenerate calls addOneMessage for swipe');
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;
} }
} else if (type === 'append') { } else if (type === 'append') {
console.log("Trying to append.") console.log("Trying to append.")
chat[chat.length - 1]['title'] = title;
chat[chat.length - 1]['mes'] += getMessage; chat[chat.length - 1]['mes'] += getMessage;
addOneMessage(chat[chat.length - 1], { type: 'swipe' }); addOneMessage(chat[chat.length - 1], { type: 'swipe' });
} else if (type === 'appendFinal') { } else if (type === 'appendFinal') {
console.log("Trying to append.") console.log("Trying to append.")
chat[chat.length - 1]['title'] = title;
chat[chat.length - 1]['mes'] = getMessage; chat[chat.length - 1]['mes'] = getMessage;
addOneMessage(chat[chat.length - 1], { type: 'swipe' }); addOneMessage(chat[chat.length - 1], { type: 'swipe' });
@ -2349,6 +2363,7 @@ function saveReply(type, getMessage, this_mes_is_name) {
chat[chat.length - 1]['send_date'] = humanizedDateTime(); chat[chat.length - 1]['send_date'] = humanizedDateTime();
getMessage = $.trim(getMessage); getMessage = $.trim(getMessage);
chat[chat.length - 1]['mes'] = getMessage; chat[chat.length - 1]['mes'] = getMessage;
chat[chat.length - 1]['title'] = title;
if (selected_group) { if (selected_group) {
console.log('entering chat update for groups'); console.log('entering chat update for groups');
@ -2373,7 +2388,7 @@ function saveImageToMessage(img, mes) {
mes.extra = {}; mes.extra = {};
} }
mes.extra.image = img.image; mes.extra.image = img.image;
mes.title = img.title; mes.extra.title = img.title;
} }
} }
@ -3539,8 +3554,8 @@ function showSwipeButtons() {
function hideSwipeButtons() { function hideSwipeButtons() {
//console.log('hideswipebuttons entered'); //console.log('hideswipebuttons entered');
$("#chat").children().filter('[mesid="' + (count_view_mes - 1) + '"]').children('.swipe_right').css('display', 'none'); $("#chat").children().filter(`[mesid="${count_view_mes - 1}"]`).children('.swipe_right').css('display', 'none');
$("#chat").children().filter('[mesid="' + (count_view_mes - 1) + '"]').children('.swipe_left').css('display', 'none'); $("#chat").children().filter(`[mesid="${count_view_mes - 1}"]`).children('.swipe_left').css('display', 'none');
} }
function saveChatConditional() { function saveChatConditional() {

View File

@ -44,8 +44,10 @@ async function sendCaptionedMessage(caption, image) {
is_name: true, is_name: true,
send_date: Date.now(), send_date: Date.now(),
mes: messageText, mes: messageText,
extra: { image: image }, extra: {
title: caption image: image,
title: caption,
},
}; };
context.chat.push(message); context.chat.push(message);
context.addOneMessage(message); context.addOneMessage(message);

View File

@ -119,12 +119,9 @@ async function generateHorde(prompt, params) {
setGenerationProgress(100); setGenerationProgress(100);
const generatedText = statusCheckJson.generations[0].text; const generatedText = statusCheckJson.generations[0].text;
const WorkerName = statusCheckJson.generations[0].worker_name; const WorkerName = statusCheckJson.generations[0].worker_name;
if (WorkerName !== undefined) {
$("#chat").last('.mes').attr('title', `Generated by Horde worker: ${WorkerName}`);
}
console.log(generatedText); console.log(generatedText);
console.log(`Generated by Horde Worker: ${WorkerName}`); console.log(`Generated by Horde Worker: ${WorkerName}`);
return generatedText; return { text: generatedText, workerName: `Generated by Horde worker: ${WorkerName}` };
} }
else if (!queue_position_first) { else if (!queue_position_first) {
queue_position_first = statusCheckJson.queue_position; queue_position_first = statusCheckJson.queue_position;