diff --git a/aiserver.py b/aiserver.py index 2115c709..77afc3d0 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) diff --git a/static/koboldai.js b/static/koboldai.js index f775f3f0..1544ee93 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,10 @@ function update_status_bar(data) { } function do_ai_busy(data) { + 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 +3270,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 +3287,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 +3323,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 +7642,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 @@
-