Potential fix for setting action data crash (Issue 343)

This commit is contained in:
ebolam
2022-12-16 20:02:29 -05:00
parent 6204883b8b
commit eabbd73bf3

View File

@@ -1433,7 +1433,7 @@ class KoboldStoryRegister(object):
if self.koboldai_vars.remove_double_space: if self.koboldai_vars.remove_double_space:
while " " in text: while " " in text:
text = text.replace(" ", " ") text = text.replace(" ", " ")
if i > 0 and text != "": if i > 0 and text != "" and i-1 in self.actions and self.actions[i-1]['Selected Text'] != "":
if self.actions[i-1]['Selected Text'][-1] == " " and text[0] == " ": if self.actions[i-1]['Selected Text'][-1] == " " and text[0] == " ":
text = text[1:] text = text[1:]
if i in self.actions: if i in self.actions:
@@ -1441,8 +1441,9 @@ class KoboldStoryRegister(object):
old_text = self.actions[i]["Selected Text"] old_text = self.actions[i]["Selected Text"]
if self.actions[i]["Selected Text"] != text: if self.actions[i]["Selected Text"] != text:
self.actions[i]["Selected Text"] = text self.actions[i]["Selected Text"] = text
if self.koboldai_vars.tokenizer is not None:
tokens = self.koboldai_vars.tokenizer.encode(text) tokens = self.koboldai_vars.tokenizer.encode(text)
if 'oribabilities' in self.actions[i]: if 'Probabilities' in self.actions[i]:
for token_num in range(len(self.actions[i]["Probabilities"])): for token_num in range(len(self.actions[i]["Probabilities"])):
for token_option in range(len(self.actions[i]["Probabilities"][token_num])): for token_option in range(len(self.actions[i]["Probabilities"][token_num])):
if token_num < len(tokens): if token_num < len(tokens):