mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-06-05 21:59:24 +02:00
Working W++/SBF for World Info
This commit is contained in:
13
aiserver.py
13
aiserver.py
@@ -7240,21 +7240,18 @@ def UI_2_Rename_World_Info_Folder(data):
|
|||||||
def UI_2_edit_world_info(data):
|
def UI_2_edit_world_info(data):
|
||||||
print("edit_world_info")
|
print("edit_world_info")
|
||||||
print(data)
|
print(data)
|
||||||
if 'wpp' not in data:
|
|
||||||
wpp = {'name': "", 'type': "", 'attributes': {}}
|
|
||||||
else:
|
|
||||||
wpp = data['wpp']
|
|
||||||
if data['uid'] == -1:
|
if data['uid'] == -1:
|
||||||
koboldai_vars.worldinfo_v2.add_item(data['title'], data['key'],
|
koboldai_vars.worldinfo_v2.add_item(data['title'], data['key'],
|
||||||
data['keysecondary'], data['folder'],
|
data['keysecondary'], data['folder'],
|
||||||
data['constant'], data['content'],
|
data['constant'], data['manual_text'],
|
||||||
data['comment'], wpp=wpp)
|
data['comment'], wpp=data['wpp'], use_wpp=data['use_wpp'])
|
||||||
emit("delete_new_world_info_entry", {})
|
emit("delete_new_world_info_entry", {})
|
||||||
else:
|
else:
|
||||||
koboldai_vars.worldinfo_v2.edit_item(data['uid'], data['title'], data['key'],
|
koboldai_vars.worldinfo_v2.edit_item(data['uid'], data['title'], data['key'],
|
||||||
data['keysecondary'], data['folder'],
|
data['keysecondary'], data['folder'],
|
||||||
data['constant'], data['content'],
|
data['constant'], data['manual_text'],
|
||||||
data['comment'], wpp=wpp)
|
data['comment'], wpp=data['wpp'], use_wpp=data['use_wpp'])
|
||||||
|
|
||||||
|
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
|
@@ -1166,11 +1166,24 @@ class KoboldWorldInfo(object):
|
|||||||
self.sync_world_info_to_old_format()
|
self.sync_world_info_to_old_format()
|
||||||
self.socketio.emit("world_info_folder", {x: self.world_info_folder[x] for x in self.world_info_folder}, broadcast=True, room="UI_2")
|
self.socketio.emit("world_info_folder", {x: self.world_info_folder[x] for x in self.world_info_folder}, broadcast=True, room="UI_2")
|
||||||
|
|
||||||
def add_item(self, title, key, keysecondary, folder, constant, content, comment, wpp={'name': "", 'type': "", 'attributes': {}}):
|
def add_item(self, title, key, keysecondary, folder, constant, manual_text, comment, use_wpp=False, wpp={'name': "", 'type': "", 'format': "W++", 'attributes': {}}):
|
||||||
if len(self.world_info) == 0:
|
if len(self.world_info) == 0:
|
||||||
uid = 0
|
uid = 0
|
||||||
else:
|
else:
|
||||||
uid = max(self.world_info)+1
|
uid = max(self.world_info)+1
|
||||||
|
if use_wpp:
|
||||||
|
if wpp['format'] == "W++":
|
||||||
|
content = '[{}("{}")\n{{\n'.format(wpp['type'], wpp['name'])
|
||||||
|
for attribute in wpp['attributes']:
|
||||||
|
content = "{}{}({})\n".format(content, attribute, " + ".join(['"{}"'.format(x) for x in wpp['attributes'][attribute]]))
|
||||||
|
content = "{}}}]".format(content)
|
||||||
|
else:
|
||||||
|
content = '[ {}: "{}";'.format(wpp['type'], wpp['name'])
|
||||||
|
for attribute in wpp['attributes']:
|
||||||
|
content = "{} {}: {};".format(content, attribute, ", ".join(['"{}"'.format(x) for x in wpp['attributes'][attribute]]))
|
||||||
|
content = "{} ]".format(content[:-1])
|
||||||
|
else:
|
||||||
|
content = manual_text
|
||||||
if self.tokenizer is not None:
|
if self.tokenizer is not None:
|
||||||
token_length = len(self.tokenizer.encode(content))
|
token_length = len(self.tokenizer.encode(content))
|
||||||
else:
|
else:
|
||||||
@@ -1194,12 +1207,14 @@ class KoboldWorldInfo(object):
|
|||||||
"keysecondary": keysecondary,
|
"keysecondary": keysecondary,
|
||||||
"folder": folder,
|
"folder": folder,
|
||||||
"constant": constant,
|
"constant": constant,
|
||||||
|
'manual_text': manual_text,
|
||||||
"content": content,
|
"content": content,
|
||||||
"comment": comment,
|
"comment": comment,
|
||||||
"token_length": token_length,
|
"token_length": token_length,
|
||||||
"selective": len(keysecondary) > 0,
|
"selective": len(keysecondary) > 0,
|
||||||
"used_in_game": constant,
|
"used_in_game": constant,
|
||||||
'wpp': wpp
|
'wpp': wpp,
|
||||||
|
'use_wpp': use_wpp
|
||||||
}
|
}
|
||||||
except:
|
except:
|
||||||
print("Error:")
|
print("Error:")
|
||||||
@@ -1216,11 +1231,24 @@ class KoboldWorldInfo(object):
|
|||||||
self.socketio.emit("world_info_entry", self.world_info[uid], broadcast=True, room="UI_2")
|
self.socketio.emit("world_info_entry", self.world_info[uid], broadcast=True, room="UI_2")
|
||||||
ignore = self.koboldai_vars.calc_ai_text()
|
ignore = self.koboldai_vars.calc_ai_text()
|
||||||
|
|
||||||
def edit_item(self, uid, title, key, keysecondary, folder, constant, content, comment, before=None, wpp={'name': "", 'type': "", 'attributes': {}}):
|
def edit_item(self, uid, title, key, keysecondary, folder, constant, manual_text, comment, use_wpp=False, before=None, wpp={'name': "", 'type': "", 'format': "W++", 'attributes': {}}):
|
||||||
old_folder = self.world_info[uid]['folder']
|
old_folder = self.world_info[uid]['folder']
|
||||||
#move the world info entry if the folder changed or if there is a new order requested
|
#move the world info entry if the folder changed or if there is a new order requested
|
||||||
if old_folder != folder or before is not None:
|
if old_folder != folder or before is not None:
|
||||||
self.add_item_to_folder(uid, folder, before=before)
|
self.add_item_to_folder(uid, folder, before=before)
|
||||||
|
if use_wpp:
|
||||||
|
if wpp['format'] == "W++":
|
||||||
|
content = '[{}("{}")\n{{\n'.format(wpp['type'], wpp['name'])
|
||||||
|
for attribute in wpp['attributes']:
|
||||||
|
content = "{}{}({})\n".format(content, attribute, " + ".join(['"{}"'.format(x) for x in wpp['attributes'][attribute]]))
|
||||||
|
content = "{}}}]".format(content)
|
||||||
|
else:
|
||||||
|
content = '[ {}: "{}";'.format(wpp['type'], wpp['name'])
|
||||||
|
for attribute in wpp['attributes']:
|
||||||
|
content = "{} {}: {};".format(content, attribute, ", ".join(['"{}"'.format(x) for x in wpp['attributes'][attribute]]))
|
||||||
|
content = "{} ]".format(content[:-1])
|
||||||
|
else:
|
||||||
|
content = manual_text
|
||||||
if self.tokenizer is not None:
|
if self.tokenizer is not None:
|
||||||
token_length = len(self.tokenizer.encode(content))
|
token_length = len(self.tokenizer.encode(content))
|
||||||
else:
|
else:
|
||||||
@@ -1234,12 +1262,14 @@ class KoboldWorldInfo(object):
|
|||||||
"keysecondary": keysecondary,
|
"keysecondary": keysecondary,
|
||||||
"folder": folder,
|
"folder": folder,
|
||||||
"constant": constant,
|
"constant": constant,
|
||||||
|
'manual_text': manual_text,
|
||||||
"content": content,
|
"content": content,
|
||||||
"comment": comment,
|
"comment": comment,
|
||||||
"token_length": token_length,
|
"token_length": token_length,
|
||||||
"selective": len(keysecondary) > 0,
|
"selective": len(keysecondary) > 0,
|
||||||
"used_in_game": constant,
|
"used_in_game": constant,
|
||||||
'wpp': wpp
|
'wpp': wpp,
|
||||||
|
'use_wpp': use_wpp
|
||||||
}
|
}
|
||||||
|
|
||||||
self.story_settings.gamesaved = False
|
self.story_settings.gamesaved = False
|
||||||
|
@@ -1264,7 +1264,7 @@ function world_info_entry(data) {
|
|||||||
wpp_toggle.id = "world_info_wpp_toggle_"+data.uid;
|
wpp_toggle.id = "world_info_wpp_toggle_"+data.uid;
|
||||||
wpp_toggle.setAttribute("type", "checkbox");
|
wpp_toggle.setAttribute("type", "checkbox");
|
||||||
wpp_toggle.setAttribute("uid", data.uid);
|
wpp_toggle.setAttribute("uid", data.uid);
|
||||||
wpp_toggle.checked = ((data.wpp.type != ""));
|
wpp_toggle.checked = data.use_wpp;
|
||||||
wpp_toggle.setAttribute("data-size", "mini");
|
wpp_toggle.setAttribute("data-size", "mini");
|
||||||
wpp_toggle.setAttribute("data-onstyle", "success");
|
wpp_toggle.setAttribute("data-onstyle", "success");
|
||||||
wpp_toggle.setAttribute("data-toggle", "toggle");
|
wpp_toggle.setAttribute("data-toggle", "toggle");
|
||||||
@@ -1276,7 +1276,9 @@ function world_info_entry(data) {
|
|||||||
document.getElementById("world_info_wpp_area_"+this.getAttribute('uid')).classList.add("hidden");
|
document.getElementById("world_info_wpp_area_"+this.getAttribute('uid')).classList.add("hidden");
|
||||||
document.getElementById("world_info_basic_text_"+this.getAttribute('uid')).classList.remove("hidden");
|
document.getElementById("world_info_basic_text_"+this.getAttribute('uid')).classList.remove("hidden");
|
||||||
}
|
}
|
||||||
//send_world_info(this.getAttribute('uid'));
|
|
||||||
|
world_info_data[this.getAttribute('uid')]['use_wpp'] = this.checked;
|
||||||
|
send_world_info(this.getAttribute('uid'));
|
||||||
this.classList.add("pulse");
|
this.classList.add("pulse");
|
||||||
}
|
}
|
||||||
wpp_toggle_area.append(wpp_toggle);
|
wpp_toggle_area.append(wpp_toggle);
|
||||||
@@ -1284,13 +1286,25 @@ function world_info_entry(data) {
|
|||||||
world_info_wpp_area = world_info_card.querySelector('#world_info_wpp_area_');
|
world_info_wpp_area = world_info_card.querySelector('#world_info_wpp_area_');
|
||||||
world_info_wpp_area.id = "world_info_wpp_area_"+data.uid;
|
world_info_wpp_area.id = "world_info_wpp_area_"+data.uid;
|
||||||
world_info_wpp_area.setAttribute("uid", data.uid);
|
world_info_wpp_area.setAttribute("uid", data.uid);
|
||||||
|
wpp_format = world_info_card.querySelector('#wpp_format_');
|
||||||
|
wpp_format.id = "wpp_format_"+data.uid;
|
||||||
|
wpp_format.setAttribute("uid", data.uid);
|
||||||
|
wpp_format.setAttribute("data_type", "format");
|
||||||
|
wpp_format.onchange = function () {
|
||||||
|
do_wpp(this.parentElement);
|
||||||
|
}
|
||||||
|
console.log(data.wpp['format']);
|
||||||
|
console.log(data.wpp);
|
||||||
|
if (data.wpp.format == "W++") {
|
||||||
|
wpp_format.selectedIndex = 0;
|
||||||
|
} else {
|
||||||
|
wpp_format.selectedIndex = 1;
|
||||||
|
}
|
||||||
wpp_type = world_info_card.querySelector('#wpp_type_');
|
wpp_type = world_info_card.querySelector('#wpp_type_');
|
||||||
wpp_type.id = "wpp_type_"+data.uid;
|
wpp_type.id = "wpp_type_"+data.uid;
|
||||||
wpp_type.setAttribute("uid", data.uid);
|
wpp_type.setAttribute("uid", data.uid);
|
||||||
wpp_type.setAttribute("data_type", "type");
|
wpp_type.setAttribute("data_type", "type");
|
||||||
if ("wpp" in data) {
|
wpp_type.value = data.wpp.type;
|
||||||
wpp_type.value = data.wpp.type;
|
|
||||||
}
|
|
||||||
wpp_name = world_info_card.querySelector('#wpp_name_');
|
wpp_name = world_info_card.querySelector('#wpp_name_');
|
||||||
wpp_name.id = "wpp_name_"+data.uid;
|
wpp_name.id = "wpp_name_"+data.uid;
|
||||||
wpp_name.setAttribute("uid", data.uid);
|
wpp_name.setAttribute("uid", data.uid);
|
||||||
@@ -1299,11 +1313,11 @@ function world_info_entry(data) {
|
|||||||
wpp_name.value = data.wpp.name;
|
wpp_name.value = data.wpp.name;
|
||||||
}
|
}
|
||||||
if ('attributes' in data.wpp) {
|
if ('attributes' in data.wpp) {
|
||||||
for (const [attribute, value] of Object.entries(data.wpp.attributes)) {
|
for (const [attribute, values] of Object.entries(data.wpp.attributes)) {
|
||||||
if (attribute != '') {
|
if (attribute != '') {
|
||||||
attribute_area = document.createElement("div");
|
attribute_area = document.createElement("div");
|
||||||
label = document.createElement("span");
|
label = document.createElement("span");
|
||||||
label.textContent = "Attribute: ";
|
label.textContent = "\xa0\xa0\xa0\xa0Attribute: ";
|
||||||
attribute_area.append(label);
|
attribute_area.append(label);
|
||||||
input = document.createElement("input");
|
input = document.createElement("input");
|
||||||
input.value = attribute;
|
input.value = attribute;
|
||||||
@@ -1313,10 +1327,10 @@ function world_info_entry(data) {
|
|||||||
input.onchange = function() {do_wpp(this.parentElement.parentElement)};
|
input.onchange = function() {do_wpp(this.parentElement.parentElement)};
|
||||||
attribute_area.append(input);
|
attribute_area.append(input);
|
||||||
world_info_wpp_area.append(attribute_area);
|
world_info_wpp_area.append(attribute_area);
|
||||||
for (value of value) {
|
for (value of values) {
|
||||||
value_area = document.createElement("div");
|
value_area = document.createElement("div");
|
||||||
label = document.createElement("span");
|
label = document.createElement("span");
|
||||||
label.textContent = " Value: ";
|
label.textContent = "\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0Value: ";
|
||||||
value_area.append(label);
|
value_area.append(label);
|
||||||
input = document.createElement("input");
|
input = document.createElement("input");
|
||||||
input.type = "text";
|
input.type = "text";
|
||||||
@@ -1329,7 +1343,7 @@ function world_info_entry(data) {
|
|||||||
}
|
}
|
||||||
value_area = document.createElement("div");
|
value_area = document.createElement("div");
|
||||||
label = document.createElement("span");
|
label = document.createElement("span");
|
||||||
label.textContent = " Value: ";
|
label.textContent = "\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0Value: ";
|
||||||
value_area.append(label);
|
value_area.append(label);
|
||||||
input = document.createElement("input");
|
input = document.createElement("input");
|
||||||
input.type = "text";
|
input.type = "text";
|
||||||
@@ -1343,7 +1357,7 @@ function world_info_entry(data) {
|
|||||||
}
|
}
|
||||||
attribute_area = document.createElement("div");
|
attribute_area = document.createElement("div");
|
||||||
label = document.createElement("span");
|
label = document.createElement("span");
|
||||||
label.textContent = "Attribute: ";
|
label.textContent = "\xa0\xa0\xa0\xa0Attribute: ";
|
||||||
attribute_area.append(label);
|
attribute_area.append(label);
|
||||||
input = document.createElement("input");
|
input = document.createElement("input");
|
||||||
input.value = "";
|
input.value = "";
|
||||||
@@ -1359,18 +1373,18 @@ function world_info_entry(data) {
|
|||||||
//regular data
|
//regular data
|
||||||
content_area = world_info_card.querySelector('#world_info_basic_text_');
|
content_area = world_info_card.querySelector('#world_info_basic_text_');
|
||||||
content_area.id = "world_info_basic_text_"+data.uid;
|
content_area.id = "world_info_basic_text_"+data.uid;
|
||||||
content = world_info_card.querySelector('#world_info_entry_text_');
|
manual_text = world_info_card.querySelector('#world_info_entry_text_');
|
||||||
content.id = "world_info_entry_text_"+data.uid;
|
manual_text.id = "world_info_entry_text_"+data.uid;
|
||||||
content.setAttribute("uid", data.uid);
|
manual_text.setAttribute("uid", data.uid);
|
||||||
content.value = data.content;
|
manual_text.value = data.manual_text;
|
||||||
content.onchange = function () {
|
manual_text.onchange = function () {
|
||||||
world_info_data[this.getAttribute('uid')]['content'] = this.value;
|
world_info_data[this.getAttribute('uid')]['manual_text'] = this.value;
|
||||||
send_world_info(this.getAttribute('uid'));
|
send_world_info(this.getAttribute('uid'));
|
||||||
this.classList.add("pulse");
|
this.classList.add("pulse");
|
||||||
}
|
}
|
||||||
comment = world_info_card.querySelector('#world_info_comment_');
|
comment = world_info_card.querySelector('#world_info_comment_');
|
||||||
comment.id = "world_info_comment_"+data.uid;
|
comment.id = "world_info_comment_"+data.uid;
|
||||||
content.setAttribute("uid", data.uid);
|
comment.setAttribute("uid", data.uid);
|
||||||
comment.value = data.comment;
|
comment.value = data.comment;
|
||||||
comment.onchange = function () {
|
comment.onchange = function () {
|
||||||
world_info_data[this.getAttribute('uid')]['comment'] = this.textContent;
|
world_info_data[this.getAttribute('uid')]['comment'] = this.textContent;
|
||||||
@@ -1432,12 +1446,12 @@ function world_info_entry(data) {
|
|||||||
$('#world_info_wpp_toggle_'+data.uid).bootstrapToggle();
|
$('#world_info_wpp_toggle_'+data.uid).bootstrapToggle();
|
||||||
|
|
||||||
//hide/unhide w++
|
//hide/unhide w++
|
||||||
if (data.wpp.type != "") {
|
if (wpp_toggle.checked) {
|
||||||
world_info_wpp_area.classList.remove("hidden");
|
document.getElementById("world_info_wpp_area_"+wpp_toggle.getAttribute('uid')).classList.remove("hidden");
|
||||||
content_area.classList.add("hidden");
|
document.getElementById("world_info_basic_text_"+wpp_toggle.getAttribute('uid')).classList.add("hidden");
|
||||||
} else {
|
} else {
|
||||||
world_info_wpp_area.classList.add("hidden");
|
document.getElementById("world_info_wpp_area_"+wpp_toggle.getAttribute('uid')).classList.add("hidden");
|
||||||
content_area.classList.remove("hidden");
|
document.getElementById("world_info_basic_text_"+wpp_toggle.getAttribute('uid')).classList.remove("hidden");
|
||||||
}
|
}
|
||||||
|
|
||||||
assign_world_info_to_action(null, data.uid);
|
assign_world_info_to_action(null, data.uid);
|
||||||
@@ -1599,6 +1613,7 @@ function do_wpp(wpp_area) {
|
|||||||
wpp['attributes'] = {};
|
wpp['attributes'] = {};
|
||||||
uid = wpp_area.getAttribute("uid");
|
uid = wpp_area.getAttribute("uid");
|
||||||
attribute = "";
|
attribute = "";
|
||||||
|
wpp['format'] = document.getElementById("wpp_format_"+uid).value;
|
||||||
for (input of wpp_area.querySelectorAll('input')) {
|
for (input of wpp_area.querySelectorAll('input')) {
|
||||||
if (input.getAttribute("data_type") == "name") {
|
if (input.getAttribute("data_type") == "name") {
|
||||||
wpp['name'] = input.value;
|
wpp['name'] = input.value;
|
||||||
@@ -1606,13 +1621,14 @@ function do_wpp(wpp_area) {
|
|||||||
wpp['type'] = input.value;
|
wpp['type'] = input.value;
|
||||||
} else if (input.getAttribute("data_type") == "attribute") {
|
} else if (input.getAttribute("data_type") == "attribute") {
|
||||||
attribute = input.value;
|
attribute = input.value;
|
||||||
if (!(input.value in wpp['attributes'])) {
|
if (!(input.value in wpp['attributes']) && (input.value != "")) {
|
||||||
console.log("adding attribute");
|
|
||||||
wpp['attributes'][input.value] = [];
|
wpp['attributes'][input.value] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (input.getAttribute("data_type") == "value") {
|
} else if ((input.getAttribute("data_type") == "value") && (attribute != "")) {
|
||||||
wpp['attributes'][attribute].push(input.value);
|
if (input.value != "") {
|
||||||
|
wpp['attributes'][attribute].push(input.value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
world_info_data[uid]['wpp'] = wpp;
|
world_info_data[uid]['wpp'] = wpp;
|
||||||
@@ -2173,10 +2189,12 @@ function create_new_wi_entry(folder) {
|
|||||||
"folder": folder,
|
"folder": folder,
|
||||||
"constant": false,
|
"constant": false,
|
||||||
"content": "",
|
"content": "",
|
||||||
|
"manual_text": "",
|
||||||
"comment": "",
|
"comment": "",
|
||||||
"token_length": 0,
|
"token_length": 0,
|
||||||
"selective": false,
|
"selective": false,
|
||||||
"wpp": {'name': "", 'type': "", 'attributes': {}}
|
"wpp": {'name': "", 'type': "", 'format': 'W++', 'attributes': {}},
|
||||||
|
'use_wpp': false,
|
||||||
};
|
};
|
||||||
card = world_info_entry(data);
|
card = world_info_entry(data);
|
||||||
card.scrollIntoView(false);
|
card.scrollIntoView(false);
|
||||||
|
@@ -16,6 +16,11 @@
|
|||||||
Use W++
|
Use W++
|
||||||
</div>
|
</div>
|
||||||
<div class="world_info_tag_area hidden" id="world_info_wpp_area_">
|
<div class="world_info_tag_area hidden" id="world_info_wpp_area_">
|
||||||
|
<!--this part is very sensitive to location. Javascript uses parents to find the above tag for each of the inputs, so don't add stuff without messing with JS-->
|
||||||
|
<select id="wpp_format_" style="color:black;">
|
||||||
|
<option>W++</option>
|
||||||
|
<option>Square Bracket Format (SBF)</option>
|
||||||
|
</select>
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Type:</td>
|
<td>Type:</td>
|
||||||
|
Reference in New Issue
Block a user