From 61774bffaa9a6d9dbace422c4021d1336edfa711 Mon Sep 17 00:00:00 2001 From: ebolam Date: Thu, 13 Oct 2022 12:21:49 -0400 Subject: [PATCH] Fix for "blinking" world info cards --- aiserver.py | 46 +++++++++++++------------------------------ koboldai_settings.py | 12 ++++++++++- static/application.js | 1 + static/koboldai.js | 4 +--- 4 files changed, 27 insertions(+), 36 deletions(-) diff --git a/aiserver.py b/aiserver.py index 7704c742..965dc83c 100644 --- a/aiserver.py +++ b/aiserver.py @@ -273,13 +273,15 @@ model_menu = { class Send_to_socketio(object): def write(self, bar): - print('\r' + bar, end='') - time.sleep(0.01) - try: - gui_msg = bar.replace(f"{colors.PURPLE}INIT{colors.END} | ","").replace(" ", " ") - emit('from_server', {'cmd': 'model_load_status', 'data': gui_msg}, broadcast=True, room="UI_1") - except: - pass + bar = bar.replace("\r", "").replace("\n", "") + if bar != "": + logger.info(bar) + #print('\r' + bar, end='') + time.sleep(0.01) + try: + emit('from_server', {'cmd': 'model_load_status', 'data': bar.replace(" ", " ")}, broadcast=True, room="UI_1") + except: + pass def flush(self): pass @@ -1752,6 +1754,7 @@ def patch_transformers_download(): class Send_to_socketio(object): def write(self, bar): bar = bar.replace("\r", "").replace("\n", "") + logger.debug(bar) if bar != "": try: @@ -2568,7 +2571,7 @@ def load_model(use_gpu=True, gpu_layers=None, disk_layers=None, initial_load=Fal print(flush=True) koboldai_vars.total_layers = num_tensors koboldai_vars.loaded_layers = 0 - utils.bar = tqdm(total=num_tensors, desc=f"{colors.PURPLE}INIT{colors.END} | Loading model tensors", file=Send_to_socketio()) + utils.bar = tqdm(total=num_tensors, desc="Loading model tensors", file=Send_to_socketio()) with zipfile.ZipFile(f, "r") as z: try: @@ -3105,31 +3108,10 @@ def download(): filename = filename[:-5] save.headers.set('Content-Disposition', 'attachment', filename='%s.txt' % filename) return(save) - - # Build json to write - js = {} - js["gamestarted"] = koboldai_vars.gamestarted - js["prompt"] = koboldai_vars.prompt - js["memory"] = koboldai_vars.memory - js["authorsnote"] = koboldai_vars.authornote - js["anotetemplate"] = koboldai_vars.authornotetemplate - js["actions"] = koboldai_vars.actions.to_json() - js["worldinfo"] = [] - - # Extract only the important bits of WI - for wi in koboldai_vars.worldinfo: - if(wi["constant"] or wi["key"] != ""): - js["worldinfo"].append({ - "key": wi["key"], - "keysecondary": wi["keysecondary"], - "content": wi["content"], - "comment": wi["comment"], - "folder": wi["folder"], - "selective": wi["selective"], - "constant": wi["constant"] - }) - save = Response(json.dumps(js, indent=3)) + + + save = Response(koboldai_vars.download_story()) filename = path.basename(koboldai_vars.savedir) if filename[-5:] == ".json": filename = filename[:-5] diff --git a/koboldai_settings.py b/koboldai_settings.py index 71a7cfc9..18d09c03 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -144,6 +144,9 @@ class koboldai_vars(object): logger.debug("Saving story from koboldai_vars.save_story()") self._story_settings[self.get_story_name()].save_story() + def download_story(self): + return self._story_settings[self.get_story_name()].to_json() + def save_revision(self): self._story_settings[self.get_story_name()].save_revision() @@ -1620,6 +1623,7 @@ class KoboldWorldInfo(object): if self.koboldai_vars.tokenizer is not None: if uid is not None: if uid in self.world_info: + logger.debug("Sending all world info after tokenizing") self.world_info[uid]['token_length'] = len(self.koboldai_vars.tokenizer.encode(self.world_info[uid]['content'])) self.socketio.emit("world_info_entry", self.world_info[uid], broadcast=True, room="UI_2") else: @@ -1627,9 +1631,13 @@ class KoboldWorldInfo(object): self.world_info[uid]['token_length'] = len(self.koboldai_vars.tokenizer.encode(self.world_info[uid]['content'])) self.send_to_ui() else: + had_change = False for uid in self.world_info: + if self.world_info[uid]['token_length'] != 0 and not had_change: + had_change = True self.world_info[uid]['token_length'] = 0 - self.send_to_ui() + if had_change: + self.send_to_ui() def add_folder(self, folder): @@ -1754,6 +1762,7 @@ class KoboldWorldInfo(object): return uid def edit_item(self, uid, title, key, keysecondary, folder, constant, manual_text, comment, use_wpp=False, before=None, wpp={'name': "", 'type': "", 'format': "W++", 'attributes': {}}): + logger.debug("Editing World Info {}: {}".format(uid, title)) old_folder = self.world_info[uid]['folder'] #move the world info entry if the folder changed or if there is a new order requested if old_folder != folder or before is not None: @@ -1853,6 +1862,7 @@ class KoboldWorldInfo(object): def send_to_ui(self): if self.socketio is not None: self.socketio.emit("world_info_folder", {x: self.world_info_folder[x] for x in self.world_info_folder}, broadcast=True, room="UI_2") + logger.debug("Sending all world info from send_to_ui") for uid in self.world_info: self.socketio.emit("world_info_entry", self.world_info[uid], broadcast=True, room="UI_2") diff --git a/static/application.js b/static/application.js index f121903f..81940fd3 100644 --- a/static/application.js +++ b/static/application.js @@ -3024,6 +3024,7 @@ $(document).ready(function(){ location.reload(); //console.log("Closing window"); } else if(msg.cmd == 'model_load_status') { + console.log(msg.data); $("#showmodelnamecontent").html("
" + msg.data + "
"); $("#showmodelnamecontainer").removeClass("hidden"); //console.log(msg.data); diff --git a/static/koboldai.js b/static/koboldai.js index 3362b916..2008536b 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -1613,8 +1613,6 @@ function world_info_entry_used_in_game(data) { } function world_info_entry(data) { - - world_info_data[data.uid] = data; //delete the existing world info and recreate @@ -1909,7 +1907,7 @@ function world_info_entry(data) { update_token_lengths(); 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, 10); return world_info_card; }