mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge branch 'SL-TAI-RA-Mods' into dev
This commit is contained in:
@ -1,2 +0,0 @@
|
||||
{"user_name":"You","character_name":"Aqua","create_date":1674559896839}
|
||||
{"name":"Aqua","is_user":false,"is_name":true,"send_date":1674563371558,"mes":"*I am in the town square at a city named \"Axel\". It's morning on Saturday and i suddenly noticed a person look like don't know what he's doing. I approached to him and speak* Are you new here? Do you need help? Don't worry, I, aqua the goddess of water, shall help you! Do i look beautiful? *strikes a pose and look at him with puppy eyes*"}
|
@ -1,2 +0,0 @@
|
||||
{"user_name":"You","character_name":"Darkness","create_date":1674559899431}
|
||||
{"name":"Darkness","is_user":false,"is_name":true,"send_date":1674564914912,"mes":"*It's a sunny day, in a big park on which there are many people, some walking and others lying in the sun. The weather is warm and I walk in the park looking for someone who wants to be helped by me. Suddenly realise that someone is looking at me.* Hello, I am Darkness, a Crusader, and would you like some help?"}
|
@ -1,2 +0,0 @@
|
||||
{"user_name":"You","character_name":"Megumin","create_date":1674559900991}
|
||||
{"name":"Megumin","is_user":false,"is_name":true,"send_date":1674563153854,"mes":"*It was day, the weather was sunny and windless. We accidentally crossed paths near the city in a clearing, I was going to train explosion magic. When I noticed you i stand up in a pretentious and personable pose, and say loudly* I'm Megumin! The Arch Wizard of the Crimson Magic Clan! And i the best at explosion magic!! What are you doing here?"}
|
BIN
public/img/swipe_left.png
Normal file
BIN
public/img/swipe_left.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 497 B |
BIN
public/img/swipe_right.png
Normal file
BIN
public/img/swipe_right.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 520 B |
@ -754,6 +754,8 @@
|
||||
</label>
|
||||
<label for="force-pygmalion-formatting-checkbox"><input id="force-pygmalion-formatting-checkbox" type="checkbox" />
|
||||
<h4>Force Pygmalion formatting for any model</h4>
|
||||
<label for="swipes-checkbox"><input id="swipes-checkbox" type="checkbox" />
|
||||
<h4>Swipes</h4>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
671
public/script.js
671
public/script.js
@ -125,7 +125,12 @@ const system_messages = {
|
||||
is_user: false,
|
||||
is_system: true,
|
||||
is_name: true,
|
||||
mes: 'Hi there! The following chat formatting commands are supported:<br><ul><li><tt>*text*</tt> – format the actions that your character does</li><li><tt>{*text*}</tt> – set the behavioral bias for your character</li></ul><p>Need more help? Visit our wiki – <a target="_blank" href="https://github.com/TavernAI/TavernAI/wiki">TavernAI Wiki</a>!</p>',
|
||||
mes: `Hi there! The following chat formatting commands are supported:<br>
|
||||
<ul>
|
||||
<li><tt>*text*</tt> – format the actions that your character does</li>
|
||||
<li><tt>{*text*}</tt> – set the behavioral bias for your character</li>
|
||||
</ul>
|
||||
<p>Need more help? Visit our wiki – <a href=\"https://github.com/TavernAI/TavernAI/wiki\">TavernAI Wiki</a>!</p>`,
|
||||
},
|
||||
welcome:
|
||||
{
|
||||
@ -235,6 +240,8 @@ var if_typing_text = false;
|
||||
const tokens_cycle_count = 30;
|
||||
var cycle_count_generation = 0;
|
||||
|
||||
var swipes = false;
|
||||
|
||||
var anchor_order = 0;
|
||||
var style_anchor = true;
|
||||
var character_anchor = true;
|
||||
@ -490,15 +497,7 @@ function printCharacters() {
|
||||
this_avatar = "characters/" + item.avatar + "?" + Date.now();
|
||||
} //RossAscends: changed 'prepend' to 'append' to make alphabetical sorting display correctly.
|
||||
$("#rm_print_characters_block").append(
|
||||
"<div class=character_select chid=" +
|
||||
i +
|
||||
' id="CharID' +
|
||||
i +
|
||||
'"><div class=avatar><img src="' +
|
||||
this_avatar +
|
||||
'"></div><div class=ch_name>' +
|
||||
item.name +
|
||||
"</div></div>"
|
||||
`<div class=character_select chid=${i} id="CharID${i}"><div class=avatar><img src="${this_avatar}"></div><div class=ch_name>${item.name}</div></div>`
|
||||
);
|
||||
//console.log('printcharacters() -- printing -- ChID '+i+' ('+item.name+')');
|
||||
});
|
||||
@ -778,18 +777,33 @@ function addOneMessage(mes) {
|
||||
);
|
||||
const bias = messageFormating(mes.extra?.bias ?? "");
|
||||
|
||||
$("#chat").append(
|
||||
"<div class='mes' mesid=" +
|
||||
count_view_mes +
|
||||
" ch_name=" +
|
||||
var HTMLForEachMes =
|
||||
'<div class="mes" mesid="' + count_view_mes + '" ch_name="' + characterName + '" is_user="' + mes["is_user"] + '">' +
|
||||
'<div class="for_checkbox"></div>' +
|
||||
'<input type="checkbox" class="del_checkbox">' +
|
||||
'<div class="avatar">' +
|
||||
'<img src="' + avatarImg + '">' +
|
||||
'</div>' +
|
||||
'<div class="swipe_left">' +
|
||||
'<img src="img/swipe_left.png">' +
|
||||
'</div>' +
|
||||
'<div class="mes_block">' +
|
||||
'<div class="ch_name">' +
|
||||
characterName +
|
||||
"><div class='for_checkbox'></div><input type='checkbox' class='del_checkbox'><div class=avatar><img src='" +
|
||||
avatarImg +
|
||||
"'></div><div class=mes_block><div class=ch_name>" +
|
||||
characterName +
|
||||
"<div title=Edit class=mes_edit></div><div class=mes_edit_cancel><img src=img/cancel.png></div><div class=mes_edit_done><img src=img/done.png></div></div><div class=mes_text>" +
|
||||
`</div><div class='mes_bias'>${bias}</div></div></div>`
|
||||
);
|
||||
'<div title=Edit class=mes_edit></div>' +
|
||||
'<div class=mes_edit_cancel><img src=img/cancel.png></div>' +
|
||||
'<div class=mes_edit_done><img src=img/done.png></div>' +
|
||||
'</div>' +
|
||||
'<div class=mes_text></div>' +
|
||||
'</div>' +
|
||||
'<div class="mes_bias">' + bias + '</div>' +
|
||||
'<div class="swipe_right">' +
|
||||
' <img src="img/swipe_right.png">' +
|
||||
'</div>' +
|
||||
'</div>';
|
||||
if (type !== 'swipe') {
|
||||
$("#chat").append(HTMLForEachMes);
|
||||
}
|
||||
|
||||
const newMessage = $(`#chat [mesid="${count_view_mes}"]`);
|
||||
newMessage.data("isSystem", isSystem);
|
||||
@ -800,57 +814,64 @@ function addOneMessage(mes) {
|
||||
newMessage.find(".mes_edit").hide();
|
||||
}
|
||||
|
||||
newMessage.find('.avatar img').on('error', function() {
|
||||
newMessage.find('.avatar img').on('error', function () {
|
||||
$(this).attr("src", "/img/user-slash-solid.svg");
|
||||
$(this).css('filter', 'invert(1)');
|
||||
});
|
||||
|
||||
if (!if_typing_text) {
|
||||
//console.log(messageText);
|
||||
$("#chat")
|
||||
.children()
|
||||
.filter('[mesid="' + count_view_mes + '"]')
|
||||
.children(".mes_block")
|
||||
.children(".mes_text")
|
||||
.append(messageText);
|
||||
} else {
|
||||
typeWriter(
|
||||
$("#chat")
|
||||
.children()
|
||||
.filter('[mesid="' + count_view_mes + '"]')
|
||||
.children(".mes_block")
|
||||
.children(".mes_text"),
|
||||
messageText,
|
||||
50,
|
||||
0
|
||||
);
|
||||
//////// swipecode inside addOneMessage - to keep swipes displayed while
|
||||
// SWIPE BUTTON DISPLAY SHOULD BE HANDLED IN showSwipeButtons/hideSwipeButtons, not here. Commented out duplicate code.
|
||||
|
||||
//console.log('addOneMessage -- type = '+type);
|
||||
if (type === 'swipe') {
|
||||
//console.log('addOneMessage -- detected adding one swipe message')
|
||||
$("#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);
|
||||
|
||||
/* if(mes['swipe_id'] !== 0 && swipes){
|
||||
console.log('addOneMessage -- swipe_id is not 0, adding both buttons');
|
||||
$("#chat").children().filter('[mesid="'+(count_view_mes-1)+'"]').children('.swipe_right').css('display', 'flex');
|
||||
$("#chat").children().filter('[mesid="'+(count_view_mes-1)+'"]').children('.swipe_left').css('display', 'flex');
|
||||
} */
|
||||
} else { //if this is not a display of a new swipe message..
|
||||
//console.log('addOneMessage -- adding message');
|
||||
$("#chat").children().filter('[mesid="' + count_view_mes + '"]').children('.mes_block').children('.mes_text').append(messageText);
|
||||
//console.log('addOneMessage - hiding swipe buttons');
|
||||
hideSwipeButtons(); //disabling this leaves buttons visibile on all messages, breaks swipes
|
||||
//console.log('addOneMessage -- checking for swipes');
|
||||
/* if(parseInt(chat.length-1) === parseInt(count_view_mes) && !mes['is_user'] && swipes){
|
||||
console.log('chat length - 1 = '+(chat[chat.length-1]['mesid']));
|
||||
if(chat[chat.length-1]['mesid'] !==undefined){
|
||||
if(mes['swipe_id'] === undefined && count_view_mes !== 0){
|
||||
console.log('addOneMessage -- no swipes here, showing right button for possible generation');
|
||||
$("#chat").children().filter('[mesid="'+(count_view_mes)+'"]').children('.swipe_right').css('display', 'flex');
|
||||
}else if(mes['swipe_id'] !== undefined){ // if swipes aren't undefined == swipes exist at this node
|
||||
console.log('addOneMessage -- found swipes')
|
||||
if(mes['swipe_id'] === 0){ //if we are viewing the first swipe message, display right
|
||||
console.log('addOneMessage -- found lone swipe, displaying right button');
|
||||
$("#chat").children().filter('[mesid="'+(count_view_mes)+'"]').children('.swipe_right').css('display', 'flex');
|
||||
}else { // if swipe_id is more than 0, than means we must have multiple swipes, so show both items
|
||||
console.log('addOneMessage -- found multiple swipes, showing both buttons');
|
||||
$("#chat").children().filter('[mesid="'+(count_view_mes)+'"]').children('.swipe_right').css('display', 'flex');
|
||||
$("#chat").children().filter('[mesid="'+(count_view_mes)+'"]').children('.swipe_left').css('display', 'flex');
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{console.log('apparently no swipes found, and not a valid mesage to add hideSwipeButtons, so skipping');} */
|
||||
count_view_mes++;
|
||||
}
|
||||
count_view_mes++;
|
||||
//console.log('add mes without animation = '+add_mes_without_animation);
|
||||
//console.log(!add_mes_without_animation);
|
||||
if (!add_mes_without_animation) {
|
||||
console.log('adding mes with animation')
|
||||
//$('#chat').children().last().css('transition','all 2s ease-in-out');
|
||||
$('#chat').children().last().css("opacity", "1");
|
||||
//$('#chat').children().last().css('transition','all 2s ease-in-out');
|
||||
/* } */
|
||||
// if(type !== 'swipe'){count_view_mes++;}
|
||||
|
||||
|
||||
}else {
|
||||
console.log('add mes with animation was false, and is set to false again')
|
||||
add_mes_without_animation = false;
|
||||
}
|
||||
var $textchat = $("#chat");
|
||||
$('#chat .mes').last().addClass('last_mes');
|
||||
$('#chat .mes').eq(-2).removeClass('last_mes');
|
||||
//$('#chat').children().last().css("opacity", "1");
|
||||
$textchat.scrollTop(($textchat[0].scrollHeight));
|
||||
}
|
||||
|
||||
function typeWriter(target, text, speed, i) {
|
||||
if (i < text.length) {
|
||||
//target.append(text.charAt(i));
|
||||
target.html(target.html() + text.charAt(i));
|
||||
i++;
|
||||
setTimeout(() => typeWriter(target, text, speed, i), speed);
|
||||
}
|
||||
hideSwipeButtons(); //disabling this prevents left button from correctly removing on last message without swipe to the left...
|
||||
showSwipeButtons();
|
||||
}
|
||||
|
||||
function newMesPattern(name) {
|
||||
@ -886,6 +907,7 @@ function sendSystemMessage(type, text) {
|
||||
}
|
||||
|
||||
chat.push(newMessage);
|
||||
console.log('sendSystemMessage calls addOneMessage');
|
||||
addOneMessage(newMessage);
|
||||
is_send_press = false;
|
||||
}
|
||||
@ -912,6 +934,7 @@ function extractMessageBias(message) {
|
||||
|
||||
async function Generate(type, automatic_trigger) {
|
||||
//encode("dsfs").length
|
||||
console.log('Generate entered');
|
||||
tokens_already_generated = 0;
|
||||
message_already_generated = name2 + ": ";
|
||||
|
||||
@ -942,15 +965,14 @@ async function Generate(type, automatic_trigger) {
|
||||
if (chat[chat.length - 1]["is_user"]) {
|
||||
//If last message from You
|
||||
} else {
|
||||
//console.log('about to remove last msg')
|
||||
chat.length = chat.length - 1;
|
||||
count_view_mes -= 1;
|
||||
//$('#chat').children().last().css({'transition':'all 0.5s ease-in-out'});
|
||||
//$('#chat').children().last().css({'transform':'translateX(100vh) scale(0.1,0.1)'});
|
||||
//$('#chat').children().last().css({'opacity':'0'});
|
||||
setTimeout(function(){
|
||||
setTimeout(function () {
|
||||
$('#chat').children().last().remove();
|
||||
},1000);
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
@ -982,9 +1004,11 @@ async function Generate(type, automatic_trigger) {
|
||||
var topAnchorDepth = 8;
|
||||
|
||||
if (character_anchor && !is_pygmalion) {
|
||||
console.log('saw not pyg');
|
||||
if (anchor_order === 0) {
|
||||
anchorTop = name2 + " " + postAnchorChar;
|
||||
} else {
|
||||
console.log('saw pyg, adding anchors')
|
||||
anchorBottom = "[" + name2 + " " + postAnchorChar + "]";
|
||||
}
|
||||
}
|
||||
@ -1009,100 +1033,72 @@ async function Generate(type, automatic_trigger) {
|
||||
chat[chat.length - 1]["extra"] = {};
|
||||
|
||||
if (messageBias) {
|
||||
console.log('checking bias');
|
||||
chat[chat.length - 1]["extra"]["bias"] = messageBias;
|
||||
}
|
||||
|
||||
console.log('Generate calls addOneMessage');
|
||||
addOneMessage(chat[chat.length - 1]);
|
||||
}
|
||||
var chatString = "";
|
||||
var arrMes = [];
|
||||
var mesSend = [];
|
||||
var charDescription = $.trim(characters[this_chid].description);
|
||||
var charPersonality = $.trim(characters[this_chid].personality);
|
||||
var Scenario = $.trim(characters[this_chid].scenario);
|
||||
var mesExamples = $.trim(characters[this_chid].mes_example);
|
||||
var checkMesExample = $.trim(mesExamples.replace(/<START>/gi, "")); //for check length without tag
|
||||
if (checkMesExample.length == 0) mesExamples = "";
|
||||
var mesExamplesArray = [];
|
||||
//***Base replace***
|
||||
if (mesExamples !== undefined) {
|
||||
if (mesExamples.length > 0) {
|
||||
var charDescription = baseChatReplaceAndSplit($.trim(characters[this_chid].description), name1, name2);
|
||||
var charPersonality = baseChatReplaceAndSplit($.trim(characters[this_chid].personality), name1, name2);
|
||||
var Scenario = baseChatReplaceAndSplit($.trim(characters[this_chid].scenario), name1, name2);
|
||||
var mesExamples = baseChatReplaceAndSplit($.trim(characters[this_chid].mes_example.replace(/<START>/gi, '')), name1, name2);
|
||||
|
||||
function baseChatReplaceAndSplit(value, name1, name2) {
|
||||
if (value !== undefined && value.length > 0) {
|
||||
if (is_pygmalion) {
|
||||
mesExamples = mesExamples.replace(/{{user}}:/gi, "You:");
|
||||
mesExamples = mesExamples.replace(/<USER>:/gi, "You:");
|
||||
value = value.replace(/{{user}}:/gi, "You:");
|
||||
value = value.replace(/<USER>:/gi, "You:");
|
||||
}
|
||||
mesExamples = mesExamples.replace(/{{user}}/gi, name1);
|
||||
mesExamples = mesExamples.replace(/{{char}}/gi, name2);
|
||||
mesExamples = mesExamples.replace(/<USER>/gi, name1);
|
||||
mesExamples = mesExamples.replace(/<BOT>/gi, name2);
|
||||
//mesExamples = mesExamples.replaceAll('<START>', '[An example of how '+name2+' responds]');
|
||||
let blocks = mesExamples.split(/<START>/gi);
|
||||
mesExamplesArray = blocks
|
||||
.slice(1)
|
||||
.map((block) => `<START>\n${block.trim()}\n`);
|
||||
value = value.replace(/{{user}}/gi, name1);
|
||||
value = value.replace(/{{char}}/gi, name2);
|
||||
value = value.replace(/<USER>/gi, name1);
|
||||
value = value.replace(/<BOT>/gi, name2);
|
||||
let blocks = value.split(/<START>/gi);
|
||||
return blocks.slice(1).map(block => `<START>\n${block.trim()}\n`).join('');
|
||||
}
|
||||
return value;
|
||||
}
|
||||
if (charDescription !== undefined) {
|
||||
if (charDescription.length > 0) {
|
||||
charDescription = charDescription.replace(/{{user}}/gi, name1);
|
||||
charDescription = charDescription.replace(/{{char}}/gi, name2);
|
||||
charDescription = charDescription.replace(/<USER>/gi, name1);
|
||||
charDescription = charDescription.replace(/<BOT>/gi, name2);
|
||||
}
|
||||
}
|
||||
if (charPersonality !== undefined) {
|
||||
if (charPersonality.length > 0) {
|
||||
charPersonality = charPersonality.replace(/{{user}}/gi, name1);
|
||||
charPersonality = charPersonality.replace(/{{char}}/gi, name2);
|
||||
charPersonality = charPersonality.replace(/<USER>/gi, name1);
|
||||
charPersonality = charPersonality.replace(/<BOT>/gi, name2);
|
||||
}
|
||||
}
|
||||
if (Scenario !== undefined) {
|
||||
if (Scenario.length > 0) {
|
||||
Scenario = Scenario.replace(/{{user}}/gi, name1);
|
||||
Scenario = Scenario.replace(/{{char}}/gi, name2);
|
||||
Scenario = Scenario.replace(/<USER>/gi, name1);
|
||||
Scenario = Scenario.replace(/<BOT>/gi, name2);
|
||||
|
||||
function appendToStoryString(value, prefix) {
|
||||
if (value !== undefined && value.length > 0) {
|
||||
return prefix + value + '\n';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
if (is_pygmalion) {
|
||||
if (charDescription.length > 0) {
|
||||
storyString = name2 + "'s Persona: " + charDescription + "\n";
|
||||
}
|
||||
if (charPersonality.length > 0) {
|
||||
storyString += "Personality: " + charPersonality + "\n";
|
||||
}
|
||||
if (Scenario.length > 0) {
|
||||
storyString += "Scenario: " + Scenario + "\n";
|
||||
}
|
||||
storyString += appendToStoryString(charDescription, name2 + "'s Persona: ");
|
||||
storyString += appendToStoryString(charPersonality, 'Personality: ');
|
||||
storyString += appendToStoryString(Scenario, 'Scenario: ');
|
||||
} else {
|
||||
if (charDescription !== undefined) {
|
||||
if (charPersonality.length > 0) {
|
||||
charPersonality = name2 + "'s personality: " + charPersonality; //"["+name2+"'s personality: "+charPersonality+"]";
|
||||
}
|
||||
}
|
||||
if (charDescription !== undefined) {
|
||||
if ($.trim(charDescription).length > 0) {
|
||||
if (
|
||||
charDescription.slice(-1) !== "]" ||
|
||||
charDescription.substr(0, 1) !== "["
|
||||
) {
|
||||
//charDescription = '['+charDescription+']';
|
||||
}
|
||||
storyString += charDescription + "\n";
|
||||
charPersonality = name2 + "'s personality: " + charPersonality;
|
||||
}
|
||||
}
|
||||
|
||||
storyString += appendToStoryString(charDescription, '');
|
||||
|
||||
if (storyString.endsWith('\n')) {
|
||||
storyString = storyString.slice(0, -1);
|
||||
}
|
||||
|
||||
if (count_view_mes < topAnchorDepth) {
|
||||
storyString += charPersonality + "\n";
|
||||
storyString += '\n' + appendToStoryString(charPersonality, '');
|
||||
}
|
||||
}
|
||||
|
||||
var count_exm_add = 0;
|
||||
console.log('emptying chat2');
|
||||
var chat2 = [];
|
||||
var j = 0;
|
||||
console.log('pre-replace chat.length = ' + chat.length);
|
||||
for (var i = chat.length - 1; i >= 0; i--) {
|
||||
if (j == 0) {
|
||||
chat[j]["mes"] = chat[j]["mes"].replace(/{{user}}/gi, name1);
|
||||
@ -1129,6 +1125,7 @@ async function Generate(type, automatic_trigger) {
|
||||
chat2[i] = (chat2[i] ?? "").replace(/{([^}]+)}/g, "");
|
||||
j++;
|
||||
}
|
||||
console.log('post replace chat.length = ' + chat.length);
|
||||
//chat2 = chat2.reverse();
|
||||
var this_max_context = 1487;
|
||||
if (main_api == "kobold") this_max_context = max_context;
|
||||
@ -1147,6 +1144,16 @@ async function Generate(type, automatic_trigger) {
|
||||
|
||||
let extension_prompt = getExtensionPrompt();
|
||||
|
||||
/////////////////////// swipecode
|
||||
if (type == 'swipe') {
|
||||
|
||||
console.log('pre swipe shift: ' + chat2.length);
|
||||
console.log('shifting swipe chat2');
|
||||
chat2.shift();
|
||||
|
||||
}
|
||||
console.log('post swipe shift:' + chat2.length);
|
||||
|
||||
var i = 0;
|
||||
|
||||
for (var item of chat2) {
|
||||
@ -1173,6 +1180,7 @@ async function Generate(type, automatic_trigger) {
|
||||
//if (is_pygmalion && i == chat2.length-1) item='<START>\n'+item;
|
||||
arrMes[arrMes.length] = item;
|
||||
} else {
|
||||
console.log('reducing chat.length by 1');
|
||||
i = chat.length - 1;
|
||||
}
|
||||
await delay(1); //For disable slow down (encode gpt-2 need fix)
|
||||
@ -1183,6 +1191,7 @@ async function Generate(type, automatic_trigger) {
|
||||
let mesExmString = "";
|
||||
for (let iii = 0; iii < mesExamplesArray.length; iii++) {
|
||||
//mesExamplesArray It need to make from end to start
|
||||
console.log('checking prompt tokens');
|
||||
mesExmString = mesExmString + mesExamplesArray[iii];
|
||||
if (
|
||||
encode(
|
||||
@ -1233,8 +1242,10 @@ async function Generate(type, automatic_trigger) {
|
||||
}
|
||||
|
||||
function runGenerate(cycleGenerationPromt = "") {
|
||||
console.log('rungenerate entered');
|
||||
generatedPromtCache += cycleGenerationPromt;
|
||||
if (generatedPromtCache.length == 0) {
|
||||
console.log('generating prompt');
|
||||
chatString = "";
|
||||
arrMes = arrMes.reverse();
|
||||
var is_add_personality = false;
|
||||
@ -1389,6 +1400,8 @@ async function Generate(type, automatic_trigger) {
|
||||
generatedPromtCache +
|
||||
promptBias;
|
||||
finalPromt = finalPromt.replace(/\r/gm, "");
|
||||
console.log('final prompt decided');
|
||||
|
||||
|
||||
//if we aren't using the kobold GUI settings...
|
||||
if (
|
||||
@ -1621,42 +1634,77 @@ async function Generate(type, automatic_trigger) {
|
||||
if (type === "force_name2") this_mes_is_name = true;
|
||||
//getMessage = getMessage.replace(/^\s+/g, '');
|
||||
if (getMessage.length > 0) {
|
||||
chat[chat.length] = {};
|
||||
chat[chat.length - 1]["name"] = name2;
|
||||
chat[chat.length - 1]["is_user"] = false;
|
||||
chat[chat.length - 1]["is_name"] = this_mes_is_name;
|
||||
chat[chat.length - 1]["send_date"] = humanizedDateTime();
|
||||
getMessage = $.trim(getMessage);
|
||||
chat[chat.length - 1]["mes"] = getMessage;
|
||||
if (chat[chat.length - 1]['swipe_id'] === undefined ||
|
||||
chat[chat.length - 1]['is_user']) { type = 'normal'; }
|
||||
if (type === 'swipe') {
|
||||
|
||||
if (selected_group) {
|
||||
let avatarImg = default_avatar;
|
||||
if (characters[this_chid].avatar != "none") {
|
||||
avatarImg = `characters/${characters[this_chid].avatar}?${Date.now()}`;
|
||||
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) {
|
||||
//console.log(getMessage);
|
||||
chat[chat.length - 1]['mes'] = getMessage;
|
||||
console.log('runGenerate calls addOneMessage for swipe');
|
||||
addOneMessage(chat[chat.length - 1], 'swipe');
|
||||
} else {
|
||||
chat[chat.length - 1]['mes'] = getMessage;
|
||||
}
|
||||
chat[chat.length - 1]["is_name"] = true;
|
||||
chat[chat.length - 1]["force_avatar"] = avatarImg;
|
||||
}
|
||||
|
||||
addOneMessage(chat[chat.length - 1]);
|
||||
$("#send_but").css("display", "inline");
|
||||
$("#loading_mes").css("display", "none");
|
||||
|
||||
if (selected_group) {
|
||||
saveGroupChat(selected_group);
|
||||
is_send_press = false;
|
||||
} else {
|
||||
saveChat();
|
||||
console.log('entering chat update routine for non-swipe post');
|
||||
is_send_press = false;
|
||||
chat[chat.length] = {};
|
||||
chat[chat.length - 1]["name"] = name2;
|
||||
chat[chat.length - 1]["is_user"] = false;
|
||||
chat[chat.length - 1]["is_name"] = this_mes_is_name;
|
||||
chat[chat.length - 1]["send_date"] = humanizedDateTime();
|
||||
getMessage = $.trim(getMessage);
|
||||
chat[chat.length - 1]["mes"] = getMessage;
|
||||
|
||||
if (selected_group) {
|
||||
console.log('entering chat update for groups');
|
||||
let avatarImg = default_avatar;
|
||||
if (characters[this_chid].avatar != "none") {
|
||||
avatarImg = `characters/${characters[this_chid].avatar}?${Date.now()}`;
|
||||
}
|
||||
chat[chat.length - 1]["is_name"] = true;
|
||||
chat[chat.length - 1]["force_avatar"] = avatarImg;
|
||||
}
|
||||
|
||||
console.log('runGenerate calls addOneMessage');
|
||||
addOneMessage(chat[chat.length - 1]);
|
||||
console.log('should hide loading mes and return with send button now');
|
||||
$("#send_but").css("display", "inline");
|
||||
$("#loading_mes").css("display", "none");
|
||||
|
||||
if (selected_group) {
|
||||
saveGroupChat(selected_group);
|
||||
} /*else {
|
||||
saveChat();
|
||||
}*/
|
||||
//console.log('/savechat called by /Generate');
|
||||
//let final_message_length = encode(JSON.stringify(getMessage)).length;
|
||||
//console.log('AI Response: +'+getMessage+ '('+final_message_length+' tokens)');
|
||||
}
|
||||
//console.log('/savechat called by /Generate');
|
||||
//let final_message_length = encode(JSON.stringify(getMessage)).length;
|
||||
//console.log('AI Response: +'+getMessage+ '('+final_message_length+' tokens)');
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
Generate("force_name2");
|
||||
}
|
||||
} else {
|
||||
console.log('final re-setting of send button due to error');
|
||||
$("#send_but").css("display", "inline");
|
||||
$("#loading_mes").css("display", "none");
|
||||
showSwipeButtons();
|
||||
}
|
||||
|
||||
console.log('/savechat called by /Generate');
|
||||
saveChat();
|
||||
//let final_message_length = encode(JSON.stringify(getMessage)).length;
|
||||
//console.log('AI Response: +'+getMessage+ '('+final_message_length+' tokens)');
|
||||
|
||||
$("#send_but").css("display", "inline");
|
||||
console.log('attempting to show swipes');
|
||||
showSwipeButtons();
|
||||
|
||||
$("#loading_mes").css("display", "none");
|
||||
},
|
||||
error: function (jqXHR, exception) {
|
||||
$("#send_textarea").removeAttr("disabled");
|
||||
@ -1758,10 +1806,13 @@ async function saveChat() {
|
||||
alert('Trying to save group chat with regular saveChat function. Aborting to prevent corruption.');
|
||||
throw new Error('Group chat saved from saveChat');
|
||||
}
|
||||
if (item["is_user"]) {
|
||||
var str = item["mes"].replace(name1 + ":", default_user_name + ":");
|
||||
chat[i]["mes"] = str;
|
||||
chat[i]["name"] = default_user_name;
|
||||
if (item.is_user) {
|
||||
var str = item.mes.replace(`${name1}:`, `${default_user_name}:`);
|
||||
chat[i].mes = str;
|
||||
chat[i].name = default_user_name;
|
||||
} else if (i !== chat.length - 1 && chat[i].swipe_id !== undefined) {
|
||||
delete chat[i].swipes;
|
||||
delete chat[i].swipe_id;
|
||||
}
|
||||
});
|
||||
var save_chat = [
|
||||
@ -1836,12 +1887,8 @@ async function getChat() {
|
||||
//console.log(data);
|
||||
//chat.length = 0;
|
||||
if (data[0] !== undefined) {
|
||||
for (let key in data) {
|
||||
chat.push(data[key]);
|
||||
}
|
||||
//chat = data;
|
||||
chat_create_date = chat[0]["create_date"];
|
||||
//console.log('/getchat saw chat_create_date: '+chat_create_date);
|
||||
chat.push(...response);
|
||||
chat_create_date = chat[0]['create_date'];
|
||||
chat.shift();
|
||||
} else {
|
||||
chat_create_date = humanizedDateTime();
|
||||
@ -1860,25 +1907,22 @@ async function getChat() {
|
||||
function getChatResult() {
|
||||
name2 = characters[this_chid].name;
|
||||
if (chat.length > 1) {
|
||||
chat.forEach(function (item, i) {
|
||||
for (let i = 0; i < chat.length; i++) {
|
||||
const item = chat[i];
|
||||
if (item["is_user"]) {
|
||||
var str = item["mes"].replace(default_user_name + ":", name1 + ":");
|
||||
chat[i]["mes"] = str;
|
||||
chat[i]["name"] = name1;
|
||||
item['mes'] = item['mes'].replace(default_user_name + ':', name1 + ':');
|
||||
item['name'] = name1;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
//console.log(characters[this_chid].first_mes);
|
||||
chat[0] = {};
|
||||
chat[0]["name"] = name2;
|
||||
chat[0]["is_user"] = false;
|
||||
chat[0]["is_name"] = true;
|
||||
chat[0]["send_date"] = humanizedDateTime();
|
||||
if (characters[this_chid].first_mes != "") {
|
||||
chat[0]["mes"] = characters[this_chid].first_mes;
|
||||
} else {
|
||||
chat[0]["mes"] = default_ch_mes;
|
||||
}
|
||||
} else {
|
||||
const firstMes = characters[this_chid].first_mes || default_ch_mes;
|
||||
chat[0] = {
|
||||
name: name2,
|
||||
is_user: false,
|
||||
is_name: true,
|
||||
send_date: humanizedDateTime(),
|
||||
mes: firstMes
|
||||
};
|
||||
}
|
||||
printMessages();
|
||||
select_selected_character(this_chid);
|
||||
@ -2104,6 +2148,12 @@ async function getSettings(type) {
|
||||
$("#rep_pen_size").val(rep_pen_size);
|
||||
$("#rep_pen_size_counter").html(rep_pen_size + " Tokens");
|
||||
|
||||
swipes = !!settings.swipes; //// swipecode
|
||||
$('#swipes-checkbox').prop('checked', swipes); /// swipecode
|
||||
console.log('getSettings -- swipes = ' + swipes + '. toggling box');
|
||||
hideSwipeButtons();
|
||||
showSwipeButtons();
|
||||
|
||||
//Novel
|
||||
temp_novel = settings.temp_novel;
|
||||
rep_pen_novel = settings.rep_pen_novel;
|
||||
@ -2265,6 +2315,7 @@ async function saveSettings(type) {
|
||||
world_info_budget: world_info_budget,
|
||||
active_character: active_character,
|
||||
textgenerationwebui_settings: textgenerationwebui_settings,
|
||||
swipes: swipes,
|
||||
}),
|
||||
beforeSend: function () {
|
||||
//console.log('saveSettings() -- active_character -- '+active_character);
|
||||
@ -2520,7 +2571,7 @@ function selectRightMenuWithAnimation(selectedMenuId) {
|
||||
function setRightTabSelectedClass(selectedButtonId) {
|
||||
document.querySelectorAll('#right-nav-panel-tabs .right_menu_button').forEach((button) => {
|
||||
button.classList.remove('selected-right-tab');
|
||||
|
||||
|
||||
if (selectedButtonId && selectedButtonId.replace('#', '') === button.id) {
|
||||
button.classList.add('selected-right-tab');
|
||||
}
|
||||
@ -2771,6 +2822,238 @@ window["TavernAI"].getContext = function () {
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
$('#swipes-checkbox').change(function () {
|
||||
console.log('detected swipes-checkbox changed values')
|
||||
swipes = !!$('#swipes-checkbox').prop('checked');
|
||||
if (swipes) {
|
||||
showSwipeButtons();
|
||||
} else {
|
||||
hideSwipeButtons();
|
||||
}
|
||||
});
|
||||
|
||||
///// SWIPE BUTTON CLICKS ///////
|
||||
|
||||
$(document).on('click', '.swipe_right', function () { //when we click swipe right button
|
||||
const swipe_duration = 120;
|
||||
const swipe_range = 700;
|
||||
//console.log(swipe_range);
|
||||
let run_generate = false;
|
||||
let run_swipe_right = false;
|
||||
if (chat[chat.length - 1]['swipe_id'] === undefined) { // if there is no swipe-message in the last spot of the chat array
|
||||
chat[chat.length - 1]['swipe_id'] = 0; // set it to id 0
|
||||
chat[chat.length - 1]['swipes'] = []; // empty the array
|
||||
chat[chat.length - 1]['swipes'][0] = chat[chat.length - 1]['mes']; //assign swipe array with last message from chat
|
||||
}
|
||||
chat[chat.length - 1]['swipe_id']++; //make new slot in array
|
||||
//console.log(chat[chat.length-1]['swipes']);
|
||||
if (parseInt(chat[chat.length - 1]['swipe_id']) === chat[chat.length - 1]['swipes'].length) { //if swipe id of last message is the same as the length of the 'swipes' array
|
||||
run_generate = true;
|
||||
} 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
|
||||
run_swipe_right = true; //then swipe
|
||||
}
|
||||
|
||||
if (chat[chat.length - 1]['swipe_id'] > chat[chat.length - 1]['swipes'].length) { //if we swipe right while generating (the swipe ID is greater than what we are viewing now)
|
||||
chat[chat.length - 1]['swipe_id'] = chat[chat.length - 1]['swipes'].length; //show that message slot (will be '...' while generating)
|
||||
}
|
||||
if (run_generate) { //hide swipe arrows while generating
|
||||
$(this).css('display', 'none');
|
||||
|
||||
}
|
||||
if (run_generate || run_swipe_right) { // handles animated transitions when swipe right, specifically height transitions between messages
|
||||
|
||||
let this_mes_div = $(this).parent();
|
||||
let this_mes_block = $(this).parent().children('.mes_block').children('.mes_text');
|
||||
const this_mes_div_height = this_mes_div[0].scrollHeight;
|
||||
const this_mes_block_height = this_mes_block[0].scrollHeight;
|
||||
|
||||
this_mes_div.children('.swipe_left').css('display', 'flex');
|
||||
this_mes_div.children('.mes_block').transition({ // this moves the div back and forth
|
||||
x: '-' + swipe_range,
|
||||
duration: swipe_duration,
|
||||
easing: animation_rm_easing,
|
||||
queue: false,
|
||||
complete: function () {
|
||||
|
||||
const is_animation_scroll = ($('#chat').scrollTop() >= ($('#chat').prop("scrollHeight") - $('#chat').outerHeight()) - 10);
|
||||
//console.log(parseInt(chat[chat.length-1]['swipe_id']));
|
||||
//console.log(chat[chat.length-1]['swipes'].length);
|
||||
if (run_generate && parseInt(chat[chat.length - 1]['swipe_id']) === chat[chat.length - 1]['swipes'].length) {
|
||||
//console.log('showing ...');
|
||||
$("#chat").children().filter('[mesid="' + (count_view_mes - 1) + '"]').children('.mes_block').children('.mes_text').html('...'); //shows ... while generating
|
||||
} else {
|
||||
//console.log('showing previously generated swipe candidate, or "..."');
|
||||
addOneMessage(chat[chat.length - 1], 'swipe');
|
||||
}
|
||||
let new_height = this_mes_div_height - (this_mes_block_height - this_mes_block[0].scrollHeight);
|
||||
if (new_height < 103) new_height = 103;
|
||||
|
||||
|
||||
this_mes_div.animate({ height: new_height + 'px' }, {
|
||||
duration: 100,
|
||||
queue: false,
|
||||
progress: function () {
|
||||
// Scroll the chat down as the message expands
|
||||
if (is_animation_scroll) $("#chat").scrollTop($("#chat")[0].scrollHeight);
|
||||
},
|
||||
complete: function () {
|
||||
this_mes_div.css('height', 'auto');
|
||||
// Scroll the chat down to the bottom once the animation is complete
|
||||
if (is_animation_scroll) $("#chat").scrollTop($("#chat")[0].scrollHeight);
|
||||
}
|
||||
});
|
||||
this_mes_div.children('.mes_block').transition({
|
||||
x: swipe_range,
|
||||
duration: 0,
|
||||
easing: animation_rm_easing,
|
||||
queue: false,
|
||||
complete: function () {
|
||||
this_mes_div.children('.mes_block').transition({
|
||||
x: '0px',
|
||||
duration: swipe_duration,
|
||||
easing: animation_rm_easing,
|
||||
queue: false,
|
||||
complete: function () {
|
||||
if (run_generate && !is_send_press && parseInt(chat[chat.length - 1]['swipe_id']) === chat[chat.length - 1]['swipes'].length) {
|
||||
console.log('caught here 2');
|
||||
is_send_press = true;
|
||||
Generate('swipe');
|
||||
} else {
|
||||
if (parseInt(chat[chat.length - 1]['swipe_id']) !== chat[chat.length - 1]['swipes'].length) {
|
||||
console.log('caught here 3');
|
||||
saveChat();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$(this).parent().children('.avatar').transition({ // moves avatar aong with swipe
|
||||
x: '-' + swipe_range,
|
||||
duration: swipe_duration,
|
||||
easing: animation_rm_easing,
|
||||
queue: false,
|
||||
complete: function () {
|
||||
$(this).parent().children('.avatar').transition({
|
||||
x: swipe_range,
|
||||
duration: 0,
|
||||
easing: animation_rm_easing,
|
||||
queue: false,
|
||||
complete: function () {
|
||||
$(this).parent().children('.avatar').transition({
|
||||
x: '0px',
|
||||
duration: swipe_duration,
|
||||
easing: animation_rm_easing,
|
||||
queue: false,
|
||||
complete: function () {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$(document).on('click', '.swipe_left', function () { // when we swipe left..but no generation.
|
||||
const swipe_duration = 120;
|
||||
const swipe_range = '700px';
|
||||
chat[chat.length - 1]['swipe_id']--;
|
||||
if (chat[chat.length - 1]['swipe_id'] >= 0) { // hide the left arrow if we are viewing the first candidate of the last message block
|
||||
$(this).parent().children('swipe_right_button').css('display', 'flex');
|
||||
if (chat[chat.length - 1]['swipe_id'] === 0) {
|
||||
$(this).css('display', 'none');
|
||||
}
|
||||
|
||||
let this_mes_div = $(this).parent();
|
||||
let this_mes_block = $(this).parent().children('.mes_block').children('.mes_text');
|
||||
const this_mes_div_height = this_mes_div[0].scrollHeight;
|
||||
this_mes_div.css('height', this_mes_div_height);
|
||||
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']];
|
||||
$(this).parent().children('.mes_block').transition({
|
||||
x: swipe_range,
|
||||
duration: swipe_duration,
|
||||
easing: animation_rm_easing,
|
||||
queue: false,
|
||||
complete: function () {
|
||||
const is_animation_scroll = ($('#chat').scrollTop() >= ($('#chat').prop("scrollHeight") - $('#chat').outerHeight()) - 10);
|
||||
console.log('sipwing left after tr5ansition calls addOneMessage');
|
||||
addOneMessage(chat[chat.length - 1], 'swipe');
|
||||
let new_height = this_mes_div_height - (this_mes_block_height - this_mes_block[0].scrollHeight);
|
||||
if (new_height < 103) new_height = 103;
|
||||
this_mes_div.animate({ height: new_height + 'px' }, {
|
||||
duration: 100,
|
||||
queue: false,
|
||||
progress: function () {
|
||||
// Scroll the chat down as the message expands
|
||||
|
||||
if (is_animation_scroll) $("#chat").scrollTop($("#chat")[0].scrollHeight);
|
||||
},
|
||||
complete: function () {
|
||||
this_mes_div.css('height', 'auto');
|
||||
// Scroll the chat down to the bottom once the animation is complete
|
||||
if (is_animation_scroll) $("#chat").scrollTop($("#chat")[0].scrollHeight);
|
||||
}
|
||||
});
|
||||
$(this).parent().children('.mes_block').transition({
|
||||
x: '-' + swipe_range,
|
||||
duration: 0,
|
||||
easing: animation_rm_easing,
|
||||
queue: false,
|
||||
complete: function () {
|
||||
$(this).parent().children('.mes_block').transition({
|
||||
x: '0px',
|
||||
duration: swipe_duration,
|
||||
easing: animation_rm_easing,
|
||||
queue: false,
|
||||
complete: function () {
|
||||
saveChat();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$(this).parent().children('.avatar').transition({
|
||||
x: swipe_range,
|
||||
duration: swipe_duration,
|
||||
easing: animation_rm_easing,
|
||||
queue: false,
|
||||
complete: function () {
|
||||
$(this).parent().children('.avatar').transition({
|
||||
x: '-' + swipe_range,
|
||||
duration: 0,
|
||||
easing: animation_rm_easing,
|
||||
queue: false,
|
||||
complete: function () {
|
||||
$(this).parent().children('.avatar').transition({
|
||||
x: '0px',
|
||||
duration: swipe_duration,
|
||||
easing: animation_rm_easing,
|
||||
queue: false,
|
||||
complete: function () {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
if (chat[chat.length - 1]['swipe_id'] < 0) {
|
||||
chat[chat.length - 1]['swipe_id'] = 0;
|
||||
}
|
||||
});
|
||||
|
||||
$("#character_search_bar").on("input", function () {
|
||||
const selector = ['#rm_print_characters_block .character_select', '#rm_print_characters_block .group_select'].join(',');
|
||||
const searchValue = $(this).val().trim().toLowerCase();
|
||||
@ -2790,8 +3073,8 @@ $(document).ready(function () {
|
||||
window.open("https://boosty.to/tavernai", "_blank");
|
||||
});
|
||||
$("#send_but").click(function () {
|
||||
//$( "#send_but" ).css({"background": "url('img/load.gif')","background-size": "100%, 100%", "background-position": "center center"});
|
||||
if (is_send_press == false) {
|
||||
hideSwipeButtons();
|
||||
is_send_press = true;
|
||||
|
||||
Generate();
|
||||
@ -2806,12 +3089,8 @@ $(document).ready(function () {
|
||||
//maybe a way to simulate this would be to disable the eventListener for people iOS.
|
||||
|
||||
$("#send_textarea").keydown(function (e) {
|
||||
if (
|
||||
!e.shiftKey &&
|
||||
!e.ctrlKey &&
|
||||
e.key == "Enter" &&
|
||||
is_send_press == false
|
||||
) {
|
||||
if (!e.shiftKey && !e.ctrlKey && e.key == "Enter" && is_send_press == false) {
|
||||
hideSwipeButtons();
|
||||
is_send_press = true;
|
||||
e.preventDefault();
|
||||
Generate();
|
||||
@ -3467,6 +3746,7 @@ $(document).ready(function () {
|
||||
|
||||
$("#option_regenerate").click(function () {
|
||||
if (is_send_press == false) {
|
||||
hideSwipeButtons();
|
||||
is_send_press = true;
|
||||
Generate("regenerate");
|
||||
}
|
||||
@ -3474,6 +3754,7 @@ $(document).ready(function () {
|
||||
|
||||
// this function hides the input form, and shows the delete/cancel buttons for deleting messages from chat
|
||||
$("#option_delete_mes").click(function () {
|
||||
hideSwipeButtons();
|
||||
if (
|
||||
(this_chid != undefined && !is_send_press) ||
|
||||
(selected_group && !is_group_generating)
|
||||
@ -3500,6 +3781,7 @@ $(document).ready(function () {
|
||||
$(this).prop("checked", false);
|
||||
});
|
||||
this_del_mes = 0;
|
||||
showSwipeButtons();
|
||||
});
|
||||
|
||||
//confirms message delation with the "ok" button
|
||||
@ -3528,6 +3810,9 @@ $(document).ready(function () {
|
||||
$textchat.scrollTop($textchat[0].scrollHeight);
|
||||
}
|
||||
this_del_mes = 0;
|
||||
$('#chat .mes').last().addClass('last_mes');
|
||||
$('#chat .mes').eq(-2).removeClass('last_mes');
|
||||
showSwipeButtons();
|
||||
});
|
||||
|
||||
$("#settings_perset").change(function () {
|
||||
@ -3778,6 +4063,16 @@ $(document).ready(function () {
|
||||
.children(".mes_block")
|
||||
.children(".ch_name")
|
||||
.children(".mes_edit_done");
|
||||
if (edit_mes_id == count_view_mes - 1) { //if the generating swipe (...)
|
||||
if (chat[edit_mes_id]['swipe_id'] !== undefined) {
|
||||
if (chat[edit_mes_id]['swipes'].length === chat[edit_mes_id]['swipe_id']) {
|
||||
run_edit = false;
|
||||
}
|
||||
}
|
||||
if (run_edit) {
|
||||
hideSwipeButtons();
|
||||
}
|
||||
}
|
||||
messageEditDone(mes_edited);
|
||||
}
|
||||
$(this).parent().parent().children(".mes_text").empty();
|
||||
|
@ -40,7 +40,21 @@ var create_save_scenario;
|
||||
var create_save_mes_example;
|
||||
var count_tokens;
|
||||
var perm_tokens;
|
||||
var ALC_Done;
|
||||
|
||||
const observerConfig = { childList: true, subtree: true };
|
||||
|
||||
const observer = new MutationObserver(function(mutations) {
|
||||
mutations.forEach(function(mutation) {
|
||||
if (mutation.target.id === "online_status_text2") {
|
||||
RA_checkOnlineStatus();
|
||||
} else if (mutation.target.parentNode === SelectedCharacterTab) {
|
||||
setTimeout(RA_CountCharTokens, 200);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
observer.observe(document.documentElement, observerConfig);
|
||||
|
||||
|
||||
//RossAscends: Added function to format dates used in files and chat timestamps to a humanized format.
|
||||
//Mostly I wanted this to be for file names, but couldn't figure out exactly where the filename save code was as everything seemed to be connected.
|
||||
@ -64,7 +78,6 @@ export function humanizedDateTime() {
|
||||
return HumanizedDateTime;
|
||||
}
|
||||
|
||||
//RA_CountCharTokens -- faster counting characters. Works for unsaved characters, and counts permanent and ephemeral tokens separately.
|
||||
|
||||
// triggers:
|
||||
$("#rm_button_create").on("click", function () { //when "+New Character" is clicked
|
||||
@ -79,15 +92,8 @@ $("#rm_button_create").on("click", function () { //when "+New Character" is
|
||||
create_save_mes_example="";
|
||||
$("#result_info").html('Type to start counting tokens!');
|
||||
});
|
||||
$(SelectedCharacterTab).children("h2").on("DOMSubtreeModified", function () { // when the nav's 3rd panel tab header changes (when a char is selected from the char list)
|
||||
//console.log('3rd tab name changed - counting tokens');
|
||||
//SaveLocal('ActiveChar',active_character);
|
||||
setTimeout(RA_CountCharTokens,200); //delay to allow textareas to fill out, so we don't show a previous char's count
|
||||
});
|
||||
|
||||
$("#rm_ch_create_block").on("input", function () {RA_CountCharTokens();}); //when any input is made to the create/edit character form textareas
|
||||
$("#character_popup").on("input", function () {RA_CountCharTokens();}); //when any input is made to the advanced editing popup textareas
|
||||
|
||||
//function:
|
||||
function RA_CountCharTokens() {
|
||||
$("#result_info").html("");
|
||||
@ -151,9 +157,6 @@ function RA_CountCharTokens() {
|
||||
$("#result_info").html(count_tokens + " Tokens (" + perm_tokens + " Permanent Tokens)"); //display normal if both counts are under 1024
|
||||
} else {$("#result_info").html("<font color=red>" +count_tokens +" Tokens (" +perm_tokens +" Permanent Tokens)(TOO MANY)</font>");} //warn if either are over 1024
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Auto Load Last Charcter -- (fires when active_character is defined and auto_load_chat is true)
|
||||
async function RA_autoloadchat() {
|
||||
if (document.getElementById('CharID0') !== null){
|
||||
@ -170,7 +173,6 @@ async function RA_autoloadchat() {
|
||||
setTimeout(RA_autoloadchat,100) // if the charcter list hadn't been loaded yet, try again.
|
||||
}
|
||||
}
|
||||
|
||||
//only triggers when AutoLoadChat is enabled, consider adding this as an independent feature later.
|
||||
function RestoreNavTab(){
|
||||
if($(rm_button_selected_ch).children("h2").text()!==''){ //check for a change in the character edit tab name
|
||||
@ -180,9 +182,7 @@ function RestoreNavTab(){
|
||||
setTimeout(RestoreNavTab,100) //if not changed yet, check again after 100ms
|
||||
}
|
||||
}
|
||||
|
||||
//changes input bar and send button display depending on connection status
|
||||
$("#online_status_text2").on("DOMSubtreeModified", function () {RA_checkOnlineStatus();});
|
||||
function RA_checkOnlineStatus() {
|
||||
if (online_status == "no_connection") {
|
||||
$("#send_textarea").attr("placeholder", "Not connected to API!"); //Input bar placeholder tells users they are not connected
|
||||
@ -199,66 +199,44 @@ function RA_checkOnlineStatus() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Auto-connect to API (when set to kobold, API URL exists, and auto_connect is true)
|
||||
function RA_autoconnect() {
|
||||
//console.log('RA_AC -- starting..')
|
||||
if(online_status !== undefined && api_server !== ''){
|
||||
if (online_status == "no_connection") {
|
||||
if (LoadLocalBool('AutoConnectEnabled') === true) {
|
||||
if (main_api === "kobold") {
|
||||
if (api_server !== "") {
|
||||
$("#api_url_text").val(api_server);
|
||||
console.log('clicking API-button');
|
||||
$("#api_button").click();
|
||||
//console.log("clicked KAI connect for you");
|
||||
} else {
|
||||
console.log(main_api+' '+api_server);
|
||||
console.log("RA_AC - KAI API not specificed");
|
||||
}
|
||||
} else {
|
||||
//console.log("RA_AC - not kobold. skipping to novel.");
|
||||
}
|
||||
|
||||
if (main_api === "novel") {
|
||||
if (api_key_novel !== "") {
|
||||
$("#api_key_novel").val(api_key_novel);
|
||||
console.log('clicking novel API-button');
|
||||
$("#api_button").click();
|
||||
// console.log("clicked NAI connect for you");
|
||||
} else {
|
||||
console.log("RA_AC - no novel API key");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log("RA_AC - is disabled. stopping.");
|
||||
|
||||
function RA_autoconnect() {
|
||||
if (typeof online_status !== 'undefined' && (api_server !== '' || api_key_novel !== '')) {
|
||||
if (online_status === "no_connection" && LoadLocalBool('AutoConnectEnabled')) {
|
||||
if (isUrlOrAPIKey(api_server) && main_api === "kobold") {
|
||||
$("#api_url_text").val(api_server);
|
||||
$("#api_button").click();
|
||||
//} else if (isUrlOrAPIKey(api_key_novel) && main_api === "novel") {
|
||||
// $("#api_key_novel").val(api_key_novel);
|
||||
// $("#api_button").click();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log("RA_AC -- Already online, nothing to do.");
|
||||
setTimeout(RA_autoconnect, 100);
|
||||
}
|
||||
}else{
|
||||
console.log('RA_AC -- settings not loaded yet...trying again..');
|
||||
setTimeout(RA_autoconnect,100);
|
||||
} // if onlinbe_staus hadn't been declared yet, try again..
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function isUrlOrAPIKey(string) {
|
||||
//const pattern = /^\d{3}-\d{3}-\d{3}-\d{3}$/; //need a sample novelAI key to set this format
|
||||
try {
|
||||
new URL(string);
|
||||
return true;
|
||||
} catch (_) {
|
||||
// return pattern.test(string);
|
||||
}
|
||||
}
|
||||
|
||||
$("document").ready(function () {
|
||||
|
||||
// read the state of Nav Lock and whether the nav was open or not before page load.
|
||||
$(PanelPin).prop('checked', LoadLocalBool("NavLockOn"));
|
||||
if (LoadLocalBool("NavLockOn") == true){
|
||||
$(NavToggle).prop("checked", LoadLocalBool("NavOpened"));
|
||||
}
|
||||
if (LoadLocalBool("NavLockOn") == true){$(NavToggle).prop("checked", LoadLocalBool("NavOpened"));}
|
||||
// read the state of AutoConnect and AutoLoadChat.
|
||||
$(AutoConnectCheckbox).prop("checked",LoadLocalBool("AutoConnectEnabled"));
|
||||
$(AutoLoadChatCheckbox).prop("checked",LoadLocalBool("AutoLoadChatEnabled"));
|
||||
|
||||
|
||||
if (LoadLocalBool('AutoLoadChatEnabled') == true) {
|
||||
console.log('calling RA_ALC');
|
||||
RA_autoloadchat();
|
||||
}
|
||||
if (LoadLocalBool('AutoLoadChatEnabled') == true) {RA_autoloadchat();}
|
||||
//Autoconnect on page load if enabled, or when api type is changed
|
||||
if (LoadLocalBool("AutoConnectEnabled") == true) {RA_autoconnect()}
|
||||
$("#main_api").change(function () {RA_autoconnect();});
|
||||
@ -266,94 +244,61 @@ $("document").ready(function () {
|
||||
|
||||
//close the RightNav panel when user clicks outside of it or related panels (adv editing popup, or dialog popups)
|
||||
$("html").click(function (e) {
|
||||
//console.log('clicking'+$(this));
|
||||
if ($(NavToggle).prop("checked") === true && $(PanelPin).prop("checked") === false) {
|
||||
if ($(e.target).attr("id") !== "nav-toggle") {
|
||||
if (RightNavPanel.contains(e.target) === false) {
|
||||
if (AdvancedCharDefsPopup.contains(e.target) === false) {
|
||||
if (ConfirmationPopup.contains(e.target) === false) {
|
||||
if ($(NavToggle).prop("checked") &&
|
||||
!$(PanelPin).prop("checked") &&
|
||||
$(e.target).attr("id") !== "nav-toggle" &&
|
||||
!RightNavPanel.contains(e.target) &&
|
||||
!AdvancedCharDefsPopup.contains(e.target) &&
|
||||
!ConfirmationPopup.contains(e.target)) {
|
||||
NavToggle.click();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//save NavLock prefs and record state of the Nav being open or closed
|
||||
$(NavToggle).on("change", function () {
|
||||
SaveLocal("NavOpened", $(NavToggle).prop("checked"));
|
||||
});
|
||||
$(PanelPin).on("change",function () {
|
||||
SaveLocal("NavLockOn", $(PanelPin).prop("checked"));
|
||||
});
|
||||
$(NavToggle).on("change", function () {SaveLocal("NavOpened", $(NavToggle).prop("checked")); });
|
||||
$(PanelPin).on("change",function () {SaveLocal("NavLockOn", $(PanelPin).prop("checked")); });
|
||||
|
||||
//save AutoConnect and AutoLoadChat prefs
|
||||
$(AutoConnectCheckbox).on("change",function () {
|
||||
SaveLocal("AutoConnectEnabled", $(AutoConnectCheckbox).prop("checked"));
|
||||
});
|
||||
$(AutoLoadChatCheckbox).on("change",function () {
|
||||
SaveLocal("AutoLoadChatEnabled", $(AutoLoadChatCheckbox).prop("checked"));
|
||||
});
|
||||
$(AutoConnectCheckbox).on("change",function () {SaveLocal("AutoConnectEnabled", $(AutoConnectCheckbox).prop("checked")); });
|
||||
$(AutoLoadChatCheckbox).on("change",function () {SaveLocal("AutoLoadChatEnabled", $(AutoLoadChatCheckbox).prop("checked")); });
|
||||
|
||||
//save the clicked Nav Tab as the tab to auto-open on page reload
|
||||
$("#rm_button_settings").click( function (){
|
||||
SaveLocal('SelectedNavTab','rm_button_settings');
|
||||
});
|
||||
$(SelectedCharacterTab).click(function () {
|
||||
console.log('3rd tab clicked - saving selnavtab');
|
||||
//SaveLocal('ActiveChar',this_chid);
|
||||
SaveLocal('SelectedNavTab','rm_button_selected_ch');
|
||||
});
|
||||
$("#rm_button_extensions").click(function() {
|
||||
SaveLocal('SelectedNavTab','rm_button_extensions');
|
||||
});
|
||||
$("#rm_button_settings").click( function (){SaveLocal('SelectedNavTab','rm_button_settings'); });
|
||||
$(SelectedCharacterTab).click(function () {SaveLocal('SelectedNavTab','rm_button_selected_ch'); });
|
||||
$("#rm_button_characters").click( function () { //if char list is clicked, in addition to saving it...
|
||||
SaveLocal('SelectedNavTab','rm_button_characters');
|
||||
characters.sort(Intl.Collator().compare); // we sort the list
|
||||
});
|
||||
// when a char is selected from the list, save them as the auto-load character for next page load
|
||||
$(document).on("click", ".character_select",function () {
|
||||
console.log('char clicked in charlist - saving local activechar');
|
||||
SaveLocal('ActiveChar',$(this).attr('chid'));
|
||||
});
|
||||
$(document).on("click", ".character_select",function () {SaveLocal('ActiveChar',$(this).attr('chid')); });
|
||||
|
||||
//this makes the chat input text area resize vertically to match the text size (limited by CSS at 50% window height)
|
||||
$('#send_textarea').on('input', function () {
|
||||
this.style.height = '40px';
|
||||
this.style.height =
|
||||
(this.scrollHeight) + 'px';
|
||||
this.style.height = (this.scrollHeight) + 'px';
|
||||
});
|
||||
|
||||
//Regenerate if user swipes on the last mesage in chat
|
||||
//TODO:
|
||||
//1. Make it detect if the last message is from user, and ignore swipes then...
|
||||
//2. find a way to make the chat slide down smoothly when the last mes div gets .remove()-d
|
||||
|
||||
document.addEventListener('swiped-left', function(e) {
|
||||
var SwipeTargetMesClassParent = e.target.closest('.mes');
|
||||
if (is_send_press == false){
|
||||
if (SwipeTargetMesClassParent !== null && SwipeTargetMesClassParent.nextSibling == null ){
|
||||
$('#chat').children().last().css({'transition':'all 0.5s ease-in-out'});
|
||||
$('#chat').children().last().css({'transform':'translateX(-100vw) scale(0,0)','overflow':'hidden'});
|
||||
$('#chat').children().last().css({'opacity':'0'});
|
||||
|
||||
Generate('regenerate');
|
||||
var SwipeButR = $('.swipe_right:last');
|
||||
var SwipeTargetMesClassParent = e.target.closest('.last_mes');
|
||||
if (SwipeTargetMesClassParent !== null){
|
||||
if(SwipeButR.attr('style')=='display: flex;' == true){
|
||||
SwipeButR.click();
|
||||
}
|
||||
}
|
||||
});
|
||||
document.addEventListener('swiped-right', function(e) {
|
||||
var SwipeTargetMesClassParent = e.target.closest('.mes');
|
||||
console.log(is_send_press);
|
||||
if (is_send_press === false){
|
||||
if (SwipeTargetMesClassParent !== null && SwipeTargetMesClassParent.nextSibling == null){
|
||||
$('#chat').children().last().css({'transition':'all 0.5s ease-in-out'});
|
||||
$('#chat').children().last().css({'transform':'translateX(100vh) scale(0,0)','overflow':'hidden'});
|
||||
$('#chat').children().last().css({'opacity':'0'});
|
||||
Generate('regenerate');
|
||||
console.log(is_send_press);
|
||||
var SwipeButL = $('.swipe_left:last');
|
||||
var SwipeTargetMesClassParent = e.target.closest('.last_mes');
|
||||
if (SwipeTargetMesClassParent !== null){
|
||||
if(SwipeButL.attr('style')=='display: flex;' == true){
|
||||
SwipeButL.click();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//Additional hotkeys CTRL+ENTER and CTRL+UPARROW
|
||||
@ -377,6 +322,12 @@ $("document").ready(function () {
|
||||
if (event.ctrlKey && event.key == "ArrowRight") { //for debug, empty local storage state
|
||||
ClearLocal();
|
||||
}
|
||||
if (event.key == "ArrowLeft") { //swipes left
|
||||
$('.swipe_left:last').click();
|
||||
}
|
||||
if (event.key == "ArrowRight") { //swipes right
|
||||
$('.swipe_right:last').click();
|
||||
}
|
||||
});
|
||||
|
||||
})
|
||||
|
@ -1 +1 @@
|
||||
{"username":"You","api_server":"http://localhost:5000/api","api_server_textgenerationwebui":"","preset_settings":"gui","preset_settings_novel":"Classic-Euterpe","user_avatar":"legat.png","temp":0.43,"amount_gen":180,"max_context":2048,"anchor_order":0,"style_anchor":false,"character_anchor":false,"auto_connect":true,"auto_load_chat":true,"main_api":"kobold","api_key_novel":"","rep_pen":1.17,"rep_pen_size":1024,"model_novel":"euterpe-v2","temp_novel":1.11,"rep_pen_novel":1.11,"rep_pen_size_novel":320,"world_info":null,"world_info_depth":2,"world_info_budget":200,"active_character":"0","textgenerationwebui_settings":{"temp":0.5,"top_p":0.9,"top_k":0,"typical_p":1,"rep_pen":1.1,"rep_pen_size":0,"penalty_alpha":0}}
|
||||
{"username":"You","api_server":"http://127.0.0.1:5000/api","api_server_textgenerationwebui":"","preset_settings":"Classic-Pygmalion-2.7b","preset_settings_novel":"Classic-Euterpe","user_avatar":"legat.png","temp":0.43,"amount_gen":180,"max_context":2048,"anchor_order":0,"style_anchor":false,"character_anchor":false,"main_api":"kobold","api_key_novel":"","rep_pen":1.17,"rep_pen_size":1024,"model_novel":"euterpe-v2","temp_novel":0.5,"rep_pen_novel":1,"rep_pen_size_novel":100,"world_info":"Toaru","world_info_depth":1,"world_info_budget":200,"active_character":"0","textgenerationwebui_settings":{"temp":0.5,"top_p":0.9,"top_k":0,"typical_p":1,"rep_pen":1.1,"rep_pen_size":0,"penalty_alpha":0},"swipes":true}
|
@ -345,13 +345,50 @@ code {
|
||||
|
||||
.mes {
|
||||
display: grid;
|
||||
grid-template-columns: min-content min-content auto;
|
||||
grid-template-columns: min-content min-content auto min-content min-content;
|
||||
padding: 10px 10px 0 10px;
|
||||
vertical-align: top;
|
||||
width: 100%;
|
||||
color: var(--ivory, white);
|
||||
}
|
||||
|
||||
.last_mes .mes_text {
|
||||
min-height: 7em;
|
||||
}
|
||||
|
||||
.last_mes{
|
||||
grid-template-columns: [checkbox] fit-content(60px) [avatar] 50px [msg_block] auto [rightswipe] fit-content(48px);
|
||||
|
||||
}
|
||||
/* SWIPE RELATED STYLES*/
|
||||
|
||||
.swipe_right,.swipe_left {
|
||||
height: 30px;
|
||||
width: 30px;
|
||||
opacity: 0.36;
|
||||
position: absolute;
|
||||
right: 15px;
|
||||
margin-top: 62px;
|
||||
left: auto;
|
||||
background-color: var(--black50a);
|
||||
padding: 20px;
|
||||
border-radius: 50%;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
/* display: none; */
|
||||
border: 1px solid grey;
|
||||
}
|
||||
|
||||
.swipe_right img, .swipe_left img {
|
||||
height: 30px;
|
||||
width: 30px;
|
||||
}
|
||||
|
||||
.swipe_left {
|
||||
left: 20px;
|
||||
right: auto;
|
||||
}
|
||||
|
||||
.avatar {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
@ -371,15 +408,14 @@ code {
|
||||
}
|
||||
|
||||
.avatar.selected img {
|
||||
outline-style: solid;
|
||||
/* outline-style: solid;
|
||||
outline-color: rgb(255 255 255 / 70%);
|
||||
outline-width: 2px;
|
||||
outline-width: 2px; */
|
||||
}
|
||||
|
||||
.mes_block {
|
||||
|
||||
padding-top: 0;
|
||||
padding-left: 10px;
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
||||
.ch_name {
|
||||
@ -390,8 +426,8 @@ code {
|
||||
.mes_text {
|
||||
font-weight: 400;
|
||||
line-height: 1.25rem;
|
||||
padding-right: 40px;
|
||||
padding-left: 5px;
|
||||
padding-right: 60px;
|
||||
padding-left: 0;
|
||||
padding-top: 5px;
|
||||
padding-bottom: 5px;
|
||||
max-width: 720px;
|
||||
@ -1533,8 +1569,10 @@ input[type='checkbox']:not(#nav-toggle):not(#rm_button_panel_pin):checked::after
|
||||
|
||||
#user_avatar_block .avatar {
|
||||
cursor: pointer;
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
width: 64px;
|
||||
height: 64px;
|
||||
border: 2px solid rgba(255,255,255,0.7);
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
#user_avatar_block .avatar img {
|
||||
@ -2521,6 +2559,8 @@ a {
|
||||
display: none;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@media screen and (max-width: 450px) { /*styles for mobile phones (tested on iPhone 13 Pro)*/
|
||||
body {
|
||||
font-size: 18px;
|
||||
@ -2530,6 +2570,7 @@ a {
|
||||
|
||||
#sheld { /*margin around the sides, and a larger one on bottom to avoid iOS Home bar*/
|
||||
height: calc(100svh - 15px);
|
||||
width: 100vw; //calc(100vw - 15px);
|
||||
margin-left: 5px;
|
||||
margin-right: 5px;
|
||||
position: fixed;
|
||||
|
Reference in New Issue
Block a user