back to working after merge,

formatting should match
fixed bug with send butting showing up midway through long pyg generations
optimized changeMainAPI function
This commit is contained in:
RossAsscends
2023-03-18 07:01:25 +09:00
parent 5f2c6b8853
commit bd60065e90
2 changed files with 572 additions and 556 deletions

View File

@ -1213,7 +1213,8 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length
return;
function runGenerate(cycleGenerationPromt = '') {
console.log('rungenerate entered');
is_send_press = true;
generatedPromtCache += cycleGenerationPromt;
if (generatedPromtCache.length == 0) {
@ -1325,7 +1326,7 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length
}
finalPromt = worldInfoBefore + storyString + worldInfoAfter + extension_prompt + mesExmString + mesSendString + generatedPromtCache + promptBias;
finalPromt = finalPromt.replace(/\r/gm, '');
console.log('final prompt decided');
//console.log('final prompt decided');
//if we aren't using the kobold GUI settings...
if (main_api == 'textgenerationwebui' || main_api == 'kobold' && preset_settings != 'gui') {
@ -1456,7 +1457,7 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length
dataType: "json",
contentType: "application/json",
success: function (data) {
console.log('generation success');
//console.log('generation success');
tokens_already_generated += this_amount_gen; // add new gen amt to any prev gen counter..
@ -1496,7 +1497,8 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length
message_already_generated.indexOf('<|endoftext|>') === -1 && //if there is no <endoftext> stamp in the response msg
tokens_already_generated < parseInt(amount_gen) && //if the gen'd msg is less than the max response length..
getMessage.length > 0) { //if we actually have gen'd text at all...
runGenerate(getMessage); //generate again with the 'GetMessage' argument..
runGenerate(getMessage);
console.log('returning to make pyg generate again'); //generate again with the 'GetMessage' argument..
return;
}
@ -1582,7 +1584,7 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length
}
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");
@ -1599,7 +1601,7 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length
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();
@ -1610,7 +1612,7 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").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");
@ -1618,6 +1620,7 @@ async function Generate(type, automatic_trigger) {//encode("dsfs").length
},
error: function (jqXHR, exception) {
$("#send_textarea").removeAttr('disabled');
is_send_press = false;
$("#send_but").css("display", "inline");
@ -1748,7 +1751,8 @@ async function getChat() {
data: JSON.stringify({
ch_name: characters[this_chid].name,
file_name: characters[this_chid].chat,
avatar_url: characters[this_chid].avatar }),
avatar_url: characters[this_chid].avatar
}),
dataType: 'json',
contentType: 'application/json',
});
@ -1797,39 +1801,50 @@ function openNavToggle() {
}
}
////////// OPTIMZED MAIN API CHANGE FUNCTION ////////////
function changeMainAPI() {
if ($("#main_api").find(":selected").val() == "kobold") {
$("#kobold_api").css("display", "block");
$("#novel_api").css("display", "none");
$("#textgenerationwebui_api").css("display", "none");
main_api = "kobold";
$("#max_context_block").css("display", "block");
$("#amount_gen_block").css("display", "block");
$("#softprompt_block").css("display", "block");
const selectedVal = $("#main_api").val();
const apiElements = {
"kobold": {
apiElem: $("#kobold_api"),
maxContextElem: $("#max_context_block"),
amountGenElem: $("#amount_gen_block"),
softPromptElem: $("#softprompt_block")
},
"textgenerationwebui": {
apiElem: $("#textgenerationwebui_api"),
maxContextElem: $("#max_context_block"),
amountGenElem: $("#amount_gen_block"),
softPromptElem: $("#softprompt_block")
},
"novel": {
apiElem: $("#novel_api"),
maxContextElem: $("#max_context_block"),
amountGenElem: $("#amount_gen_block"),
softPromptElem: $("#softprompt_block")
}
};
for (const apiName in apiElements) {
const apiObj = apiElements[apiName];
const isCurrentApi = selectedVal === apiName;
apiObj.apiElem.css("display", isCurrentApi ? "block" : "none");
apiObj.maxContextElem.css("display", isCurrentApi && apiName !== "novel" ? "block" : "none");
apiObj.amountGenElem.css("display", isCurrentApi && apiName !== "novel" ? "block" : "none");
apiObj.softPromptElem.css("display", isCurrentApi && apiName !== "novel" ? "block" : "none");
if (isCurrentApi && apiName === "textgenerationwebui") {
apiObj.amountGenElem.children().prop("disabled", false);
apiObj.amountGenElem.css("opacity", 1.0);
}
if ($("#main_api").find(":selected").val() == "textgenerationwebui") {
$("#kobold_api").css("display", "none");
$("#novel_api").css("display", "none");
$("#textgenerationwebui_api").css("display", "block");
main_api = "textgenerationwebui";
$("#max_context_block").css("display", "block");
$("#amount_gen_block").css("display", "block");
$("#softprompt_block").css("display", "block");
$("#amount_gen_block").children().prop("disabled", false);
$("#amount_gen_block").css("opacity", 1.0);
}
if ($("#main_api").find(":selected").val() == "novel") {
$("#kobold_api").css("display", "none");
$("#novel_api").css("display", "block");
$("#textgenerationwebui_api").css("display", "none");
main_api = "novel";
$("#max_context_block").css("display", "none");
$("#amount_gen_block").css("display", "none");
$("#softprompt_block").css("display", "none");
}
main_api = selectedVal;
}
////////////////////////////////////////////////////
async function getUserAvatars() {
$("#user_avatar_block").html(""); //RossAscends: necessary to avoid doubling avatars each QuickRefresh.
$("#user_avatar_block").append('<div class="avatar_upload">+</div>');

View File

@ -122,7 +122,8 @@ function RA_CountCharTokens() {
create_save_scenario
)).length;
} else {if (this_chid !== undefined && this_chid !== "invalid-safety-id") { // if we are counting a valid pre-saved char
} else {
if (this_chid !== undefined && this_chid !== "invalid-safety-id") { // if we are counting a valid pre-saved char
//same as above, all tokens including temporary ones
count_tokens = encode(