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,14 +1441,15 @@ 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
tokens = self.koboldai_vars.tokenizer.encode(text) if self.koboldai_vars.tokenizer is not None:
if 'oribabilities' in self.actions[i]: tokens = self.koboldai_vars.tokenizer.encode(text)
for token_num in range(len(self.actions[i]["Probabilities"])): if 'Probabilities' in self.actions[i]:
for token_option in range(len(self.actions[i]["Probabilities"][token_num])): for token_num in range(len(self.actions[i]["Probabilities"])):
if token_num < len(tokens): for token_option in range(len(self.actions[i]["Probabilities"][token_num])):
self.actions[i]["Probabilities"][token_num][token_option]["Used"] = tokens[token_num] == self.actions[i]["Probabilities"][token_num][token_option]["tokenId"] if token_num < len(tokens):
else: self.actions[i]["Probabilities"][token_num][token_option]["Used"] = tokens[token_num] == self.actions[i]["Probabilities"][token_num][token_option]["tokenId"]
self.actions[i]["Probabilities"][token_num][token_option]["Used"] = False else:
self.actions[i]["Probabilities"][token_num][token_option]["Used"] = False
if "Options" in self.actions[i]: if "Options" in self.actions[i]:
for j in range(len(self.actions[i]["Options"])): for j in range(len(self.actions[i]["Options"])):
if self.actions[i]["Options"][j]["text"] == text: if self.actions[i]["Options"][j]["text"] == text: