Fix for auto-save

This commit is contained in:
ebolam
2022-10-07 14:03:23 -04:00
parent 8664316470
commit 899c47b38c
2 changed files with 17 additions and 10 deletions

View File

@@ -7078,7 +7078,6 @@ def load_story_v1(js):
temp_story_class.set_options(data, int(key))
koboldai_vars.actions.load_json(temp_story_class.to_json())
logger.debug("Saved temp story class")
time.sleep(30)
del temp_story_class
# Try not to break older save files
@@ -8817,18 +8816,25 @@ def UI_2_generate_image(data):
#If we have > 4 keys, use those otherwise use sumarization
if len(keys) < 4:
start_time = time.time()
#text to summarize:
if len(koboldai_vars.actions) < 5:
text = "".join(koboldai_vars.actions[:-5]+[koboldai_vars.prompt])
else:
text = "".join(koboldai_vars.actions[:-5])
if os.path.exists("models/{}".format(args.summarizer_model.replace('/', '_'))):
koboldai_vars.summary_tokenizer = AutoTokenizer.from_pretrained("models/{}".format(args.summarizer_model.replace('/', '_')), cache_dir="cache")
else:
koboldai_vars.summary_tokenizer = AutoTokenizer.from_pretrained(args.summarizer_model, cache_dir="cache")
#text to summarize (get 1000 tokens worth of text):
text = []
text_length = 0
for item in reversed(koboldai_vars.actions.to_sentences()):
if len(koboldai_vars.summary_tokenizer.encode(item[0])) + text_length <= 1000:
text.append(item[0])
text_length += len(koboldai_vars.summary_tokenizer.encode(item[0]))
else:
break
text = "".join(text)
logger.debug("Text to summarizer: {}".format(text))
max_length = args.max_summary_length - len(koboldai_vars.summary_tokenizer.encode(art_guide))
keys = [summarize(text, max_length=max_length)]
logger.debug("Text from summarizer: {}".format(keys[0]))

View File

@@ -140,6 +140,7 @@ class koboldai_vars(object):
settings_file.write(self._system_settings.to_json())
def save_story(self):
logger.debug("Saving story from koboldai_vars.save_story()")
self._story_settings[self.get_story_name()].save_story()
def save_revision(self):
@@ -728,7 +729,8 @@ class story_settings(settings):
def save_story(self):
if not self.no_save:
if self.prompt != "" or self.memory != "" or self.authornote != "" or len(self.actions) > 0 or len(self.worldinfo_v2) > 0:
print("Saving")
logger.debug("Saving story from koboldai_vars.story_settings.save_story()")
logger.info("Saving")
save_name = self.story_name if self.story_name != "" else "untitled"
adder = ""
while True:
@@ -805,6 +807,7 @@ class story_settings(settings):
#autosave action
if name == "gamesaved" and value == False and self.autosave:
logger.debug("Saving story from gamesaved change and on autosave")
self.save_story()
if not new_variable and old_value != value:
#Change game save state
@@ -1174,8 +1177,6 @@ class KoboldStoryRegister(object):
logger.debug("Calcing AI Text from Action load from json")
ignore = self.koboldai_vars.calc_ai_text()
self.set_game_saved()
if self.story_settings is not None:
self.story_settings.save_story()
def append(self, text, action_id_offset=0, recalc=True):
self.clear_unused_options()