Additional speed improvements

This commit is contained in:
ebolam
2022-09-30 08:34:37 -04:00
parent 6235be272e
commit 1e9be02770
3 changed files with 51 additions and 40 deletions

View File

@@ -8246,10 +8246,12 @@ def story_sort(base_path, desc=False):
@socketio.on('load_story')
@logger.catch
def UI_2_load_story(file):
start_time = time.time()
logger.debug("got a call or loading a story: {}".format(file))
if koboldai_vars.debug:
print("loading {}".format(file))
loadRequest(file)
logger.debug("Load Story took {}s".format(time.time()-start_time))
#==================================================================#
# Event triggered on load story

View File

@@ -456,6 +456,7 @@ class settings(object):
if 'no_save' in self.__dict__:
setattr(self, 'no_save', True)
for key, value in json_data.items():
start_time = time.time()
if key in self.__dict__ and key not in self.no_save_variables:
if key == 'sampler_order':
if(len(value) < 7):
@@ -480,6 +481,7 @@ class settings(object):
getattr(self, key).load_json(value)
else:
setattr(self, key, value)
logger.debug("Loading {} took {}s".format(key, time.time()- start_time))
if 'no_save' in self.__dict__:
setattr(self, 'no_save', False)
@@ -738,7 +740,7 @@ class story_settings(settings):
wi.get("constant", False),
wi["content"],
wi.get("comment", ""),
v1_uid=wi['uid'])
v1_uid=wi['uid'], sync=False)
new_world_info.socketio = self.socketio
self.worldinfo_v2 = new_world_info
@@ -1098,13 +1100,12 @@ class KoboldStoryRegister(object):
if type(json_data) == str:
import json
json_data = json.loads(json_data)
self.action_count = json_data['action_count']
#JSON forces keys to be strings, so let's fix that
temp = {}
for item in json_data['actions']:
temp[int(item)] = json_data['actions'][item]
process_variable_changes(self.socketio, "story", 'actions', {"id": item, 'action': temp[int(item)]}, None)
self.action_count = json_data['action_count']
self.actions = temp
self.set_game_saved()
self.story_settings.save_story()
@@ -1550,7 +1551,7 @@ class KoboldWorldInfo(object):
def add_item(self, title, key, keysecondary, folder, constant, manual_text,
comment, use_wpp=False, wpp={'name': "", 'type': "", 'format': "W++", 'attributes': {}},
v1_uid=None, recalc=True):
v1_uid=None, recalc=True, sync=True):
if len(self.world_info) == 0:
uid = 0
else:
@@ -1568,10 +1569,10 @@ class KoboldWorldInfo(object):
content = "{} ]".format(content[:-1])
else:
content = manual_text
if self.tokenizer is not None:
token_length = len(self.tokenizer.encode(content))
else:
token_length = 0
#if self.tokenizer is not None:
# token_length = len(self.tokenizer.encode(content))
#else:
token_length = 0
if folder is None:
folder = "root"
@@ -1610,7 +1611,8 @@ class KoboldWorldInfo(object):
self.world_info_folder[folder] = []
self.world_info_folder[folder].append(uid)
self.story_settings.gamesaved = False
self.sync_world_info_to_old_format()
if sync:
self.sync_world_info_to_old_format()
if self.socketio is not None:
self.socketio.emit("world_info_folder", {x: self.world_info_folder[x] for x in self.world_info_folder}, broadcast=True, room="UI_2")
@@ -1742,6 +1744,7 @@ class KoboldWorldInfo(object):
#Add the item
for uid, item in data['entries'].items():
start_time = time.time()
self.add_item(item['title'] if 'title' in item else item['key'][0],
item['key'] if 'key' in item else [],
item['keysecondary'] if 'keysecondary' in item else [],
@@ -1751,10 +1754,12 @@ class KoboldWorldInfo(object):
item['comment'] if 'comment' in item else '',
use_wpp=item['use_wpp'] if 'use_wpp' in item else False,
wpp=item['wpp'] if 'wpp' in item else {'name': "", 'type': "", 'format': "W++", 'attributes': {}},
recalc=False)
recalc=False, sync=False)
logger.debug("Load World Info {} took {}s".format(uid, time.time()-start_time))
try:
start_time = time.time()
self.sync_world_info_to_old_format()
logger.debug("Syncing WI2 to WI1 took {}s".format(time.time()-start_time))
except:
print(self.world_info)
print(data)

