mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Multigen fix
This commit is contained in:
@@ -33,6 +33,7 @@
|
|||||||
var default_ch_mes = "Hello";
|
var default_ch_mes = "Hello";
|
||||||
var count_view_mes = 0;
|
var count_view_mes = 0;
|
||||||
var mesStr = '';
|
var mesStr = '';
|
||||||
|
var generatedPromtCache = '';
|
||||||
var characters = [];
|
var characters = [];
|
||||||
var this_chid;
|
var this_chid;
|
||||||
var backgrounds = [];
|
var backgrounds = [];
|
||||||
@@ -125,7 +126,6 @@
|
|||||||
|
|
||||||
var colab_ini_step = 1;
|
var colab_ini_step = 1;
|
||||||
setInterval(function() {
|
setInterval(function() {
|
||||||
console.log(colab_ini_step);
|
|
||||||
switch(colab_ini_step){
|
switch(colab_ini_step){
|
||||||
case 0:
|
case 0:
|
||||||
$('#colab_popup_text').html('<h3>Initialization</h3>');
|
$('#colab_popup_text').html('<h3>Initialization</h3>');
|
||||||
@@ -362,7 +362,7 @@
|
|||||||
if (response.ok === true) {
|
if (response.ok === true) {
|
||||||
const getData = await response.json();
|
const getData = await response.json();
|
||||||
if(getData.colaburl != false){
|
if(getData.colaburl != false){
|
||||||
$('colab_shadow_popup').css('display', 'none');
|
$('#colab_shadow_popup').css('display', 'none');
|
||||||
is_colab = true;
|
is_colab = true;
|
||||||
let url = String(getData.colaburl).split("flare.com")[0] + "flare.com";
|
let url = String(getData.colaburl).split("flare.com")[0] + "flare.com";
|
||||||
$('#api_url_text').val(url);
|
$('#api_url_text').val(url);
|
||||||
@@ -445,8 +445,7 @@
|
|||||||
$('#chat').html('');
|
$('#chat').html('');
|
||||||
}
|
}
|
||||||
function messageFormating(mes, ch_name){
|
function messageFormating(mes, ch_name){
|
||||||
if(this_chid != undefined)
|
if(this_chid != undefined) mes = mes.replaceAll("<", "<").replaceAll(">", ">");
|
||||||
mes = mes.replaceAll("<", "<").replaceAll(">", ">");
|
|
||||||
mes = mes.replace(/\*\*(.+?)\*\*/g, '<b>$1</b>').replace(/\*(.+?)\*/g, '<i>$1</i>').replace(/\n/g, '<br/>');
|
mes = mes.replace(/\*\*(.+?)\*\*/g, '<b>$1</b>').replace(/\*(.+?)\*/g, '<i>$1</i>').replace(/\n/g, '<br/>');
|
||||||
if(ch_name !== name1){
|
if(ch_name !== name1){
|
||||||
mes = mes.replaceAll(name2+":", "");
|
mes = mes.replaceAll(name2+":", "");
|
||||||
@@ -460,6 +459,7 @@
|
|||||||
var messageText = mes['mes'];
|
var messageText = mes['mes'];
|
||||||
var characterName = name1;
|
var characterName = name1;
|
||||||
var avatarImg = "User Avatars/"+user_avatar;
|
var avatarImg = "User Avatars/"+user_avatar;
|
||||||
|
generatedPromtCache = '';
|
||||||
//thisText = thisText.split("\n").join("<br>");
|
//thisText = thisText.split("\n").join("<br>");
|
||||||
var avatarImg = "User Avatars/"+user_avatar;
|
var avatarImg = "User Avatars/"+user_avatar;
|
||||||
if(!mes['is_user']){
|
if(!mes['is_user']){
|
||||||
@@ -485,6 +485,12 @@
|
|||||||
//messageText = messageText.replaceAll(name2+":", "");
|
//messageText = messageText.replaceAll(name2+":", "");
|
||||||
//}
|
//}
|
||||||
//console.log(messageText);
|
//console.log(messageText);
|
||||||
|
if(count_view_mes == 0){
|
||||||
|
messageText = messageText.replace(/{{user}}/gi, name1);
|
||||||
|
messageText = messageText.replace(/{{char}}/gi, name2);
|
||||||
|
messageText = messageText.replace(/<USER>/gi, name1);
|
||||||
|
messageText = messageText.replace(/<BOT>/gi, name2);
|
||||||
|
}
|
||||||
messageText = messageFormating(messageText, characterName);
|
messageText = messageFormating(messageText, characterName);
|
||||||
|
|
||||||
$("#chat").append( "<div class='mes' mesid="+count_view_mes+" 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><img src=img/scroll.png style='width:20px;height:20px;'></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>" );
|
$("#chat").append( "<div class='mes' mesid="+count_view_mes+" 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><img src=img/scroll.png style='width:20px;height:20px;'></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>" );
|
||||||
@@ -607,8 +613,13 @@
|
|||||||
var checkMesExample = $.trim(mesExamples.replace(/<START>/gi, ''));//for check length without tag
|
var checkMesExample = $.trim(mesExamples.replace(/<START>/gi, ''));//for check length without tag
|
||||||
if(checkMesExample.length == 0) mesExamples = '';
|
if(checkMesExample.length == 0) mesExamples = '';
|
||||||
var mesExamplesArray = [];
|
var mesExamplesArray = [];
|
||||||
|
//***Base replace***
|
||||||
if(mesExamples !== undefined){
|
if(mesExamples !== undefined){
|
||||||
if(mesExamples.length > 0){
|
if(mesExamples.length > 0){
|
||||||
|
if(is_pugmalion){
|
||||||
|
mesExamples = mesExamples.replace(/{{user}}:/gi, 'You:');
|
||||||
|
mesExamples = mesExamples.replace(/<USER>:/gi, 'You:');
|
||||||
|
}
|
||||||
mesExamples = mesExamples.replace(/{{user}}/gi, name1);
|
mesExamples = mesExamples.replace(/{{user}}/gi, name1);
|
||||||
mesExamples = mesExamples.replace(/{{char}}/gi, name2);
|
mesExamples = mesExamples.replace(/{{char}}/gi, name2);
|
||||||
mesExamples = mesExamples.replace(/<USER>/gi, name1);
|
mesExamples = mesExamples.replace(/<USER>/gi, name1);
|
||||||
@@ -618,6 +629,31 @@
|
|||||||
mesExamplesArray = blocks.slice(1).map(block => `<START>\n${block.trim()}\n`);
|
mesExamplesArray = blocks.slice(1).map(block => `<START>\n${block.trim()}\n`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if(is_pygmalion){
|
if(is_pygmalion){
|
||||||
if(charDescription.length > 0){
|
if(charDescription.length > 0){
|
||||||
@@ -655,6 +691,12 @@
|
|||||||
var chat2 = [];
|
var chat2 = [];
|
||||||
var j = 0;
|
var j = 0;
|
||||||
for(var i = chat.length-1; i >= 0; i--){
|
for(var i = chat.length-1; i >= 0; i--){
|
||||||
|
if(j == 0){
|
||||||
|
chat[j]['mes'] = chat[j]['mes'].replace(/{{user}}/gi, name1);
|
||||||
|
chat[j]['mes'] = chat[j]['mes'].replace(/{{char}}/gi, name2);
|
||||||
|
chat[j]['mes'] = chat[j]['mes'].replace(/<USER>/gi, name1);
|
||||||
|
chat[j]['mes'] = chat[j]['mes'].replace(/<BOT>/gi, name2);
|
||||||
|
}
|
||||||
let this_mes_ch_name = '';
|
let this_mes_ch_name = '';
|
||||||
if(chat[j]['is_user']){
|
if(chat[j]['is_user']){
|
||||||
this_mes_ch_name = name1;
|
this_mes_ch_name = name1;
|
||||||
@@ -733,9 +775,10 @@
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
function runGenerate(cycleGenerationPromt = ''){
|
|
||||||
|
|
||||||
if(cycleGenerationPromt.length == 0){
|
function runGenerate(cycleGenerationPromt = ''){
|
||||||
|
generatedPromtCache+=cycleGenerationPromt;
|
||||||
|
if(generatedPromtCache.length == 0){
|
||||||
chatString = "";
|
chatString = "";
|
||||||
arrMes = arrMes.reverse();
|
arrMes = arrMes.reverse();
|
||||||
var is_add_personality = false;
|
var is_add_personality = false;
|
||||||
@@ -800,17 +843,17 @@
|
|||||||
mesSendString+=mesSend[j];
|
mesSendString+=mesSend[j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function checkProptSize(){
|
function checkPromtSize(){
|
||||||
setPromtString();
|
setPromtString();
|
||||||
let thisPromtContextSize = encode(JSON.stringify(storyString+mesExmString+mesSendString+anchorTop+anchorBottom+charPersonality+cycleGenerationPromt)).length+120;
|
let thisPromtContextSize = encode(JSON.stringify(storyString+mesExmString+mesSendString+anchorTop+anchorBottom+charPersonality+generatedPromtCache)).length+120;
|
||||||
if(thisPromtContextSize > this_max_context){
|
if(thisPromtContextSize > this_max_context){
|
||||||
if(count_exm_add > 0){
|
if(count_exm_add > 0){
|
||||||
//mesExamplesArray.length = mesExamplesArray.length-1;
|
//mesExamplesArray.length = mesExamplesArray.length-1;
|
||||||
count_exm_add--;
|
count_exm_add--;
|
||||||
checkProptSize();
|
checkPromtSize();
|
||||||
}else if(mesSend.length > 0){
|
}else if(mesSend.length > 0){
|
||||||
mesSend.shift();
|
mesSend.shift();
|
||||||
checkProptSize();
|
checkPromtSize();
|
||||||
}else{
|
}else{
|
||||||
//end
|
//end
|
||||||
}
|
}
|
||||||
@@ -819,8 +862,8 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(cycleGenerationPromt.length > 0){
|
if(generatedPromtCache.length > 0){
|
||||||
checkProptSize();
|
checkPromtSize();
|
||||||
}else{
|
}else{
|
||||||
setPromtString();
|
setPromtString();
|
||||||
}
|
}
|
||||||
@@ -830,7 +873,7 @@
|
|||||||
}else{
|
}else{
|
||||||
mesSendString = '<START>\n'+mesSendString;
|
mesSendString = '<START>\n'+mesSendString;
|
||||||
}
|
}
|
||||||
finalPromt = storyString+mesExmString+mesSendString+cycleGenerationPromt;
|
finalPromt = storyString+mesExmString+mesSendString+generatedPromtCache;
|
||||||
|
|
||||||
var generate_data;
|
var generate_data;
|
||||||
if(main_api == 'kobold'){
|
if(main_api == 'kobold'){
|
||||||
@@ -2704,7 +2747,7 @@
|
|||||||
|
|
||||||
<div id="scenario_div">
|
<div id="scenario_div">
|
||||||
<h4>Scenario</h4>
|
<h4>Scenario</h4>
|
||||||
<h5>Circumstances and context of the dialogue</h5>
|
<h5>Circumstances and context of the dialogue (<a href="/notes/12" target="_blank">?</a>)</h5>
|
||||||
<input id="scenario_pole" name="scenario" class="text_pole" maxlength="9999" size="40" value="" autocomplete="off" form="form_create">
|
<input id="scenario_pole" name="scenario" class="text_pole" maxlength="9999" size="40" value="" autocomplete="off" form="form_create">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user