From fc7fa991d536b7eb02f87262a2dac07edb1622bb Mon Sep 17 00:00:00 2001 From: somebody Date: Mon, 24 Jul 2023 10:57:24 -0500 Subject: [PATCH 1/3] Streaming: Fix streaming not being cleaned up before commentator speaks super duper critical --- aiserver.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/aiserver.py b/aiserver.py index fe499edc..d7c3532e 100644 --- a/aiserver.py +++ b/aiserver.py @@ -3280,9 +3280,6 @@ def actionsubmit(data, actionmode=0, force_submit=False, force_prompt_gen=False, if(koboldai_vars.aibusy): return - # Open up token stream - emit("stream_tokens", True, broadcast=True, room="UI_2") - while(True): set_aibusy(1) koboldai_vars.actions.clear_unused_options() @@ -3474,8 +3471,6 @@ def actionsubmit(data, actionmode=0, force_submit=False, force_prompt_gen=False, set_aibusy(0) emit('from_server', {'cmd': 'scrolldown', 'data': ''}, broadcast=True, room="UI_1") break - # Clean up token stream - emit("stream_tokens", None, broadcast=True, room="UI_2") def apiactionsubmit_generate(txt, minimum, maximum): koboldai_vars.generated_tkns = 0 @@ -3903,7 +3898,10 @@ class HordeException(Exception): # Send text to generator and deal with output #==================================================================# -def generate(txt, minimum, maximum, found_entries=None): +def generate(txt, minimum, maximum, found_entries=None): + # Open up token stream + emit("stream_tokens", True, broadcast=True, room="UI_2") + koboldai_vars.generated_tkns = 0 if(found_entries is None): @@ -3940,7 +3938,10 @@ def generate(txt, minimum, maximum, found_entries=None): emit('from_server', {'cmd': 'errmsg', 'data': 'Error occurred during generator call; please check console.'}, broadcast=True, room="UI_1") logger.error(traceback.format_exc().replace("\033", "")) socketio.emit("error", str(e), broadcast=True, room="UI_2") + set_aibusy(0) + # Clean up token stream + emit("stream_tokens", None, broadcast=True, room="UI_2") return for i in range(koboldai_vars.numseqs): @@ -3972,7 +3973,10 @@ def generate(txt, minimum, maximum, found_entries=None): del genout gc.collect() torch.cuda.empty_cache() - + + # Clean up token stream + emit("stream_tokens", None, broadcast=True, room="UI_2") + maybe_review_story() set_aibusy(0) From 30640acca7873894f2005328e65533f881cc271e Mon Sep 17 00:00:00 2001 From: somebody Date: Mon, 24 Jul 2023 11:26:20 -0500 Subject: [PATCH 2/3] Editor: Don't allow editing or syncing during generation Only bad things can come from that! Also filter out stream buffer when fixing dirty game text (just in case!) --- static/koboldai.js | 42 +++++++++++++++++++++++++++++++++++++++- templates/index_new.html | 2 +- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/static/koboldai.js b/static/koboldai.js index f775f3f0..4902908f 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -85,6 +85,7 @@ var dirty_chunks = []; var initial_socketio_connection_occured = false; var selected_model_data; var privacy_mode_enabled = false; +var ai_busy = false; var streaming = { windowOpen: false, @@ -775,6 +776,11 @@ function update_status_bar(data) { } function do_ai_busy(data) { + console.log("AIBUSY", data.value) + ai_busy = data.value; + // Don't allow editing while Mr. Kobold is thinking + document.getElementById("Selected Text").contentEditable = !ai_busy; + if (data.value) { ai_busy_start = Date.now(); favicon.start_swap() @@ -3265,6 +3271,11 @@ function fix_dirty_game_text() { //This should get fired if we have deleted chunks or have added text outside of a node. //We wait until after the game text has lost focus to fix things otherwise it messes with typing var game_text = document.getElementById("Selected Text"); + + // Fix stray stream + const streamBufferEl = document.getElementById("#token-stream-buffer"); + if (streamBufferEl) streamBufferEl.remove(); + //Fix missing story prompt if (dirty_chunks.includes("-1")) { if (!document.getElementById("story_prompt")) { @@ -3277,6 +3288,7 @@ function fix_dirty_game_text() { game_text.prepend(story_prompt); } } + if (dirty_chunks.includes("game_text")) { dirty_chunks = dirty_chunks.filter(item => item != "game_text"); console.log("Firing Fix messed up text"); @@ -3312,7 +3324,7 @@ function fix_dirty_game_text() { function savegametextchanges() { fix_dirty_game_text(); - for (item of document.getElementsByClassName("editing")) { + for (const item of document.getElementsByClassName("editing")) { item.classList.remove("editing"); } if (dirty_chunks.length > 0) { @@ -7631,4 +7643,32 @@ $el("#gamescreen").addEventListener("paste", function(event) { false, event.clipboardData.getData("text/plain") ); +}); + +const gameText = document.getElementById("Selected Text"); +gameText.addEventListener("click", function(event) { + if (ai_busy) { + event.stopPropagation(); + return; + }; + + set_edit(event); +}); + +gameText.addEventListener("focusout", function(event) { + if (ai_busy) { + event.stopPropagation(); + return; + }; + + savegametextchanges(); +}); + +gameText.addEventListener("paste", function(event) { + if (ai_busy) { + event.stopPropagation(); + return; + }; + + check_game_after_paste(); }); \ No newline at end of file diff --git a/templates/index_new.html b/templates/index_new.html index 99b8c941..25dee500 100644 --- a/templates/index_new.html +++ b/templates/index_new.html @@ -53,7 +53,7 @@
-
+
From 9cc6972c1c7ac6012181f7c6e43e6e7abb92a827 Mon Sep 17 00:00:00 2001 From: somebody Date: Mon, 24 Jul 2023 11:30:33 -0500 Subject: [PATCH 3/3] Shh! --- static/koboldai.js | 1 - 1 file changed, 1 deletion(-) diff --git a/static/koboldai.js b/static/koboldai.js index 4902908f..1544ee93 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -776,7 +776,6 @@ function update_status_bar(data) { } function do_ai_busy(data) { - console.log("AIBUSY", data.value) ai_busy = data.value; // Don't allow editing while Mr. Kobold is thinking document.getElementById("Selected Text").contentEditable = !ai_busy;