View File

@@ -114,6 +114,7 @@ map2.set(5, 'Temperature')
map2.set(6, 'Repetition Penalty')
var calc_token_usage_timeout;
var game_text_scroll_timeout;
var world_info_scroll_timeout;
var font_size_cookie_timout;
var var_processing_time = 0;
var finder_last_input;
@@ -140,6 +141,7 @@ function reset_story() {
clearTimeout(calc_token_usage_timeout);
clearTimeout(game_text_scroll_timeout);
clearTimeout(font_size_cookie_timout);
clearTimeout(world_info_scroll_timeout);
finder_last_input = null;
on_new_wi_item = null;
current_chunk_number = null;
@@ -320,8 +322,11 @@ function do_story_text_updates(data) {
story_area.append(span);
clearTimeout(game_text_scroll_timeout);
game_text_scroll_timeout = setTimeout(function() {document.getElementById("Selected Text").scrollTop = document.getElementById("Selected Text").scrollHeight;}, 500);
if (data.value.id.toString() == document.getElementById('action_count').textContent) {
document.getElementById("Selected Text").scrollTop = document.getElementById("Selected Text").scrollHeight;
}
//clearTimeout(game_text_scroll_timeout);
//game_text_scroll_timeout = setTimeout(function() {document.getElementById("Selected Text").scrollTop = document.getElementById("Selected Text").scrollHeight;}, 500);
if (span.textContent != "") {
assign_world_info_to_action(span, null);
}
@@ -3001,8 +3006,11 @@ function create_new_wi_entry(folder) {
"wpp": {'name': "", 'type': "", 'format': 'W++', 'attributes': {}},
'use_wpp': false,
};
card = world_info_entry(data);
card.scrollIntoView(false);
var card = world_info_entry(data);
//card.scrollIntoView(false);
clearTimeout(world_info_scroll_timeout);
world_info_scroll_timeout = setTimeout(function() {card.scrollIntoView(false);}, 200);
}
function hide_wi_folder(folder) {
@@ -3142,34 +3150,30 @@ function assign_world_info_to_action(action_item, uid) {
//First check to see if we have a key in the text
for (const [key, worldinfo] of Object.entries(worldinfo_to_check)) {
//remove any world info tags on the overall chunk
for (tag of action.getElementsByClassName("tag_uid_"+uid)) {
tag.classList.remove("tag_uid_"+uid);
tag.removeAttribute("title");
current_ids = tag.parentElement.getAttribute("world_info_uids").split(",");
removeA(current_ids, uid);
tag.parentElement.setAttribute("world_info_uids", current_ids.join(","));
}
if (worldinfo.key == undefined) {
console.log(uid);
console.log(key);
console.log(worldinfo);
console.log(world_info_data);
}
for (keyword of worldinfo['key']) {
if ((action.textContent.replace(/[^0-9a-z \'\"]/gi, '')).includes(keyword)) {
//Ok we have a key match, but we need to check for secondary keys if applicable
if (worldinfo['keysecondary'].length > 0) {
for (second_key of worldinfo['keysecondary']) {
if (action.textContent.replace(/[^0-9a-z \'\"]/gi, '').includes(second_key)) {
highlight_world_info_text_in_chunk(action, worldinfo);
break;
if (worldinfo['constant'] == false) {
for (tag of action.getElementsByClassName("tag_uid_"+uid)) {
tag.classList.remove("tag_uid_"+uid);
tag.removeAttribute("title");
current_ids = tag.parentElement.getAttribute("world_info_uids").split(",");
removeA(current_ids, uid);
tag.parentElement.setAttribute("world_info_uids", current_ids.join(","));
}
for (keyword of worldinfo['key']) {
if ((action.textContent.replace(/[^0-9a-z \'\"]/gi, '')).includes(keyword)) {
//Ok we have a key match, but we need to check for secondary keys if applicable
if (worldinfo['keysecondary'].length > 0) {
for (second_key of worldinfo['keysecondary']) {
if (action.textContent.replace(/[^0-9a-z \'\"]/gi, '').includes(second_key)) {
highlight_world_info_text_in_chunk(action, worldinfo);
break;
}
}
} else {
highlight_world_info_text_in_chunk(action, worldinfo);
break;
}
} else {
highlight_world_info_text_in_chunk(action, worldinfo);
break;
}
}
}
}