mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-06-05 21:59:24 +02:00
Added in export of world info folders
This commit is contained in:
18
aiserver.py
18
aiserver.py
@@ -7310,6 +7310,24 @@ def UI_2_create_world_info_folder(data):
|
|||||||
def UI_2_delete_world_info(uid):
|
def UI_2_delete_world_info(uid):
|
||||||
koboldai_vars.worldinfo_v2.delete(int(uid))
|
koboldai_vars.worldinfo_v2.delete(int(uid))
|
||||||
|
|
||||||
|
#==================================================================#
|
||||||
|
# Event triggered when user exports world info folder
|
||||||
|
#==================================================================#
|
||||||
|
@app.route('/export_world_info_folder')
|
||||||
|
def UI_2_export_world_info_folder():
|
||||||
|
if 'folder' in request.args:
|
||||||
|
data = koboldai_vars.worldinfo_v2.to_json(folder=request.args['folder'])
|
||||||
|
folder = request.args['folder']
|
||||||
|
else:
|
||||||
|
data = koboldai_vars.worldinfo_v2.to_json()
|
||||||
|
folder = koboldai_vars.story_name
|
||||||
|
|
||||||
|
return Response(
|
||||||
|
data,
|
||||||
|
mimetype="application/json",
|
||||||
|
headers={"Content-disposition":
|
||||||
|
"attachment; filename={}_world_info.json".format(folder)})
|
||||||
|
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
# Event triggered when user edits phrase biases
|
# Event triggered when user edits phrase biases
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
|
@@ -1355,11 +1355,17 @@ class KoboldWorldInfo(object):
|
|||||||
for uid in self.world_info:
|
for uid in self.world_info:
|
||||||
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")
|
||||||
|
|
||||||
def to_json(self):
|
def to_json(self, folder=None):
|
||||||
return {
|
if folder is None:
|
||||||
"folders": {x: self.world_info_folder[x] for x in self.world_info_folder},
|
return {
|
||||||
"entries": self.world_info
|
"folders": {x: self.world_info_folder[x] for x in self.world_info_folder},
|
||||||
}
|
"entries": self.world_info
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
return {
|
||||||
|
"folders": {x: self.world_info_folder[x] for x in self.world_info_folder if x == folder},
|
||||||
|
"entries": {x: self.world_info[x] for x in self.world_info if self.world_info[x]['folder'] == folder}
|
||||||
|
}
|
||||||
|
|
||||||
def load_json(self, data):
|
def load_json(self, data):
|
||||||
self.world_info = {int(x): data['entries'][x] for x in data['entries']}
|
self.world_info = {int(x): data['entries'][x] for x in data['entries']}
|
||||||
|
@@ -1506,7 +1506,18 @@ function world_info_folder(data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
title.append(title_text);
|
title.append(title_text);
|
||||||
|
//create download button
|
||||||
|
download = document.createElement("span");
|
||||||
|
download.classList.add("material-icons-outlined");
|
||||||
|
download.setAttribute("folder", folder_name);
|
||||||
|
download.textContent = "file_download";
|
||||||
|
download.onclick = function () {
|
||||||
|
console.log('export_world_info_folder?folder='+this.getAttribute("folder"));
|
||||||
|
document.getElementById('download_iframe').src = 'export_world_info_folder?folder='+this.getAttribute("folder");
|
||||||
|
};
|
||||||
|
title.append(download);
|
||||||
folder.append(title);
|
folder.append(title);
|
||||||
|
|
||||||
//create add button
|
//create add button
|
||||||
new_icon = document.createElement("span");
|
new_icon = document.createElement("span");
|
||||||
new_icon.classList.add("wi_add_button");
|
new_icon.classList.add("wi_add_button");
|
||||||
@@ -2049,7 +2060,7 @@ function update_context(data) {
|
|||||||
$(".context-block").remove();
|
$(".context-block").remove();
|
||||||
|
|
||||||
for (const entry of data) {
|
for (const entry of data) {
|
||||||
console.log(entry);
|
//console.log(entry);
|
||||||
let contextClass = "context-" + ({
|
let contextClass = "context-" + ({
|
||||||
soft_prompt: "sp",
|
soft_prompt: "sp",
|
||||||
prompt: "prompt",
|
prompt: "prompt",
|
||||||
@@ -2310,6 +2321,8 @@ function find_wi_container(e) {
|
|||||||
while (true) {
|
while (true) {
|
||||||
if (e.parentElement == document) {
|
if (e.parentElement == document) {
|
||||||
return e;
|
return e;
|
||||||
|
} else if (e.classList.contains('WI_Folder')) {
|
||||||
|
return e;
|
||||||
} else if (e.tagName == 'H2') {
|
} else if (e.tagName == 'H2') {
|
||||||
return e.parentElement;
|
return e.parentElement;
|
||||||
} else if (typeof e.id == 'undefined') {
|
} else if (typeof e.id == 'undefined') {
|
||||||
@@ -2330,6 +2343,7 @@ function dragEnter(e) {
|
|||||||
|
|
||||||
function dragOver(e) {
|
function dragOver(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
//console.log(e.target);
|
||||||
element = find_wi_container(e.target);
|
element = find_wi_container(e.target);
|
||||||
element.classList.add('drag-over');
|
element.classList.add('drag-over');
|
||||||
}
|
}
|
||||||
@@ -2354,7 +2368,7 @@ function drop(e) {
|
|||||||
|
|
||||||
|
|
||||||
//check if we're droping on a folder, and then append it to the folder
|
//check if we're droping on a folder, and then append it to the folder
|
||||||
if (element.children[0].tagName == "H2") {
|
if (element.classList.contains('WI_Folder')) {
|
||||||
//element.append(draggable);
|
//element.append(draggable);
|
||||||
socket.emit("wi_set_folder", {'dragged_id': dragged_id, 'folder': drop_id});
|
socket.emit("wi_set_folder", {'dragged_id': dragged_id, 'folder': drop_id});
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user