Merge pull request #423 from one-some/fix-introduced-bugs

Fix streaming bugs
This commit is contained in:
henk717
2023-07-25 18:58:16 +02:00
committed by GitHub
3 changed files with 52 additions and 9 deletions

View File

@@ -3280,9 +3280,6 @@ def actionsubmit(data, actionmode=0, force_submit=False, force_prompt_gen=False,
if(koboldai_vars.aibusy): if(koboldai_vars.aibusy):
return return
# Open up token stream
emit("stream_tokens", True, broadcast=True, room="UI_2")
while(True): while(True):
set_aibusy(1) set_aibusy(1)
koboldai_vars.actions.clear_unused_options() 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) set_aibusy(0)
emit('from_server', {'cmd': 'scrolldown', 'data': ''}, broadcast=True, room="UI_1") emit('from_server', {'cmd': 'scrolldown', 'data': ''}, broadcast=True, room="UI_1")
break break
# Clean up token stream
emit("stream_tokens", None, broadcast=True, room="UI_2")
def apiactionsubmit_generate(txt, minimum, maximum): def apiactionsubmit_generate(txt, minimum, maximum):
koboldai_vars.generated_tkns = 0 koboldai_vars.generated_tkns = 0
@@ -3903,7 +3898,10 @@ class HordeException(Exception):
# Send text to generator and deal with output # 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 koboldai_vars.generated_tkns = 0
if(found_entries is None): 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") 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", "")) logger.error(traceback.format_exc().replace("\033", ""))
socketio.emit("error", str(e), broadcast=True, room="UI_2") socketio.emit("error", str(e), broadcast=True, room="UI_2")
set_aibusy(0) set_aibusy(0)
# Clean up token stream
emit("stream_tokens", None, broadcast=True, room="UI_2")
return return
for i in range(koboldai_vars.numseqs): for i in range(koboldai_vars.numseqs):
@@ -3972,7 +3973,10 @@ def generate(txt, minimum, maximum, found_entries=None):
del genout del genout
gc.collect() gc.collect()
torch.cuda.empty_cache() torch.cuda.empty_cache()
# Clean up token stream
emit("stream_tokens", None, broadcast=True, room="UI_2")
maybe_review_story() maybe_review_story()
set_aibusy(0) set_aibusy(0)

View File

@@ -85,6 +85,7 @@ var dirty_chunks = [];
var initial_socketio_connection_occured = false; var initial_socketio_connection_occured = false;
var selected_model_data; var selected_model_data;
var privacy_mode_enabled = false; var privacy_mode_enabled = false;
var ai_busy = false;
var streaming = { var streaming = {
windowOpen: false, windowOpen: false,
@@ -775,6 +776,10 @@ function update_status_bar(data) {
} }
function do_ai_busy(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) { if (data.value) {
ai_busy_start = Date.now(); ai_busy_start = Date.now();
favicon.start_swap() 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. //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 //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"); 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 //Fix missing story prompt
if (dirty_chunks.includes("-1")) { if (dirty_chunks.includes("-1")) {
if (!document.getElementById("story_prompt")) { if (!document.getElementById("story_prompt")) {
@@ -3277,6 +3287,7 @@ function fix_dirty_game_text() {
game_text.prepend(story_prompt); game_text.prepend(story_prompt);
} }
} }
if (dirty_chunks.includes("game_text")) { if (dirty_chunks.includes("game_text")) {
dirty_chunks = dirty_chunks.filter(item => item != "game_text"); dirty_chunks = dirty_chunks.filter(item => item != "game_text");
console.log("Firing Fix messed up text"); console.log("Firing Fix messed up text");
@@ -3312,7 +3323,7 @@ function fix_dirty_game_text() {
function savegametextchanges() { function savegametextchanges() {
fix_dirty_game_text(); fix_dirty_game_text();
for (item of document.getElementsByClassName("editing")) { for (const item of document.getElementsByClassName("editing")) {
item.classList.remove("editing"); item.classList.remove("editing");
} }
if (dirty_chunks.length > 0) { if (dirty_chunks.length > 0) {
@@ -7631,4 +7642,32 @@ $el("#gamescreen").addEventListener("paste", function(event) {
false, false,
event.clipboardData.getData("text/plain") 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();
}); });

View File

@@ -53,7 +53,7 @@
<div id="welcome_text" class="var_sync_model_welcome" draggable="False"></div> <div id="welcome_text" class="var_sync_model_welcome" draggable="False"></div>
</div> </div>
<div class="gametext" id="Selected Text" contenteditable=false tabindex=0 onpaste="check_game_after_paste()" onfocusout="savegametextchanges();" onclick="return set_edit(event)" onkeyup="return set_edit(event);"> <div class="gametext" id="Selected Text" contenteditable="false" tabindex="0" onkeyup="return set_edit(event);">
<span id="story_prompt" class="var_sync_story_prompt var_sync_alt_story_prompt_in_ai rawtext hidden" chunk="-1"></span></div><!--don't move the /div down or it'll cause odd spacing issues in the UI---> <span id="story_prompt" class="var_sync_story_prompt var_sync_alt_story_prompt_in_ai rawtext hidden" chunk="-1"></span></div><!--don't move the /div down or it'll cause odd spacing issues in the UI--->
</div> </div>