This commit is contained in:
ebolam
2022-10-12 15:10:56 -04:00

View File

@@ -1908,8 +1908,6 @@ function world_info_entry(data) {
update_token_lengths(); update_token_lengths();
clearTimeout(calc_token_usage_timeout);
calc_token_usage_timeout = setTimeout(calc_token_usage, 200);
clearTimeout(setup_missing_wi_toggles_timeout); clearTimeout(setup_missing_wi_toggles_timeout);
setup_missing_wi_toggles_timeout = setTimeout(setup_missing_wi_toggles, 200); setup_missing_wi_toggles_timeout = setTimeout(setup_missing_wi_toggles, 200);
@@ -2603,28 +2601,32 @@ function autoResize(element, min_size=200) {
} }
function calc_token_usage(soft_prompt_tokens, memory_tokens, authors_notes_tokens, prompt_tokens, game_text_tokens, world_info_tokens, submit_tokens) { function calc_token_usage(
//submit_tokens = token_length(document.getElementById("input_text").value); soft_prompt_length,
total_tokens = parseInt(document.getElementById('model_max_length_cur').value); memory_length,
authors_note_length,
unused_tokens = total_tokens - memory_tokens - authors_notes_tokens - world_info_tokens - prompt_tokens - game_text_tokens - submit_tokens; prompt_length,
game_text_length,
document.getElementById("soft_prompt_tokens").style.width = (soft_prompt_tokens/total_tokens)*100 + "%"; world_info_length,
document.getElementById("soft_prompt_tokens").setAttribute("tooltip", "Soft Prompt: "+soft_prompt_tokens); submit_length
document.getElementById("memory_tokens").style.width = (memory_tokens/total_tokens)*100 + "%"; ) {
document.getElementById("memory_tokens").setAttribute("tooltip", "Memory: "+memory_tokens); let total_tokens = parseInt(document.getElementById('model_max_length_cur').value);
document.getElementById("authors_notes_tokens").style.width = (authors_notes_tokens/total_tokens)*100 + "%"; let unused_token_count = total_tokens - memory_length - authors_note_length - world_info_length - prompt_length - game_text_length - submit_length;
document.getElementById("authors_notes_tokens").setAttribute("tooltip", "Author's Notes: "+authors_notes_tokens);
document.getElementById("world_info_tokens").style.width = (world_info_tokens/total_tokens)*100 + "%"; for (const dat of [
document.getElementById("world_info_tokens").setAttribute("tooltip", "World Info: "+world_info_tokens); {id: "soft_prompt_tokens", tokenCount: soft_prompt_length, label: "Soft Prompt"},
document.getElementById("prompt_tokens").style.width = (prompt_tokens/total_tokens)*100 + "%"; {id: "memory_tokens", tokenCount: memory_length, label: "Memory"},
document.getElementById("prompt_tokens").setAttribute("tooltip", "Prompt: "+prompt_tokens); {id: "authors_notes_tokens", tokenCount: authors_note_length, label: "Author's Note"},
document.getElementById("game_text_tokens").style.width = (game_text_tokens/total_tokens)*100 + "%"; {id: "world_info_tokens", tokenCount: world_info_length, label: "World Info"},
document.getElementById("game_text_tokens").setAttribute("tooltip", "Game Text: "+game_text_tokens); {id: "prompt_tokens", tokenCount: prompt_length, label: "Prompt"},
document.getElementById("submit_tokens").style.width = (submit_tokens/total_tokens)*100 + "%"; {id: "game_text_tokens", tokenCount: game_text_length, label: "Game Text"},
document.getElementById("submit_tokens").setAttribute("tooltip", "Submit Text: "+submit_tokens); {id: "submit_tokens", tokenCount: submit_length, label: "Submit Text"},
document.getElementById("unused_tokens").style.width = (unused_tokens/total_tokens)*100 + "%"; {id: "unused_tokens", tokenCount: unused_token_count, label: "Remaining"},
document.getElementById("unused_tokens").setAttribute("tooltip", "Remaining: "+unused_tokens); ]) {
const el = document.getElementById(dat.id);
el.style.width = ((dat.tokenCount / total_tokens) * 100) + "%";
el.setAttribute("tooltip", `${dat.label}: ${dat.tokenCount}`);
}
} }
function Change_Theme(theme) { function Change_Theme(theme) {
@@ -2879,13 +2881,13 @@ function distortColor(rgb) {
function update_context(data) { function update_context(data) {
$(".context-block").remove(); $(".context-block").remove();
memory_tokens = 0; let memory_length = 0;
authors_notes_tokens = 0; let authors_notes_length = 0;
prompt_tokens = 0; let prompt_length = 0;
game_text_tokens = 0; let game_text_length = 0;
world_info_tokens = 0; let world_info_length = 0;
soft_prompt_tokens = 0; let soft_prompt_length = 0;
submit_tokens = 0; let submit_length = 0;
//clear out within_max_length class //clear out within_max_length class
for (action of document.getElementsByClassName("within_max_length")) { for (action of document.getElementsByClassName("within_max_length")) {
@@ -2928,22 +2930,22 @@ function update_context(data) {
switch (entry.type) { switch (entry.type) {
case 'soft_prompt': case 'soft_prompt':
soft_prompt_tokens = entry.tokens; soft_prompt_length = entry.tokens.length;
break; break;
case 'prompt': case 'prompt':
prompt_tokens = entry.tokens; prompt_length = entry.tokens.length;
break; break;
case 'world_info': case 'world_info':
world_info_tokens += entry.tokens; world_info_length += entry.tokens.length;
break; break;
case 'memory': case 'memory':
memory_tokens = entry.tokens; memory_length = entry.tokens.length;
break; break;
case 'authors_note': case 'authors_note':
authors_notes_tokens = entry.tokens; authors_notes_length = entry.tokens.length;
break; break;
case 'action': case 'action':
game_text_tokens += entry.tokens; game_text_length += entry.tokens.length;
if ('action_ids' in entry) { if ('action_ids' in entry) {
for (action_id of entry.action_ids) { for (action_id of entry.action_ids) {
if (document.getElementById('Selected Text Chunk '+action_id)) { if (document.getElementById('Selected Text Chunk '+action_id)) {
@@ -2953,11 +2955,20 @@ function update_context(data) {
} }
break; break;
case 'submit': case 'submit':
submit_tokens = entry.tokens; submit_length = entry.tokens.length;
break; break;
} }
} }
calc_token_usage(soft_prompt_tokens, memory_tokens, authors_notes_tokens, prompt_tokens, game_text_tokens, world_info_tokens, submit_tokens);
calc_token_usage(
soft_prompt_length,
memory_length,
authors_notes_length,
prompt_length,
game_text_length,
world_info_length,
submit_length
);
} }