mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-06-05 21:59:24 +02:00
World Info working with re-sorting (changing folders doesn't work yet)
This commit is contained in:
85
aiserver.py
85
aiserver.py
@@ -1192,12 +1192,14 @@ def patch_transformers_download():
|
|||||||
import copy, requests, tqdm, time
|
import copy, requests, tqdm, time
|
||||||
class Send_to_socketio(object):
|
class Send_to_socketio(object):
|
||||||
def write(self, bar):
|
def write(self, bar):
|
||||||
bar = bar.replace("\r", "")
|
bar = bar.replace("\r", "").replace("\n", "")
|
||||||
try:
|
if bar != "":
|
||||||
emit('from_server', {'cmd': 'model_load_status', 'data': bar.replace(" ", " ")}, broadcast=True, room="UI_1")
|
try:
|
||||||
eventlet.sleep(seconds=0)
|
print(bar, end="\r")
|
||||||
except:
|
emit('from_server', {'cmd': 'model_load_status', 'data': bar.replace(" ", " ")}, broadcast=True, room="UI_1")
|
||||||
pass
|
eventlet.sleep(seconds=0)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
def http_get(
|
def http_get(
|
||||||
url: str,
|
url: str,
|
||||||
temp_file: transformers.utils.hub.BinaryIO,
|
temp_file: transformers.utils.hub.BinaryIO,
|
||||||
@@ -6336,6 +6338,77 @@ def UI_2_load_story(file):
|
|||||||
print("loading {}".format(file))
|
print("loading {}".format(file))
|
||||||
loadRequest(file)
|
loadRequest(file)
|
||||||
|
|
||||||
|
#==================================================================#
|
||||||
|
# Event triggered when user deletes world info tag
|
||||||
|
#==================================================================#
|
||||||
|
@socketio.on('delete_wi_tag')
|
||||||
|
def UI_2_delete_wi_tag(data):
|
||||||
|
keys = koboldai_vars.worldinfo_v2[int(data['wiid'])]['key']
|
||||||
|
keys = [x for x in keys if x != data['key']]
|
||||||
|
koboldai_vars.worldinfo_v2[int(data['wiid'])]['key'] = keys
|
||||||
|
|
||||||
|
#==================================================================#
|
||||||
|
# Event triggered when user updates world info tag
|
||||||
|
#==================================================================#
|
||||||
|
@socketio.on('change_wi_tag')
|
||||||
|
def UI_2_change_wi_tag(data):
|
||||||
|
print("update: {}".format(data))
|
||||||
|
keys = koboldai_vars.worldinfo_v2[int(data['wiid'])]['key']
|
||||||
|
keys = [x if x != data['key'] else data['new_tag'] for x in keys]
|
||||||
|
koboldai_vars.worldinfo_v2[int(data['wiid'])]['key'] = keys
|
||||||
|
|
||||||
|
#==================================================================#
|
||||||
|
# Event triggered when user adds world info tag
|
||||||
|
#==================================================================#
|
||||||
|
@socketio.on('new_wi_tag')
|
||||||
|
def UI_2_new_wi_tag(data):
|
||||||
|
print("Add: {}".format(data))
|
||||||
|
keys = koboldai_vars.worldinfo_v2[int(data['wiid'])]['key']
|
||||||
|
keys.append(data['key'])
|
||||||
|
koboldai_vars.worldinfo_v2[int(data['wiid'])]['key'] = keys
|
||||||
|
|
||||||
|
#==================================================================#
|
||||||
|
# Event triggered when user deletes world info secondary tag
|
||||||
|
#==================================================================#
|
||||||
|
@socketio.on('delete_wi_secondary_tag')
|
||||||
|
def UI_2_delete_wi_secondary_tag(data):
|
||||||
|
keys = koboldai_vars.worldinfo_v2[int(data['wiid'])]['keysecondary']
|
||||||
|
keys = [x for x in keys if x != data['key']]
|
||||||
|
koboldai_vars.worldinfo_v2[int(data['wiid'])]['keysecondary'] = keys
|
||||||
|
|
||||||
|
#==================================================================#
|
||||||
|
# Event triggered when user updates world info secondary tag
|
||||||
|
#==================================================================#
|
||||||
|
@socketio.on('change_wi_secondary_tag')
|
||||||
|
def UI_2_change_wi_secondary_tag(data):
|
||||||
|
keys = koboldai_vars.worldinfo_v2[int(data['wiid'])]['keysecondary']
|
||||||
|
keys = [x if x != data['key'] else data['new_tag'] for x in keys]
|
||||||
|
koboldai_vars.worldinfo_v2[int(data['wiid'])]['keysecondary'] = keys
|
||||||
|
|
||||||
|
#==================================================================#
|
||||||
|
# Event triggered when user adds world info tag
|
||||||
|
#==================================================================#
|
||||||
|
@socketio.on('new_wi_secondary_tag')
|
||||||
|
def UI_2_new_wi_secondary_tag(data):
|
||||||
|
keys = koboldai_vars.worldinfo_v2[int(data['wiid'])]['keysecondary']
|
||||||
|
keys.append(data['key'])
|
||||||
|
koboldai_vars.worldinfo_v2[int(data['wiid'])]['keysecondary'] = keys
|
||||||
|
|
||||||
|
#==================================================================#
|
||||||
|
# Event triggered when user adds world info text
|
||||||
|
#==================================================================#
|
||||||
|
@socketio.on('change_wi_text')
|
||||||
|
def UI_2_change_wi_text(data):
|
||||||
|
koboldai_vars.worldinfo_v2[int(data['wiid'])]['content'] = data['text']
|
||||||
|
|
||||||
|
#==================================================================#
|
||||||
|
# Event triggered when user moves world info
|
||||||
|
#==================================================================#
|
||||||
|
@socketio.on('move_wi')
|
||||||
|
def UI_2_move_wi(data):
|
||||||
|
print(data)
|
||||||
|
koboldai_vars.worldinfo_v2.reorder(int(data['dragged_id']), int(data['drop_id']))
|
||||||
|
|
||||||
|
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
# Event triggered to rely a message
|
# Event triggered to rely a message
|
||||||
|
@@ -25,7 +25,6 @@ def process_variable_changes(socketio, classname, name, value, old_value, debug_
|
|||||||
if value != old_value:
|
if value != old_value:
|
||||||
#Special Case for KoboldStoryRegister
|
#Special Case for KoboldStoryRegister
|
||||||
if isinstance(value, KoboldStoryRegister):
|
if isinstance(value, KoboldStoryRegister):
|
||||||
print("sending story register")
|
|
||||||
socketio.emit("reset_story", {}, broadcast=True, room="UI_2")
|
socketio.emit("reset_story", {}, broadcast=True, room="UI_2")
|
||||||
socketio.emit("var_changed", {"classname": "actions", "name": "Action Count", "old_value": None, "value":value.action_count}, broadcast=True, room="UI_2")
|
socketio.emit("var_changed", {"classname": "actions", "name": "Action Count", "old_value": None, "value":value.action_count}, broadcast=True, room="UI_2")
|
||||||
for i in range(len(value.actions)):
|
for i in range(len(value.actions)):
|
||||||
@@ -35,8 +34,7 @@ def process_variable_changes(socketio, classname, name, value, old_value, debug_
|
|||||||
elif isinstance(value, KoboldWorldInfo):
|
elif isinstance(value, KoboldWorldInfo):
|
||||||
data = value.to_json()
|
data = value.to_json()
|
||||||
for uid in data:
|
for uid in data:
|
||||||
for key in data[uid]:
|
process_variable_changes(socketio, "world_info", uid, data[uid], None)
|
||||||
socketio.emit("var_changed", {"classname":"world_info", "name": "{}_{}".format(key, uid), "value": data[uid][key], "old_value": None}, broadcast=True, room="UI_2")
|
|
||||||
else:
|
else:
|
||||||
#If we got a variable change from a thread other than what the app is run it, eventlet seems to block and no further messages are sent. Instead, we'll rely the message to the app and have the main thread send it
|
#If we got a variable change from a thread other than what the app is run it, eventlet seems to block and no further messages are sent. Instead, we'll rely the message to the app and have the main thread send it
|
||||||
if not has_request_context():
|
if not has_request_context():
|
||||||
@@ -329,7 +327,7 @@ class story_settings(settings):
|
|||||||
self.chatmode = False
|
self.chatmode = False
|
||||||
self.chatname = "You"
|
self.chatname = "You"
|
||||||
self.adventure = False
|
self.adventure = False
|
||||||
self.actionmode = 1
|
self.actionmode = 0
|
||||||
self.dynamicscan = False
|
self.dynamicscan = False
|
||||||
self.recentedit = False
|
self.recentedit = False
|
||||||
self.tokenizer = tokenizer
|
self.tokenizer = tokenizer
|
||||||
@@ -824,11 +822,14 @@ class KoboldStoryRegister(object):
|
|||||||
|
|
||||||
class KoboldWorldInfoEntry(object):
|
class KoboldWorldInfoEntry(object):
|
||||||
#if we call info with a [x] get the world info data for x
|
#if we call info with a [x] get the world info data for x
|
||||||
|
local_only_variables = ['selective', 'num']
|
||||||
|
_required_variables = ['uid', 'sort', 'key', 'keysecondary', 'folder', 'content', 'constant']
|
||||||
def __init__(self, socketio, uid, actions):
|
def __init__(self, socketio, uid, actions):
|
||||||
self._socketio = socketio
|
self._socketio = socketio
|
||||||
self.uid = uid
|
self.uid = uid
|
||||||
self.folder = "root"
|
self.folder = "root"
|
||||||
self._actions = actions
|
self._actions = actions
|
||||||
|
|
||||||
|
|
||||||
def __getitem__(self, i):
|
def __getitem__(self, i):
|
||||||
return getattr(self, i)
|
return getattr(self, i)
|
||||||
@@ -847,14 +848,27 @@ class KoboldWorldInfoEntry(object):
|
|||||||
setattr(self, i, data)
|
setattr(self, i, data)
|
||||||
|
|
||||||
def __setattr__(self, name, value):
|
def __setattr__(self, name, value):
|
||||||
if (name == 'key' or name == 'keysecondary') and isinstance(value, str):
|
|
||||||
value = [x.strip() for x in value.split(",")]
|
|
||||||
new_variable = name not in self.__dict__
|
new_variable = name not in self.__dict__
|
||||||
old_value = getattr(self, name, None)
|
if isinstance(value, list):
|
||||||
|
old_value = None
|
||||||
|
else:
|
||||||
|
old_value = getattr(self, name, None)
|
||||||
|
#if we set secondary keys we set selective
|
||||||
|
if name == 'keysecondary':
|
||||||
|
if value == "" or value == [] or value == [""] or value is None:
|
||||||
|
self.selective = False
|
||||||
|
else:
|
||||||
|
self.selective = True
|
||||||
super().__setattr__(name, value)
|
super().__setattr__(name, value)
|
||||||
#Put variable change actions here
|
#Put variable change actions here
|
||||||
if name[0] != "_":
|
if name[0] != "_" and name not in self.local_only_variables:
|
||||||
process_variable_changes(self._socketio, "world_info", "{}_{}".format(name, self.uid), value, old_value)
|
send = True
|
||||||
|
for var in self._required_variables:
|
||||||
|
if var not in self.__dict__:
|
||||||
|
send = False
|
||||||
|
break
|
||||||
|
if send:
|
||||||
|
process_variable_changes(self._socketio, "world_info", self.uid, self.to_dict(), None)
|
||||||
|
|
||||||
class KoboldWorldInfo(object):
|
class KoboldWorldInfo(object):
|
||||||
|
|
||||||
@@ -869,11 +883,10 @@ class KoboldWorldInfo(object):
|
|||||||
|
|
||||||
#if we call info with a [x] get the world info data for x as a dictionary
|
#if we call info with a [x] get the world info data for x as a dictionary
|
||||||
def __getitem__(self, i):
|
def __getitem__(self, i):
|
||||||
return self.world_info[i].to_dict()
|
return self.world_info[i]
|
||||||
|
|
||||||
#allow for setting the entire world info to a dictionary of values
|
#allow for setting the entire world info to a dictionary of values
|
||||||
def __setitem__(self, i, data):
|
def __setitem__(self, i, data):
|
||||||
print("setting {} to {}".format(i, data))
|
|
||||||
if i not in self.world_info:
|
if i not in self.world_info:
|
||||||
i = self.append(data)
|
i = self.append(data)
|
||||||
for key in data:
|
for key in data:
|
||||||
@@ -905,23 +918,23 @@ class KoboldWorldInfo(object):
|
|||||||
items = [item.to_dict() for item in self.world_info if item['folder'] == folder]
|
items = [item.to_dict() for item in self.world_info if item['folder'] == folder]
|
||||||
return sorted(items, key=lambda d: d['sort_order'])
|
return sorted(items, key=lambda d: d['sort_order'])
|
||||||
|
|
||||||
def reorder(self, uid, after_uid):
|
def reorder(self, uid, before_uid):
|
||||||
if uid not in self.world_info or after_uid not in self.world_info:
|
if uid not in self.world_info or before_uid not in self.world_info:
|
||||||
return
|
return
|
||||||
folder = self.world_info[uid]['folder']
|
folder = self.world_info[uid]['folder']
|
||||||
after_sort_number = self.world_info[after_uid]['sort']
|
before_sort_number = self.world_info[before_uid]['sort']
|
||||||
for item in world_info:
|
for key, item in self.world_info.items():
|
||||||
if item['folder'] == folder and item['sort'] > after_sort_number:
|
if item['folder'] == folder and item['sort'] >= before_sort_number:
|
||||||
item['sort'] = item['sort']+1
|
item['sort'] = item['sort']+1
|
||||||
self.world_info[uid]['sort'] = after_sort_number+1
|
self.world_info[uid]['sort'] = before_sort_number
|
||||||
|
|
||||||
def set_folder(self, uid, folder, after_uid=None):
|
def set_folder(self, uid, folder, before_uid=None):
|
||||||
max_sort = max([x['sort'] for x in self.world_info if x['folder'] == folder])
|
max_sort = max([x['sort'] for x in self.world_info if x['folder'] == folder])
|
||||||
old_folder = self.world_info[uid]['folder']
|
old_folder = self.world_info[uid]['folder']
|
||||||
self.world_info[uid]['folder'] = folder
|
self.world_info[uid]['folder'] = folder
|
||||||
self.world_info[uid]['sort'] = max_sort
|
self.world_info[uid]['sort'] = max_sort
|
||||||
if after_uid is not None:
|
if before_uid is not None:
|
||||||
self.reorder(folder, uid, after_uid)
|
self.reorder(folder, uid, before_uid)
|
||||||
self.resort(folder)
|
self.resort(folder)
|
||||||
self.resort(old_folder)
|
self.resort(old_folder)
|
||||||
|
|
||||||
@@ -940,6 +953,11 @@ class KoboldWorldInfo(object):
|
|||||||
self.world_info[uid] = KoboldWorldInfoEntry(self._socketio, uid, self._actions)
|
self.world_info[uid] = KoboldWorldInfoEntry(self._socketio, uid, self._actions)
|
||||||
if 'folder' not in data:
|
if 'folder' not in data:
|
||||||
data['folder'] = "root"
|
data['folder'] = "root"
|
||||||
|
if data['key'] == "":
|
||||||
|
data['key'] = []
|
||||||
|
if 'keysecondary' in data:
|
||||||
|
if data['keysecondary'] == "":
|
||||||
|
data['keysecondary'] = []
|
||||||
data['sort'] = max([self.world_info[x]['sort'] for x in self.world_info if self.world_info[x]['folder'] == data['folder']]+[-1])+1
|
data['sort'] = max([self.world_info[x]['sort'] for x in self.world_info if self.world_info[x]['folder'] == data['folder']]+[-1])+1
|
||||||
for key in data:
|
for key in data:
|
||||||
if (key == 'key' or key == 'keysecondary') and isinstance(data[key], str):
|
if (key == 'key' or key == 'keysecondary') and isinstance(data[key], str):
|
||||||
|
@@ -33,6 +33,10 @@
|
|||||||
--disabled_button_border_color: #686c68;
|
--disabled_button_border_color: #686c68;
|
||||||
--menu_button_level_1_bg_color: #337ab7;
|
--menu_button_level_1_bg_color: #337ab7;
|
||||||
--menu_button_level_2_bg_color: #285070;
|
--menu_button_level_2_bg_color: #285070;
|
||||||
|
--wi_card_border_color: white;
|
||||||
|
--wi_card_bg_color: #262626;
|
||||||
|
--wi_card_tag_bg_color: #404040;
|
||||||
|
--wi_tag_color: #337ab7;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,6 +217,7 @@
|
|||||||
background: var(--setting_text);
|
background: var(--setting_text);
|
||||||
border: 1px solid white;
|
border: 1px solid white;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
|
cursor: help;
|
||||||
}
|
}
|
||||||
|
|
||||||
.helpicon .helptext {
|
.helpicon .helptext {
|
||||||
@@ -388,6 +393,35 @@ td.server_vars {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.WI_Folder {
|
||||||
|
/*color: black;*/
|
||||||
|
}
|
||||||
|
|
||||||
|
.WI_Folder table {
|
||||||
|
margin: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.world_info_card {
|
||||||
|
width: 100%;
|
||||||
|
border: 2px outset var(--wi_card_border_color);
|
||||||
|
background-color: var(--wi_card_bg_color)
|
||||||
|
}
|
||||||
|
|
||||||
|
.world_info_tag_area {
|
||||||
|
border: 2px inset var(--wi_card_border_color);
|
||||||
|
background-color: var(--wi_card_tag_bg_color);
|
||||||
|
padding-bottom : 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tag {
|
||||||
|
background-color: var(--wi_tag_color);
|
||||||
|
border: solid;
|
||||||
|
border-color: var(--wi_card_tag_bg_color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tag .delete_icon {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ---------------------------- OVERALL PAGE CONFIG ------------------------------*/
|
/* ---------------------------- OVERALL PAGE CONFIG ------------------------------*/
|
||||||
@@ -900,4 +934,8 @@ button.disabled {
|
|||||||
transform: scale(0.95);
|
transform: scale(0.95);
|
||||||
box-shadow: 0 0 0 0 rgba(255, 255, 255, 0);
|
box-shadow: 0 0 0 0 rgba(255, 255, 255, 0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.drag-over {
|
||||||
|
border-top: dashed 3px red;
|
||||||
}
|
}
|
@@ -192,6 +192,7 @@ function do_story_text_updates(data) {
|
|||||||
item.original_text = data.value.text;
|
item.original_text = data.value.text;
|
||||||
item.classList.remove("pulse")
|
item.classList.remove("pulse")
|
||||||
item.scrollIntoView();
|
item.scrollIntoView();
|
||||||
|
assign_world_info_to_action(action_item = item);
|
||||||
} else {
|
} else {
|
||||||
var span = document.createElement("span");
|
var span = document.createElement("span");
|
||||||
span.id = 'Selected Text Chunk '+data.value.id;
|
span.id = 'Selected Text Chunk '+data.value.id;
|
||||||
@@ -224,8 +225,10 @@ function do_story_text_updates(data) {
|
|||||||
|
|
||||||
story_area.append(span);
|
story_area.append(span);
|
||||||
span.scrollIntoView();
|
span.scrollIntoView();
|
||||||
|
assign_world_info_to_action(action_item = span);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function do_prompt(data) {
|
function do_prompt(data) {
|
||||||
@@ -987,52 +990,189 @@ function buildload(data) {
|
|||||||
|
|
||||||
function world_info(data) {
|
function world_info(data) {
|
||||||
var world_info_area = document.getElementById("story_menu_wi");
|
var world_info_area = document.getElementById("story_menu_wi");
|
||||||
var wiid = data.name.split("_")[data.name.split("_").length-1];
|
var wiid = data.value.uid;
|
||||||
var name = data.name.split("_").slice(0, data.name.split("_").length-1).join('_');
|
var folder = data.value.folder;
|
||||||
|
|
||||||
//first check to see if we have the world info id already
|
//first check to see if we have the world info id already
|
||||||
if (document.getElementById("world_info_"+wiid)) {
|
if (!(document.getElementById("world_info_"+wiid))) {
|
||||||
table = document.getElementById("world_info_"+wiid);
|
world_info_card = create_wi_card(wiid);
|
||||||
if (document.getElementById("world_info_"+wiid+"_"+name)) {
|
} else {
|
||||||
tr = document.getElementById("world_info_"+wiid+"_"+name);
|
world_info_card = document.getElementById("world_info_"+wiid);
|
||||||
tr.lastChild.textContent = data.value
|
}
|
||||||
} else {
|
|
||||||
tr = document.createElement("tr")
|
//create folder if needed
|
||||||
tr.id = "world_info_"+wiid+"_"+name
|
if (folder == null) {
|
||||||
td = document.createElement("td")
|
folder = 'root';
|
||||||
td.textContent = name;
|
}
|
||||||
tr.append(td);
|
if (!(document.getElementById("world_info_folder_"+folder))) {
|
||||||
td = document.createElement("td")
|
var folder_item = document.createElement("span");
|
||||||
td.textContent = data.value;
|
folder_item.id = "world_info_folder_"+folder;
|
||||||
tr.append(td);
|
folder_item.classList.add("WI_Folder");
|
||||||
table.append(tr);
|
title = document.createElement("h2");
|
||||||
|
title.textContent = folder;
|
||||||
|
folder_item.append(title);
|
||||||
|
world_info_area.append(folder_item);
|
||||||
|
} else {
|
||||||
|
folder_item = document.getElementById("world_info_folder_"+folder);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//we'll need to move the item to the appropriate section (folder and location in folder)
|
||||||
|
cards = folder_item.children
|
||||||
|
for (var i = 0; i < cards.length; i++) {
|
||||||
|
if ((cards[i].tagName == 'DIV') & (cards[i].getAttribute("wi_sort") > data.value.sort)) {
|
||||||
|
//check to see if we've exceeded our sort #
|
||||||
|
folder_item.insertBefore(world_info_card, cards[i]);
|
||||||
|
break;
|
||||||
|
} else if (cards.length-1 == i) {
|
||||||
|
folder_item.append(world_info_card);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
//First we need to add a folder if that doesn't exist
|
|
||||||
table = document.createElement("table");
|
|
||||||
table.border = 1
|
|
||||||
table.id = "world_info_"+wiid;
|
|
||||||
tr = document.createElement("tr")
|
|
||||||
tr.id = "world_info_"+wiid+"_"+name
|
|
||||||
td = document.createElement("td")
|
|
||||||
td.textContent = name;
|
|
||||||
tr.append(td);
|
|
||||||
td = document.createElement("td")
|
|
||||||
td.textContent = data.value;
|
|
||||||
tr.append(td);
|
|
||||||
table.append(tr);
|
|
||||||
|
|
||||||
|
|
||||||
world_info_area.append(table);
|
|
||||||
}
|
}
|
||||||
if (wiid in world_info_data) {
|
|
||||||
world_info_data[wiid][name] = data.value;
|
//set sort
|
||||||
} else {
|
world_info_card.setAttribute("wi_sort", data.value.sort);
|
||||||
world_info_data[wiid] = {name: data.value};
|
|
||||||
|
//set title
|
||||||
|
title = document.getElementById("world_info_title_"+wiid);
|
||||||
|
if ('title' in data.value) {
|
||||||
|
title.textContent = data.value.title;
|
||||||
|
} else if ((data.value.comment != "") & (data.value.comment != null)) {
|
||||||
|
title.textContent = data.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//set content
|
||||||
|
entry_text = document.getElementById("world_info_entry_text_"+wiid);
|
||||||
|
entry_text.value = data.value.content;
|
||||||
|
entry_text.setAttribute("wiid", wiid);
|
||||||
|
entry_text.classList.remove("pulse");
|
||||||
|
|
||||||
|
//setup keys
|
||||||
|
//use the first key as the title if there isn't one
|
||||||
|
title = document.getElementById("world_info_title_"+wiid);
|
||||||
|
if (title.textContent == "") {
|
||||||
|
title.textContent = data.value.key[0];
|
||||||
|
}
|
||||||
|
tags = document.getElementById("world_info_tags_"+wiid);
|
||||||
|
while (tags.firstChild) {
|
||||||
|
tags.removeChild(tags.firstChild);
|
||||||
|
}
|
||||||
|
tags_title = document.createElement("div");
|
||||||
|
tags_title.textContent = "Primary Keys:";
|
||||||
|
tags.append(tags_title);
|
||||||
|
for (tag of data.value.key) {
|
||||||
|
if (!(document.getElementById("world_info_tags_"+wiid+"_"+tag))) {
|
||||||
|
tag_item = document.createElement("span");
|
||||||
|
tag_item.classList.add("tag");
|
||||||
|
x = document.createElement("span");
|
||||||
|
x.textContent = "x ";
|
||||||
|
x.classList.add("delete_icon");
|
||||||
|
x.setAttribute("wii", wiid);
|
||||||
|
x.setAttribute("tag", tag);
|
||||||
|
x.onclick = function () {
|
||||||
|
socket.emit('delete_wi_tag', {'wiid': this.getAttribute('wii'), 'key': this.getAttribute('tag')});
|
||||||
|
};
|
||||||
|
text = document.createElement("span");
|
||||||
|
text.textContent = tag;
|
||||||
|
text.setAttribute("contenteditable", true);
|
||||||
|
text.setAttribute("wii", wiid);
|
||||||
|
text.setAttribute("tag", tag);
|
||||||
|
text.onblur = function () {
|
||||||
|
socket.emit('change_wi_tag', {'wiid': this.getAttribute('wii'), 'key': this.getAttribute('tag'), 'new_tag': this.textContent});
|
||||||
|
this.classList.add("pulse");
|
||||||
|
};
|
||||||
|
tag_item.append(x);
|
||||||
|
tag_item.append(text);
|
||||||
|
tag_item.id = "world_info_tags_"+wiid+"_"+tag;
|
||||||
|
tags.append(tag_item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//add the blank tag
|
||||||
|
tag_item = document.createElement("span");
|
||||||
|
tag_item.classList.add("tag");
|
||||||
|
x = document.createElement("span");
|
||||||
|
x.textContent = "+ ";
|
||||||
|
tag_item.append(x);
|
||||||
|
text = document.createElement("span");
|
||||||
|
text.classList.add("rawtext");
|
||||||
|
text.textContent = " ";
|
||||||
|
text.setAttribute("wii", wiid);
|
||||||
|
text.setAttribute("contenteditable", true);
|
||||||
|
text.onblur = function () {
|
||||||
|
socket.emit('new_wi_tag', {'wiid': this.getAttribute('wii'), 'key': this.textContent});
|
||||||
|
this.parentElement.remove();
|
||||||
|
};
|
||||||
|
text.onclick = function () {
|
||||||
|
this.textContent = "";
|
||||||
|
};
|
||||||
|
tag_item.append(text);
|
||||||
|
tag_item.id = "world_info_secondtags_"+wiid+"_new";
|
||||||
|
tags.append(tag_item);
|
||||||
|
|
||||||
|
|
||||||
|
//secondary key
|
||||||
|
tags = document.getElementById("world_info_secondtags_"+wiid);
|
||||||
|
while (tags.firstChild) {
|
||||||
|
tags.removeChild(tags.firstChild);
|
||||||
|
}
|
||||||
|
tags_title = document.createElement("div");
|
||||||
|
tags_title.textContent = "Secondary Keys:";
|
||||||
|
tags.append(tags_title);
|
||||||
|
for (tag of data.value.keysecondary) {
|
||||||
|
if (!(document.getElementById("world_info_secondtags_"+wiid+"_"+tag))) {
|
||||||
|
tag_item = document.createElement("span");
|
||||||
|
tag_item.classList.add("tag");
|
||||||
|
x = document.createElement("span");
|
||||||
|
x.textContent = "x ";
|
||||||
|
x.classList.add("delete_icon");
|
||||||
|
x.setAttribute("wii", wiid);
|
||||||
|
x.setAttribute("tag", tag);
|
||||||
|
x.onclick = function () {
|
||||||
|
socket.emit('delete_wi_secondary_tag', {'wiid': this.getAttribute('wii'), 'key': this.getAttribute('tag')});
|
||||||
|
};
|
||||||
|
text = document.createElement("span");
|
||||||
|
text.textContent = tag;
|
||||||
|
text.setAttribute("contenteditable", true);
|
||||||
|
text.setAttribute("wii", wiid);
|
||||||
|
text.setAttribute("tag", tag);
|
||||||
|
text.onblur = function () {
|
||||||
|
socket.emit('change_wi_secondary_tag', {'wiid': this.getAttribute('wii'), 'key': this.getAttribute('tag'), 'new_tag': this.textContent});
|
||||||
|
this.classList.add("pulse");
|
||||||
|
};
|
||||||
|
tag_item.append(x);
|
||||||
|
tag_item.append(text);
|
||||||
|
tag_item.id = "world_info_secondtags_"+wiid+"_"+tag;
|
||||||
|
tags.append(tag_item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//add the blank tag
|
||||||
|
tag_item = document.createElement("span");
|
||||||
|
tag_item.classList.add("tag");
|
||||||
|
x = document.createElement("span");
|
||||||
|
x.textContent = "+ ";
|
||||||
|
tag_item.append(x);
|
||||||
|
text = document.createElement("span");
|
||||||
|
text.classList.add("rawtext");
|
||||||
|
text.textContent = " ";
|
||||||
|
text.setAttribute("wii", wiid);
|
||||||
|
text.setAttribute("contenteditable", true);
|
||||||
|
text.onblur = function () {
|
||||||
|
socket.emit('new_wi_secondary_tag', {'wiid': this.getAttribute('wii'), 'key': this.textContent});
|
||||||
|
this.parentElement.remove();
|
||||||
|
};
|
||||||
|
text.onclick = function () {
|
||||||
|
this.textContent = "";
|
||||||
|
};
|
||||||
|
tag_item.append(text);
|
||||||
|
tag_item.id = "world_info_secondtags_"+wiid+"_new";
|
||||||
|
tags.append(tag_item);
|
||||||
|
|
||||||
|
//save the world info data into an object in javascript so we can reference it later
|
||||||
|
world_info_data[wiid] = data.value;
|
||||||
|
|
||||||
//Now let's see if we can find this key in the body of text
|
//Now let's see if we can find this key in the body of text
|
||||||
if (['key', 'selective', 'keysecondary'].includes(name)) {
|
assign_world_info_to_action(wiid=wiid);
|
||||||
assign_world_info_to_action(wiid=wiid);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------UI to Server Functions----------------------------------
|
//--------------------------------------------UI to Server Functions----------------------------------
|
||||||
@@ -1084,7 +1224,121 @@ function upload_file(file_box) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------General UI Functions------------------------------------
|
//--------------------------------------------General UI Functions------------------------------------
|
||||||
function assign_world_info_to_action(wiid=null) {
|
function create_wi_card(wiid) {
|
||||||
|
world_info_card = document.createElement("div");
|
||||||
|
world_info_card.setAttribute("draggable", true);
|
||||||
|
world_info_card.addEventListener('dragstart', dragStart);
|
||||||
|
world_info_card.addEventListener('dragenter', dragEnter)
|
||||||
|
world_info_card.addEventListener('dragover', dragOver);
|
||||||
|
world_info_card.addEventListener('dragleave', dragLeave);
|
||||||
|
world_info_card.addEventListener('drop', drop);
|
||||||
|
world_info_card.addEventListener('dragend', dragend);
|
||||||
|
world_info_card.classList.add("world_info_card");
|
||||||
|
world_info_card.id = "world_info_"+wiid;
|
||||||
|
world_info_card.setAttribute("wi_sort", -1);
|
||||||
|
world_info_card.setAttribute("wi_folder", "root");
|
||||||
|
//create title
|
||||||
|
title = document.createElement("h4");
|
||||||
|
title.id = "world_info_title_"+wiid;
|
||||||
|
world_info_card.append(title)
|
||||||
|
//create primary tags
|
||||||
|
world_info_tags = document.createElement("div");
|
||||||
|
world_info_tags.id = "world_info_tags_"+wiid;
|
||||||
|
world_info_tags.classList.add("world_info_tag_area");
|
||||||
|
tags_title = document.createElement("div");
|
||||||
|
tags_title.textContent = "Primary Keys:";
|
||||||
|
world_info_tags.append(tags_title);
|
||||||
|
world_info_card.append(world_info_tags);
|
||||||
|
//create secondary tags
|
||||||
|
world_info_tags = document.createElement("div");
|
||||||
|
world_info_tags.id = "world_info_secondtags_"+wiid;
|
||||||
|
world_info_tags.classList.add("world_info_tag_area");
|
||||||
|
tags_title = document.createElement("div");
|
||||||
|
tags_title.textContent = "Secondary Keys:";
|
||||||
|
world_info_tags.append(tags_title);
|
||||||
|
world_info_card.append(world_info_tags);
|
||||||
|
//create entry text
|
||||||
|
entry_text = document.createElement("textarea");
|
||||||
|
entry_text.id = "world_info_entry_text_"+wiid;
|
||||||
|
entry_text.classList.add("world_info_text");
|
||||||
|
entry_text.classList.add('fullwidth');
|
||||||
|
entry_text.onchange = function() {
|
||||||
|
socket.emit("change_wi_text", {"wiid": this.getAttribute("wiid"), 'text': this.value});
|
||||||
|
this.classList.add("pulse");
|
||||||
|
}
|
||||||
|
world_info_card.append(entry_text);
|
||||||
|
|
||||||
|
return world_info_card;
|
||||||
|
}
|
||||||
|
|
||||||
|
function dragStart(e) {
|
||||||
|
e.dataTransfer.setData('text/plain', e.target.id);
|
||||||
|
e.dataTransfer.dropEffect = "move";
|
||||||
|
setTimeout(() => {
|
||||||
|
e.target.classList.add('hidden');
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function find_wi_container(e) {
|
||||||
|
while (true) {
|
||||||
|
if (e.parentElement == document) {
|
||||||
|
return e;
|
||||||
|
} else if (typeof e.id == 'undefined') {
|
||||||
|
e = e.parentElement;
|
||||||
|
} else if (e.id.replace(/[^a-z_]/gi, '') == 'world_info_') {
|
||||||
|
return e
|
||||||
|
} else {
|
||||||
|
e = e.parentElement;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function dragEnter(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
element = find_wi_container(e.target);
|
||||||
|
element.classList.add('drag-over');
|
||||||
|
}
|
||||||
|
|
||||||
|
function dragOver(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
element = find_wi_container(e.target);
|
||||||
|
element.classList.add('drag-over');
|
||||||
|
}
|
||||||
|
|
||||||
|
function dragLeave(e) {
|
||||||
|
element = find_wi_container(e.target);
|
||||||
|
element.classList.remove('drag-over');
|
||||||
|
}
|
||||||
|
|
||||||
|
function drop(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
element = find_wi_container(e.target);
|
||||||
|
element.classList.remove('drag-over');
|
||||||
|
|
||||||
|
// get the draggable element
|
||||||
|
const id = e.dataTransfer.getData('text/plain');
|
||||||
|
const draggable = document.getElementById(id);
|
||||||
|
|
||||||
|
// add it before the drop target
|
||||||
|
element = find_wi_container(e.target);
|
||||||
|
element.parentElement.insertBefore(draggable, element);
|
||||||
|
|
||||||
|
// display the draggable element
|
||||||
|
draggable.classList.remove('hidden');
|
||||||
|
|
||||||
|
//send the new order to the backend
|
||||||
|
dragged_id = draggable.id.split("_").slice(-1)[0];
|
||||||
|
drop_id = element.id.split("_").slice(-1)[0];
|
||||||
|
socket.emit("move_wi", {'dragged_id': dragged_id, 'drop_id': drop_id});
|
||||||
|
}
|
||||||
|
|
||||||
|
function dragend(e) {
|
||||||
|
element = find_wi_container(e.target);
|
||||||
|
element.classList.remove('hidden');
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
function assign_world_info_to_action(wiid=null, action_item=null) {
|
||||||
//console.log(world_info_data);
|
//console.log(world_info_data);
|
||||||
if (wiid != null) {
|
if (wiid != null) {
|
||||||
var worldinfo_to_check = {};
|
var worldinfo_to_check = {};
|
||||||
@@ -1092,59 +1346,68 @@ function assign_world_info_to_action(wiid=null) {
|
|||||||
} else {
|
} else {
|
||||||
var worldinfo_to_check = world_info_data;
|
var worldinfo_to_check = world_info_data;
|
||||||
}
|
}
|
||||||
for (action of document.getElementById("Selected Text").children) {
|
if (action_item != null) {
|
||||||
|
var actions = [action_item]
|
||||||
|
} else {
|
||||||
|
var actions = document.getElementById("Selected Text").children;
|
||||||
|
}
|
||||||
|
for (action of actions) {
|
||||||
//First check to see if we have a key in the text
|
//First check to see if we have a key in the text
|
||||||
var found = false;
|
|
||||||
var words = Array.prototype.slice.call( action.children );
|
var words = Array.prototype.slice.call( action.children );
|
||||||
words_text = [];
|
words_text = [];
|
||||||
for (word of words) {
|
for (word of words) {
|
||||||
words_text.push(word.textContent);
|
words_text.push(word.textContent);
|
||||||
}
|
}
|
||||||
for (const [key, worldinfo] of Object.entries(worldinfo_to_check)) {
|
for (const [key, worldinfo] of Object.entries(worldinfo_to_check)) {
|
||||||
if ('key' in worldinfo) {
|
//remove any world info tags
|
||||||
|
for (tag of action.getElementsByClassName("tag_wiid_"+wiid)) {
|
||||||
|
tag.classList.remove("tag_wiid_"+wiid);
|
||||||
|
tag.removeAttribute("title");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (('key' in worldinfo) & ('keysecondary' in worldinfo) & ('content' in worldinfo)) {
|
||||||
for (keyword of worldinfo['key']) {
|
for (keyword of worldinfo['key']) {
|
||||||
// if (keyword == 'Chernobyl Exclusion Zone') {
|
|
||||||
// console.log("checking " + keyword +" in " + action.textContent.replace(/[^0-9a-z \'\"]/gi, ''));
|
|
||||||
// console.log(action.textContent.replace(/[^0-9a-z \'\"]/gi, '').includes(keyword));
|
|
||||||
// }
|
|
||||||
if ((action.textContent.replace(/[^0-9a-z \'\"]/gi, '')).includes(keyword)) {
|
if ((action.textContent.replace(/[^0-9a-z \'\"]/gi, '')).includes(keyword)) {
|
||||||
found = true;
|
//Ok we have a key match, but we need to check for secondary keys if applicable
|
||||||
//OK we have the phrase in our action. Let's see if we can identify the word(s) that are triggering
|
if (worldinfo['keysecondary'].length > 0) {
|
||||||
for (var i = 0; i < words.length; i++) {
|
if ('keysecondary' in worldinfo) {
|
||||||
key_words = keyword.split(" ").length;
|
for (second_key of worldinfo['keysecondary']) {
|
||||||
var to_check = words_text.slice(i, i+key_words).join("").replace(/[^0-9a-z \'\"]/gi, '').trim();
|
if (action.textContent.replace(/[^0-9a-z \'\"]/gi, '').includes(second_key)) {
|
||||||
if (keyword == to_check) {
|
//OK we have the phrase in our action. Let's see if we can identify the word(s) that are triggering
|
||||||
console.log("found "+keyword);
|
for (var i = 0; i < words.length; i++) {
|
||||||
for (var j = i; j < key_words+i; j++) {
|
key_words = keyword.split(" ").length;
|
||||||
words[j].title = worldinfo['content'];
|
var to_check = words_text.slice(i, i+key_words).join("").replace(/[^0-9a-z \'\"]/gi, '').trim();
|
||||||
|
if (keyword == to_check) {
|
||||||
|
for (var j = i; j < key_words+i; j++) {
|
||||||
|
words[j].title = worldinfo['content'];
|
||||||
|
words[j].classList.add("tag_wiid_"+wiid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//OK we have the phrase in our action. Let's see if we can identify the word(s) that are triggering
|
||||||
|
for (var i = 0; i < words.length; i++) {
|
||||||
|
key_words = keyword.split(" ").length;
|
||||||
|
var to_check = words_text.slice(i, i+key_words).join("").replace(/[^0-9a-z \'\"]/gi, '').trim();
|
||||||
|
if (keyword == to_check) {
|
||||||
|
for (var j = i; j < key_words+i; j++) {
|
||||||
|
words[j].title = worldinfo['content'];
|
||||||
|
words[j].classList.add("tag_wiid_"+wiid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// //Check each word
|
|
||||||
// if (found) {
|
|
||||||
// for (word of action.children) {
|
|
||||||
// //we need to check each word to see if it's in the list
|
|
||||||
//
|
|
||||||
// for (const [key, worldinfo] of Object.entries(worldinfo_to_check)) {
|
|
||||||
// //console.log(worldinfo);
|
|
||||||
// if ('key' in worldinfo) {
|
|
||||||
// if ((worldinfo['key'].includes(word.textContent.replace(/[^0-9a-z\'\"]/gi, '')))) {
|
|
||||||
// console.log(word.textContent+" is in wiid "+key);
|
|
||||||
// word.title = worldinfo['content'];
|
|
||||||
// //word.textContent = worldinfo['content'];
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function update_token_lengths() {
|
function update_token_lengths() {
|
||||||
max_token_length = parseInt(document.getElementById("model_max_length_cur").value);
|
max_token_length = parseInt(document.getElementById("model_max_length_cur").value);
|
||||||
if ((document.getElementById("memory").getAttribute("story_memory_length") == null) || (document.getElementById("memory").getAttribute("story_memory_length") == "")) {
|
if ((document.getElementById("memory").getAttribute("story_memory_length") == null) || (document.getElementById("memory").getAttribute("story_memory_length") == "")) {
|
||||||
|
@@ -55,5 +55,5 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="story_menu_wi" class="story_category_area hidden">
|
<div id="story_menu_wi" class="story_category_area hidden">
|
||||||
|
<span id="world_info_folder_root" class="WI_Folder"><h2>root</h2></span>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user