Merge branch 'united' into api

This commit is contained in:
vfbd
2022-08-12 13:57:50 -04:00
5 changed files with 185 additions and 129 deletions

View File

@ -512,6 +512,16 @@ function addWiLine(ob) {
$(".wisortable-excluded-dynamic").removeClass("wisortable-excluded-dynamic");
$(this).parent().css("max-height", "").find(".wicomment").find(".form-control").css("max-height", "");
});
for (const wientry of document.getElementsByClassName("wientry")) {
// If we are uninitialized, skip.
if ($(wientry).closest(".wilistitem-uninitialized").length) continue;
// add() will not add if the class is already present
wientry.classList.add("tokens-counted");
}
registerTokenCounters();
}
function addWiFolder(uid, ob) {
@ -835,6 +845,7 @@ function exitMemoryMode() {
button_actmem.html("Memory");
show([button_actback, button_actfwd, button_actretry, button_actwi]);
input_text.val("");
updateInputBudget(input_text[0]);
// Hide Author's Note field
anote_menu.slideUp("fast");
}
@ -1078,7 +1089,7 @@ function buildLoadModelList(ar, menu, breadcrumbs, showdelete) {
html = html + "<span class=\"loadlisticon loadmodellisticon-folder oi oi-folder allowed\" aria-hidden=\"true\"></span>"
} else {
//this is a model
html = html + "<div class=\"loadlistpadding\"></div>"
html = html + "<div class=\"loadlisticon oi oi-caret-right allowed\"></div>"
}
//now let's do the delete icon if applicable
@ -1096,6 +1107,7 @@ function buildLoadModelList(ar, menu, breadcrumbs, showdelete) {
</div>"
loadmodelcontent.append(html);
//If this is a menu
console.log(ar[i]);
if(ar[i][3]) {
$("#loadmodel"+i).off("click").on("click", (function () {
return function () {
@ -1105,15 +1117,27 @@ function buildLoadModelList(ar, menu, breadcrumbs, showdelete) {
})(i));
//Normal load
} else {
$("#loadmodel"+i).off("click").on("click", (function () {
return function () {
$("#use_gpu_div").addClass("hidden");
$("#modelkey").addClass("hidden");
$("#modellayers").addClass("hidden");
socket.send({'cmd': 'selectmodel', 'data': $(this).attr("name")});
highlightLoadLine($(this));
}
})(i));
if (['NeoCustom', 'GPT2Custom'].includes(menu)) {
$("#loadmodel"+i).off("click").on("click", (function () {
return function () {
$("#use_gpu_div").addClass("hidden");
$("#modelkey").addClass("hidden");
$("#modellayers").addClass("hidden");
socket.send({'cmd': 'selectmodel', 'data': $(this).attr("name"), 'path': $(this).attr("pretty_name")});
highlightLoadLine($(this));
}
})(i));
} else {
$("#loadmodel"+i).off("click").on("click", (function () {
return function () {
$("#use_gpu_div").addClass("hidden");
$("#modelkey").addClass("hidden");
$("#modellayers").addClass("hidden");
socket.send({'cmd': 'selectmodel', 'data': $(this).attr("name")});
highlightLoadLine($(this));
}
})(i));
}
}
}
}
@ -2139,6 +2163,37 @@ function interpolateRGB(color0, color1, t) {
]
}
function updateInputBudget(inputElement) {
let data = {"unencoded": inputElement.value, "field": inputElement.id};
if (inputElement.id === "anoteinput") {
data["anotetemplate"] = $("#anotetemplate").val();
}
socket.send({"cmd": "getfieldbudget", "data": data});
}
function registerTokenCounters() {
// Add token counters to all input containers with the class of "tokens-counted",
// if a token counter is not already a child of said container.
for (const el of document.getElementsByClassName("tokens-counted")) {
if (el.getElementsByClassName("input-token-usage").length) continue;
let span = document.createElement("span");
span.classList.add("input-token-usage");
span.innerText = "?/? Tokens";
el.appendChild(span);
let inputElement = el.querySelector("input, textarea");
inputElement.addEventListener("input", function() {
updateInputBudget(this);
});
updateInputBudget(inputElement);
}
}
//=================================================================//
// READY/RUNTIME
//=================================================================//
@ -2482,6 +2537,7 @@ $(document).ready(function(){
memorytext = msg.data;
input_text.val(msg.data);
}
updateInputBudget(input_text[0]);
} else if(msg.cmd == "setmemory") {
memorytext = msg.data;
if(memorymode) {
@ -2603,6 +2659,7 @@ $(document).ready(function(){
} else if(msg.cmd == "setanote") {
// Set contents of Author's Note field
anote_input.val(msg.data);
updateInputBudget(anote_input[0]);
} else if(msg.cmd == "setanotetemplate") {
// Set contents of Author's Note Template field
$("#anotetemplate").val(msg.data);
@ -2842,6 +2899,8 @@ $(document).ready(function(){
if (msg.key) {
$("#modelkey").removeClass("hidden");
$("#modelkey")[0].value = msg.key_value;
//if we're in the API list, disable to load button until the model is selected (after the API Key is entered)
disableButtons([load_model_accept]);
} else {
$("#modelkey").addClass("hidden");
@ -2879,6 +2938,7 @@ $(document).ready(function(){
}
} else if(msg.cmd == 'oai_engines') {
$("#oaimodel").removeClass("hidden")
enableButtons([load_model_accept]);
selected_item = 0;
length = $("#oaimodel")[0].options.length;
for (let i = 0; i < length; i++) {
@ -2915,7 +2975,18 @@ $(document).ready(function(){
opt.innerHTML = engine[1];
$("#oaimodel")[0].appendChild(opt);
}
} else if(msg.cmd == 'showfieldbudget') {
let inputElement = document.getElementById(msg.data.field);
let tokenBudgetElement = inputElement.parentNode.getElementsByClassName("input-token-usage")[0];
if (msg.data.max === null) {
tokenBudgetElement.innerText = "";
} else {
let tokenLength = msg.data.length ?? "?";
let tokenMax = msg.data.max ?? "?";
tokenBudgetElement.innerText = `${tokenLength}/${tokenMax} Tokens`;
}
}
enableButtons([load_model_accept]);
});
socket.on('disconnect', function() {
@ -3383,6 +3454,15 @@ $(document).ready(function(){
if (handled) ev.preventDefault();
});
$("#anotetemplate").on("input", function() {
updateInputBudget(anote_input[0]);
})
registerTokenCounters();
updateInputBudget(input_text[0]);
});