Fix for critical bug on saving causing infinite loop

This commit is contained in:
ebolam
2022-08-16 13:09:13 -04:00
parent fa37484eb3
commit da036ce712
3 changed files with 21 additions and 4 deletions

View File

@@ -6350,12 +6350,14 @@ def UI_2_Set_Selected_Text(data):
def UI_2_submit(data):
print(data)
if not koboldai_vars.noai and data['theme'] != "":
print("doing random prompt")
memory = koboldai_vars.memory
koboldai_vars.memory = "{}\n\nYou generate the following {} story concept :".format(koboldai_vars.memory, data['theme'])
koboldai_vars.lua_koboldbridge.feedback = None
actionsubmit("", force_submit=True, force_prompt_gen=True)
koboldai_vars.memory = memory
else:
print("doing normal input")
koboldai_vars.actions.clear_unused_options()
koboldai_vars.lua_koboldbridge.feedback = None
koboldai_vars.recentrng = koboldai_vars.recentrngm = None

View File

@@ -38,6 +38,7 @@ def process_variable_changes(socketio, classname, name, value, old_value, debug_
socketio.emit("var_changed", {"classname": "actions", "name": "Selected Text", "old_value": None, "value": {"id": i, "text": value[i]}}, include_self=True, broadcast=True, room="UI_2")
socketio.emit("var_changed", {"classname": "actions", "name": "Options", "old_value": None, "value": {"id": i, "options": value.actions[i]['Options']}}, include_self=True, broadcast=True, room="UI_2")
socketio.emit("var_changed", {"classname": "actions", "name": "Selected Text Length", "old_value": None, "value": {"id": i, 'length': value.actions[i]['Selected Text Length']}}, include_self=True, broadcast=True, room="UI_2")
if 'In AI Input' in value.actions[i]:
socketio.emit("var_changed", {"classname": "actions", "name": "In AI Input", "old_value": None, "value": {"id": i, 'In AI Input': value.actions[i]['In AI Input']}}, include_self=True, broadcast=True, room="UI_2")
elif isinstance(value, KoboldWorldInfo):
value.send_to_ui()
@@ -519,7 +520,21 @@ class story_settings(settings):
def save_story(self):
print("Saving")
save_name = self.story_name if self.story_name != "" else "untitled"
with open("stories/{}_v2.json".format(save_name), "w") as settings_file:
adder = ""
while True:
if os.path.exists("stories/{}{}_v2.json".format(save_name, adder)):
with open("stories/{}{}_v2.json".format(save_name, adder), "r") as f:
temp = json.load(f)
if 'story_id' in temp:
if self.story_id != temp['story_id']:
adder = 0 if adder == "" else adder+1
else:
break
else:
adder = 0 if adder == "" else adder+1
else:
break
with open("stories/{}{}_v2.json".format(save_name, adder), "w") as settings_file:
settings_file.write(self.to_json())
self.gamesaved = True
@@ -1019,7 +1034,7 @@ class KoboldWorldInfo(object):
self.story_settings = story_settings
def reset(self):
self.__init__(self.socketio, self.story_settings, self.tokenizer)
self.__init__(self.socketio, self.story_settings, self.koboldai_vars, self.tokenizer)
def __iter__(self):
self.itter = -1

View File

@@ -69,7 +69,7 @@
<div class="statusbar_inner" style="width:0%">0%</div>
</div><br>
<button type="button" class="btn action_button submit var_sync_alt_system_aibusy" system_aibusy=False id="btnsend"
onclick="socket.emit('submit', {'data': document.getElementById('input_text').value, 'theme': document.getElementById('themetext').value});document.getElementById('input_text').value = '';"
onclick="socket.emit('submit', {'data': document.getElementById('input_text').value, 'theme': document.getElementById('themetext').value});document.getElementById('input_text').value = '';document.getElementById('themetext').value = '';"
>Submit</button>
<button type="button" class="btn action_button submited var_sync_alt_system_aibusy" system_aibusy=False id="btnsend"><img src="static/thinking.gif" class="force_center" onclick="socket.emit('abort','');"></button>
<button type="button" class="btn action_button back" onclick="socket.emit('back', {});"><span class="oi" data-glyph="action-undo"></span></button>