mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-06-05 21:59:24 +02:00
Fix for auto-save
This commit is contained in:
20
aiserver.py
20
aiserver.py
@@ -7078,7 +7078,6 @@ def load_story_v1(js):
|
|||||||
temp_story_class.set_options(data, int(key))
|
temp_story_class.set_options(data, int(key))
|
||||||
koboldai_vars.actions.load_json(temp_story_class.to_json())
|
koboldai_vars.actions.load_json(temp_story_class.to_json())
|
||||||
logger.debug("Saved temp story class")
|
logger.debug("Saved temp story class")
|
||||||
time.sleep(30)
|
|
||||||
del temp_story_class
|
del temp_story_class
|
||||||
|
|
||||||
# Try not to break older save files
|
# 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 we have > 4 keys, use those otherwise use sumarization
|
||||||
if len(keys) < 4:
|
if len(keys) < 4:
|
||||||
start_time = time.time()
|
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('/', '_'))):
|
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")
|
koboldai_vars.summary_tokenizer = AutoTokenizer.from_pretrained("models/{}".format(args.summarizer_model.replace('/', '_')), cache_dir="cache")
|
||||||
else:
|
else:
|
||||||
koboldai_vars.summary_tokenizer = AutoTokenizer.from_pretrained(args.summarizer_model, cache_dir="cache")
|
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))
|
max_length = args.max_summary_length - len(koboldai_vars.summary_tokenizer.encode(art_guide))
|
||||||
keys = [summarize(text, max_length=max_length)]
|
keys = [summarize(text, max_length=max_length)]
|
||||||
|
logger.debug("Text from summarizer: {}".format(keys[0]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -140,6 +140,7 @@ class koboldai_vars(object):
|
|||||||
settings_file.write(self._system_settings.to_json())
|
settings_file.write(self._system_settings.to_json())
|
||||||
|
|
||||||
def save_story(self):
|
def save_story(self):
|
||||||
|
logger.debug("Saving story from koboldai_vars.save_story()")
|
||||||
self._story_settings[self.get_story_name()].save_story()
|
self._story_settings[self.get_story_name()].save_story()
|
||||||
|
|
||||||
def save_revision(self):
|
def save_revision(self):
|
||||||
@@ -728,7 +729,8 @@ class story_settings(settings):
|
|||||||
def save_story(self):
|
def save_story(self):
|
||||||
if not self.no_save:
|
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:
|
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"
|
save_name = self.story_name if self.story_name != "" else "untitled"
|
||||||
adder = ""
|
adder = ""
|
||||||
while True:
|
while True:
|
||||||
@@ -805,6 +807,7 @@ class story_settings(settings):
|
|||||||
|
|
||||||
#autosave action
|
#autosave action
|
||||||
if name == "gamesaved" and value == False and self.autosave:
|
if name == "gamesaved" and value == False and self.autosave:
|
||||||
|
logger.debug("Saving story from gamesaved change and on autosave")
|
||||||
self.save_story()
|
self.save_story()
|
||||||
if not new_variable and old_value != value:
|
if not new_variable and old_value != value:
|
||||||
#Change game save state
|
#Change game save state
|
||||||
@@ -1174,8 +1177,6 @@ class KoboldStoryRegister(object):
|
|||||||
logger.debug("Calcing AI Text from Action load from json")
|
logger.debug("Calcing AI Text from Action load from json")
|
||||||
ignore = self.koboldai_vars.calc_ai_text()
|
ignore = self.koboldai_vars.calc_ai_text()
|
||||||
self.set_game_saved()
|
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):
|
def append(self, text, action_id_offset=0, recalc=True):
|
||||||
self.clear_unused_options()
|
self.clear_unused_options()
|
||||||
|
Reference in New Issue
Block a user