From 3f73f84b692f69284eeee6eadf0e1da4edfd97ee Mon Sep 17 00:00:00 2001 From: ebolam Date: Mon, 28 Feb 2022 19:04:12 -0500 Subject: [PATCH 1/3] bug fix --- aiserver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiserver.py b/aiserver.py index 66c0e197..c0e680c7 100644 --- a/aiserver.py +++ b/aiserver.py @@ -2676,7 +2676,7 @@ def actionsubmit(data, actionmode=0, force_submit=False, force_prompt_gen=False, # we'll have two conditions. # 1. This is totally new (user entered) if vars.actions.get_next_id()-1 not in vars.actions_metadata: - vars.actions_metadata.append({"Selected Text": data, "Alternative Text": []}) + vars.actions_metadata[vars.actions.get_next_id()-1] = {"Selected Text": data, "Alternative Text": []} else: # 2. We've selected a chunk of text that is was presented previously try: From 26b92683912c40afe40c6781639fddc598205657 Mon Sep 17 00:00:00 2001 From: ebolam Date: Fri, 4 Mar 2022 14:14:44 -0500 Subject: [PATCH 2/3] Redo bug fix --- aiserver.py | 71 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/aiserver.py b/aiserver.py index c0e680c7..6d7fd10d 100644 --- a/aiserver.py +++ b/aiserver.py @@ -2675,8 +2675,8 @@ def actionsubmit(data, actionmode=0, force_submit=False, force_prompt_gen=False, # we now need to update the actions_metadata # we'll have two conditions. # 1. This is totally new (user entered) - if vars.actions.get_next_id()-1 not in vars.actions_metadata: - vars.actions_metadata[vars.actions.get_next_id()-1] = {"Selected Text": data, "Alternative Text": []} + if vars.actions.get_last_key() not in vars.actions_metadata: + vars.actions_metadata[vars.actions.get_last_key()] = {"Selected Text": data, "Alternative Text": []} else: # 2. We've selected a chunk of text that is was presented previously try: @@ -2686,9 +2686,9 @@ def actionsubmit(data, actionmode=0, force_submit=False, force_prompt_gen=False, print(vars.actions_metadata) raise if data in alternatives: - alternatives = [item for item in vars.actions_metadata[vars.actions.get_next_id()-1 ]["Alternative Text"] if item['Text'] != data] - vars.actions_metadata[vars.actions.get_next_id()-1]["Alternative Text"] = alternatives - vars.actions_metadata[vars.actions.get_next_id()-1]["Selected Text"] = data + alternatives = [item for item in vars.actions_metadata[vars.actions.get_last_key() ]["Alternative Text"] if item['Text'] != data] + vars.actions_metadata[vars.actions.get_last_key()]["Alternative Text"] = alternatives + vars.actions_metadata[vars.actions.get_last_key()]["Selected Text"] = data update_story_chunk('last') send_debug() @@ -2746,11 +2746,11 @@ def actionretry(data): if(vars.gamestarted if vars.useprompt else len(vars.actions) > 0): if(not vars.recentback and len(vars.actions) != 0 and len(vars.genseqs) == 0): # Don't pop if we're in the "Select sequence to keep" menu or if there are no non-prompt actions # We are going to move the selected text to alternative text in the actions_metadata variable so we can redo this action - vars.actions_metadata[vars.actions.get_next_id()-1 ]['Alternative Text'] = [{'Text': vars.actions_metadata[vars.actions.get_next_id()-1 ]['Selected Text'], + vars.actions_metadata[vars.actions.get_last_key() ]['Alternative Text'] = [{'Text': vars.actions_metadata[vars.actions.get_last_key() ]['Selected Text'], 'Pinned': False, "Previous Selection": True, - "Edited": False}] + vars.actions_metadata[vars.actions.get_next_id()-1 ]['Alternative Text'] - vars.actions_metadata[vars.actions.get_next_id()-1]['Selected Text'] = "" + "Edited": False}] + vars.actions_metadata[vars.actions.get_last_key() ]['Alternative Text'] + vars.actions_metadata[vars.actions.get_last_key()]['Selected Text'] = "" @@ -2774,18 +2774,18 @@ def actionback(): # Remove last index of actions and refresh game screen if(len(vars.genseqs) == 0 and len(vars.actions) > 0): # We are going to move the selected text to alternative text in the actions_metadata variable so we can redo this action - vars.actions_metadata[vars.actions.get_next_id()-1 ]['Alternative Text'] = [{'Text': vars.actions_metadata[vars.actions.get_next_id()-1 ]['Selected Text'], + vars.actions_metadata[vars.actions.get_last_key() ]['Alternative Text'] = [{'Text': vars.actions_metadata[vars.actions.get_last_key() ]['Selected Text'], 'Pinned': False, "Previous Selection": True, - "Edited": False}] + vars.actions_metadata[vars.actions.get_next_id()-1 ]['Alternative Text'] - vars.actions_metadata[vars.actions.get_next_id()-1 ]['Selected Text'] = "" + "Edited": False}] + vars.actions_metadata[vars.actions.get_last_key() ]['Alternative Text'] + vars.actions_metadata[vars.actions.get_last_key() ]['Selected Text'] = "" last_key = vars.actions.get_last_key() vars.actions.pop() vars.recentback = True remove_story_chunk(last_key + 1) #for the redo to not get out of whack, need to reset the max # in the actions sequence - vars.actions.set_next_id(vars.actions.get_next_id()-1) + vars.actions.set_next_id(vars.actions.get_last_key()) elif(len(vars.genseqs) == 0): emit('from_server', {'cmd': 'errmsg', 'data': "Cannot delete the prompt."}) else: @@ -3206,10 +3206,10 @@ def genresult(genout, flash=True): vars.prompt = genout else: vars.actions.append(genout) - if vars.actions.get_next_id()-1 not in vars.actions_metadata: - vars.actions_metadata[vars.actions.get_next_id()-1] = {'Selected Text': genout, 'Alternative Text': []} + if vars.actions.get_last_key() not in vars.actions_metadata: + vars.actions_metadata[vars.actions.get_last_key()] = {'Selected Text': genout, 'Alternative Text': []} else: - vars.actions_metadata[vars.actions.get_next_id()-1]['Selected Text'] = genout + vars.actions_metadata[vars.actions.get_last_key()]['Selected Text'] = genout update_story_chunk('last') if(flash): emit('from_server', {'cmd': 'texteffect', 'data': vars.actions.get_last_key() + 1 if len(vars.actions) else 0}, broadcast=True) @@ -3262,8 +3262,8 @@ def selectsequence(n): if(len(vars.lua_koboldbridge.feedback) != 0): vars.actions.append(vars.lua_koboldbridge.feedback) #We'll want to remove the option from the alternative text and put it in selected text - vars.actions_metadata[vars.actions.get_next_id()-1 ]['Alternative Text'] = [item for item in vars.actions_metadata[vars.actions.get_next_id()-1]['Alternative Text'] if item['Text'] != vars.lua_koboldbridge.feedback] - vars.actions_metadata[vars.actions.get_next_id()-1 ]['Selected Text'] = vars.lua_koboldbridge.feedback + vars.actions_metadata[vars.actions.get_last_key() ]['Alternative Text'] = [item for item in vars.actions_metadata[vars.actions.get_last_key()]['Alternative Text'] if item['Text'] != vars.lua_koboldbridge.feedback] + vars.actions_metadata[vars.actions.get_last_key() ]['Selected Text'] = vars.lua_koboldbridge.feedback update_story_chunk('last') emit('from_server', {'cmd': 'texteffect', 'data': vars.actions.get_last_key() + 1 if len(vars.actions) else 0}, broadcast=True) emit('from_server', {'cmd': 'hidegenseqs', 'data': ''}, broadcast=True) @@ -4166,15 +4166,15 @@ def ikrequest(txt): if not vars.quiet: print("{0}{1}{2}".format(colors.CYAN, genout, colors.END)) vars.actions.append(genout) - if vars.actions.get_next_id()-1 in vars.actions_metadata: - vars.actions_metadata[vars.actions.get_next_id()-1] = {"Selected Text": genout, "Alternative Text": []} + if vars.actions.get_last_key() in vars.actions_metadata: + vars.actions_metadata[vars.actions.get_last_key()] = {"Selected Text": genout, "Alternative Text": []} else: # 2. We've selected a chunk of text that is was presented previously - alternatives = [item['Text'] for item in vars.actions_metadata[vars.actions.get_next_id()-1]["Alternative Text"]] + alternatives = [item['Text'] for item in vars.actions_metadata[vars.actions.get_last_key()]["Alternative Text"]] if genout in alternatives: - alternatives = [item for item in vars.actions_metadata[vars.actions.get_next_id()-1]["Alternative Text"] if item['Text'] != genout] - vars.actions_metadata[vars.actions.get_next_id()-1]["Alternative Text"] = alternatives - vars.actions_metadata[vars.actions.get_next_id()-1]["Selected Text"] = genout + alternatives = [item for item in vars.actions_metadata[vars.actions.get_last_key()]["Alternative Text"] if item['Text'] != genout] + vars.actions_metadata[vars.actions.get_last_key()]["Alternative Text"] = alternatives + vars.actions_metadata[vars.actions.get_last_key()]["Selected Text"] = genout update_story_chunk('last') emit('from_server', {'cmd': 'texteffect', 'data': vars.actions.get_last_key() + 1 if len(vars.actions) else 0}, broadcast=True) send_debug() @@ -4236,15 +4236,15 @@ def oairequest(txt, min, max): if not vars.quiet: print("{0}{1}{2}".format(colors.CYAN, genout, colors.END)) vars.actions.append(genout) - if vars.actions.get_next_id()-1 in vars.actions_metadata: - vars.actions_metadata[vars.actions.get_next_id()-1] = {"Selected Text": genout, "Alternative Text": []} + if vars.actions.get_last_key() in vars.actions_metadata: + vars.actions_metadata[vars.actions.get_last_key()] = {"Selected Text": genout, "Alternative Text": []} else: # 2. We've selected a chunk of text that is was presented previously - alternatives = [item['Text'] for item in vars.actions_metadata[vars.actions.get_next_id()-1]["Alternative Text"]] + alternatives = [item['Text'] for item in vars.actions_metadata[vars.actions.get_last_key()]["Alternative Text"]] if genout in alternatives: - alternatives = [item for item in vars.actions_metadata[vars.actions.get_next_id()-1 ]["Alternative Text"] if item['Text'] != genout] - vars.actions_metadata[vars.actions.get_next_id()-1 ]["Alternative Text"] = alternatives - vars.actions_metadata[vars.actions.get_next_id()-1 ]["Selected Text"] = genout + alternatives = [item for item in vars.actions_metadata[vars.actions.get_last_key() ]["Alternative Text"] if item['Text'] != genout] + vars.actions_metadata[vars.actions.get_last_key() ]["Alternative Text"] = alternatives + vars.actions_metadata[vars.actions.get_last_key() ]["Selected Text"] = genout update_story_chunk('last') emit('from_server', {'cmd': 'texteffect', 'data': vars.actions.get_last_key() + 1 if len(vars.actions) else 0}, broadcast=True) send_debug() @@ -4501,6 +4501,7 @@ def loadRequest(loadpath, filename=None): del vars.actions vars.actions = structures.KoboldStoryRegister() actions = collections.deque(js["actions"]) + if "actions_metadata" in js: @@ -4510,7 +4511,8 @@ def loadRequest(loadpath, filename=None): #we need to redo the numbering of the actions_metadata since the actions list doesn't preserve it's number on saving if len(temp) > 0: counter = 0 - for i in range(max(temp)): + temp = {int(k):v for k,v in temp.items()} + for i in range(max(temp)+1): if i in temp: vars.actions_metadata[counter] = temp[i] counter += 1 @@ -4613,6 +4615,10 @@ def loadRequest(loadpath, filename=None): emit('from_server', {'cmd': 'setgamestate', 'data': 'ready'}, broadcast=True) emit('from_server', {'cmd': 'hidegenseqs', 'data': ''}, broadcast=True) print("{0}Story loaded from {1}!{2}".format(colors.GREEN, filename, colors.END)) + + print([k for k in vars.actions]) + print([k for k in vars.actions_metadata]) + send_debug() #==================================================================# # Import an AIDungon game exported with Mimi's tool @@ -5009,7 +5015,10 @@ if(vars.model in ("TPUMeshTransformerGPTJ",)): def send_debug(): if vars.debug: debug_info = "" - for variable in [["Newline Mode", vars.newlinemode], ["Action Length", vars.actions.get_last_key()], ["Actions Metadata Length", max(vars.actions_metadata) if len(vars.actions_metadata) > 0 else 0], ["Actions Metadata", vars.actions_metadata]]: + for variable in [["Newline Mode", vars.newlinemode], + ["Action Length", vars.actions.get_last_key()], ["Actions Metadata Length", max(vars.actions_metadata) if len(vars.actions_metadata) > 0 else 0], + ["Actions", [k for k in vars.actions]], ["Actions Metadata", [k for k in vars.actions_metadata]], + ["Last Action", vars.actions[vars.actions.get_last_key()]], ["Last Metadata", vars.actions_metadata[max(vars.actions_metadata)]]]: debug_info = "{}{}: {}\n".format(debug_info, variable[0], variable[1]) emit('from_server', {'cmd': 'debug_info', 'data': debug_info}, broadcast=True) From 321f45ccadba46340c3a297394941ac22b792946 Mon Sep 17 00:00:00 2001 From: ebolam Date: Fri, 4 Mar 2022 15:36:13 -0500 Subject: [PATCH 3/3] Fix debug to never crash (would on some initialization steps) --- aiserver.py | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/aiserver.py b/aiserver.py index 6d7fd10d..af86032d 100644 --- a/aiserver.py +++ b/aiserver.py @@ -5015,11 +5015,35 @@ if(vars.model in ("TPUMeshTransformerGPTJ",)): def send_debug(): if vars.debug: debug_info = "" - for variable in [["Newline Mode", vars.newlinemode], - ["Action Length", vars.actions.get_last_key()], ["Actions Metadata Length", max(vars.actions_metadata) if len(vars.actions_metadata) > 0 else 0], - ["Actions", [k for k in vars.actions]], ["Actions Metadata", [k for k in vars.actions_metadata]], - ["Last Action", vars.actions[vars.actions.get_last_key()]], ["Last Metadata", vars.actions_metadata[max(vars.actions_metadata)]]]: - debug_info = "{}{}: {}\n".format(debug_info, variable[0], variable[1]) + try: + debug_info = "{}Newline Mode: {}\n".format(debug_info, vars.newlinemode) + except: + pass + try: + debug_info = "{}Action Length: {}\n".format(debug_info, vars.actions.get_last_key()) + except: + pass + try: + debug_info = "{}Actions Metadata Length: {}\n".format(debug_info, max(vars.actions_metadata) if len(vars.actions_metadata) > 0 else 0) + except: + pass + try: + debug_info = "{}Actions: {}\n".format(debug_info, vars.actions.get_last_key()) + except: + pass + try: + debug_info = "{}Actions Metadata: {}\n".format(debug_info, [k for k in vars.actions_metadata]) + except: + pass + try: + debug_info = "{}Last Action: {}\n".format(debug_info, vars.actions[vars.actions.get_last_key()]) + except: + pass + try: + debug_info = "{}Last Metadata: {}\n".format(debug_info, vars.actions_metadata[max(vars.actions_metadata)]) + except: + pass + emit('from_server', {'cmd': 'debug_info', 'data': debug_info}, broadcast=True) #==================================================================#