Implemented import from aidg.club

Fix for world info error on loading stories
This commit is contained in:
ebolam
2022-08-14 19:24:25 -04:00
parent eafe14d068
commit 43c8fd7e25
5 changed files with 47 additions and 97 deletions

View File

@@ -5538,48 +5538,9 @@ def load_story_v1(js):
if("worldinfo" in js):
num = 0
for wi in js["worldinfo"]:
koboldai_vars.worldinfo.append({
"key": wi["key"],
"keysecondary": wi.get("keysecondary", ""),
"content": wi["content"],
"comment": wi.get("comment", ""),
"folder": wi.get("folder", None),
"num": num,
"init": True,
"selective": wi.get("selective", False),
"constant": wi.get("constant", False),
"uid": None,
})
koboldai_vars.worldinfo_v2.add_item([x.strip() for x in wi["key"].split(",")][0], wi["key"], wi.get("keysecondary", ""),
wi.get("folder", "root"), wi.get("constant", False),
wi["content"], wi.get("comment", ""))
while(True):
uid = int.from_bytes(os.urandom(4), "little", signed=True)
if(uid not in koboldai_vars.worldinfo_u):
break
koboldai_vars.worldinfo_u[uid] = koboldai_vars.worldinfo[-1]
koboldai_vars.worldinfo[-1]["uid"] = uid
if(koboldai_vars.worldinfo[-1]["folder"] is not None):
koboldai_vars.wifolders_u[koboldai_vars.worldinfo[-1]["folder"]].append(koboldai_vars.worldinfo[-1])
num += 1
for uid in koboldai_vars.wifolders_l + [None]:
koboldai_vars.worldinfo.append({"key": "", "keysecondary": "", "content": "", "comment": "", "folder": uid, "num": None, "init": False, "selective": False, "constant": False, "uid": None})
while(True):
uid = int.from_bytes(os.urandom(4), "little", signed=True)
if(uid not in koboldai_vars.worldinfo_u):
break
try:
koboldai_vars.worldinfo_u[uid] = koboldai_vars.worldinfo[-1]
except:
print(koboldai_vars.worldinfo)
koboldai_vars.worldinfo[-1]["uid"] = uid
if(koboldai_vars.worldinfo[-1]["folder"] is not None):
koboldai_vars.wifolders_u[koboldai_vars.worldinfo[-1]["folder"]].append(koboldai_vars.worldinfo[-1])
stablesortwi()
koboldai_vars.worldinfo_i = [wi for wi in koboldai_vars.worldinfo if wi["init"]]
# Save path for save button
koboldai_vars.savedir = loadpath
@@ -5766,29 +5727,24 @@ def importgame():
def importAidgRequest(id):
exitModes()
urlformat = "https://prompts.aidg.club/api/"
urlformat = "https://aetherroom.club/api/"
req = requests.get(urlformat+id)
if(req.status_code == 200):
js = req.json()
# Import game state
koboldai_vars.create_story("")
koboldai_vars.gamestarted = True
koboldai_vars.prompt = js["promptContent"]
koboldai_vars.memory = js["memory"]
koboldai_vars.authornote = js["authorsNote"]
koboldai_vars.authornotetemplate = "[Author's note: <|>]"
koboldai_vars.actions.reset()
koboldai_vars.actions_metadata = {}
koboldai_vars.worldinfo = []
koboldai_vars.worldinfo_i = []
koboldai_vars.worldinfo_u = {}
koboldai_vars.wifolders_d = {}
koboldai_vars.wifolders_l = []
koboldai_vars.wifolders_u = {uid: [] for uid in koboldai_vars.wifolders_d}
koboldai_vars.lastact = ""
koboldai_vars.submission = ""
koboldai_vars.lastctx = ""
if not koboldai_vars.memory:
koboldai_vars.memory = ""
if not koboldai_vars.authornote:
koboldai_vars.authornote = ""
num = 0
for wi in js["worldInfos"]:
@@ -5804,28 +5760,12 @@ def importAidgRequest(id):
"constant": wi.get("constant", False),
"uid": None,
})
while(True):
uid = int.from_bytes(os.urandom(4), "little", signed=True)
if(uid not in koboldai_vars.worldinfo_u):
break
koboldai_vars.worldinfo_u[uid] = koboldai_vars.worldinfo[-1]
koboldai_vars.worldinfo[-1]["uid"] = uid
if(koboldai_vars.worldinfo[-1]["folder"]) is not None:
koboldai_vars.wifolders_u[koboldai_vars.worldinfo[-1]["folder"]].append(koboldai_vars.worldinfo[-1])
num += 1
for uid in koboldai_vars.wifolders_l + [None]:
koboldai_vars.worldinfo.append({"key": "", "keysecondary": "", "content": "", "comment": "", "folder": uid, "num": None, "init": False, "selective": False, "constant": False, "uid": None})
while(True):
uid = int.from_bytes(os.urandom(4), "little", signed=True)
if(uid not in koboldai_vars.worldinfo_u):
break
koboldai_vars.worldinfo_u[uid] = koboldai_vars.worldinfo[-1]
koboldai_vars.worldinfo[-1]["uid"] = uid
if(koboldai_vars.worldinfo[-1]["folder"] is not None):
koboldai_vars.wifolders_u[koboldai_vars.worldinfo[-1]["folder"]].append(koboldai_vars.worldinfo[-1])
stablesortwi()
koboldai_vars.worldinfo_i = [wi for wi in koboldai_vars.worldinfo if wi["init"]]
koboldai_vars.worldinfo_v2.add_item([x.strip() for x in wi["keys"].split(",")][0], wi["keys"], wi.get("keysecondary", ""),
wi.get("folder", "root"), wi.get("constant", False),
wi["entry"], wi.get("comment", ""))
# Reset current save
koboldai_vars.savedir = getcwd()+"\\stories"
@@ -6674,6 +6614,17 @@ def UI_2_load_softprompt(data):
print("Load softprompt: {}".format(data))
spRequest(data)
#==================================================================#
# Event triggered when aidg.club loaded
#==================================================================#
@socketio.on('load_aidg_club')
def UI_2_load_aidg_club(data):
print("Load aidg.club: {}".format(data))
importAidgRequest(data)
#==================================================================#
# Test
#==================================================================#

View File

@@ -1011,6 +1011,7 @@ class KoboldWorldInfo(object):
def reorder(self, uid, before):
self.add_item_to_folder(uid, self.world_info[before]['folder'], before=before)
self.sync_world_info_to_old_format()
def send_to_ui(self):
self.socketio.emit("world_info_folder", {x: self.world_info_folder[x] for x in self.world_info_folder}, broadcast=True, room="UI_2")
@@ -1048,7 +1049,7 @@ class KoboldWorldInfo(object):
"comment": self.world_info[x]['comment'],
"constant": self.world_info[x]['constant'],
"content": self.world_info[x]['content'],
"folder": self.world_info[x]['folder'],
"folder": folder_entries[self.world_info[x]['folder']],
"init": True,
"key": ",".join(self.world_info[x]['key']),
"keysecondary": ",".join(self.world_info[x]['keysecondary']),

View File

@@ -1498,7 +1498,7 @@ function preserve_game_space(preserve) {
document.getElementById('preserve_game_space_setting').checked = true;
} else {
setCookie("preserve_game_space", "false");
r.style.setProperty('--setting_menu_closed_width_no_pins_width', '450px');
r.style.setProperty('--setting_menu_closed_width_no_pins_width', 'var(--flyout_menu_width)');
if (document.getElementById('preserve_game_space_setting').checked) {
//not sure why the bootstrap-toggle won't respect a standard item.checked = true/false, so....
document.getElementById('preserve_game_space_setting').parentNode.click();
@@ -2090,7 +2090,6 @@ function close_menus() {
//close popup menus
document.getElementById('popup').classList.add("hidden");
document.getElementById('loadmodelcontainer').classList.add("hidden");
document.getElementById('loadcontainer').classList.add("hidden");
document.getElementById('save-confirm').classList.add("hidden");
document.getElementById('error_message').classList.add("hidden");

View File

@@ -52,23 +52,6 @@
</div>
</div>
<!---------------- Story Load Screen ---------------------->
<div class="popup hidden" id="loadcontainer">
<div class="title">
<div class="popuptitletext">Select A Story To Load</div>
</div>
<div style="display: flex;">
<div>Save Name</div>
<div style="margin-left: auto;"># Actions</div>
</div>
<div id="popup_list_area" class="popup_list_area">
</div>
<div class="popup_load_cancel">
<button type="button" class="btn btn-primary" id="btn_loadaccept">Load</button>
<button type="button" class="btn btn-primary" id="btn_loadclose">Cancel</button>
</div>
</div>
<!---------------- Story overwrite screen ---------------------->
<div class="popup hidden" id="save-confirm">
<div class="title">
@@ -82,8 +65,24 @@
<button type="button" class="btn btn-primary" onclick="document.getElementById('save-confirm').classList.add('hidden');">Cancel</button>
</div>
</div>
<!---------------- Import aidg.club Prompt ---------------------->
<div class="popup hidden" id="import_aidg_club_popup">
<div class="title">
<div class="popuptitletext">Enter the Prompt Number</div>
</div>
<div class="popup_list_area">
<br/>
<div style="text-align: center;"><a href="https://aetherroom.club/" target="_blank" rel="noopener noreferrer">https://aetherroom.club/</a></div>
<br/>
<input autocomplete="off" class="form-control" type="text" placeholder="Prompt Number (4-digit number at the end of aetherroom.club URL)" id="aidgpromptnum">
</div>
<div class="popup_load_cancel">
<button type="button" class="btn btn-primary" onclick="socket.emit('load_aidg_club', document.getElementById('aidgpromptnum').value); this.parentElement.parentElement.classList.add('hidden');">Accept</button>
<button type="button" class="btn btn-primary" onclick="this.parentElement.parentElement.classList.add('hidden');">Cancel</button>
</div>
</div>
<!---------------- Story overwrite screen ---------------------->
<!---------------- error screen ---------------------->
<div class="popup hidden" id="error_message">
<div class="title">
<div class="popuptitletext">Error</div>

View File

@@ -55,7 +55,7 @@
<span class="material-icons-outlined cursor" title="New Story" onclick="socket.emit('new_story', '');">description</span>
<span class="material-icons-outlined cursor" title="Load Story" onclick="socket.emit('load_story_list', '');">folder_open</span>
<span class="material-icons-outlined cursor var_sync_alt_story_gamesaved" title="Save Story">save</span>
<span class="material-icons-outlined cursor" title="Import Story">cloud_download</span>
<span class="material-icons-outlined cursor" title="Import Story" onclick="document.getElementById('import_aidg_club_popup').classList.remove('hidden');">cloud_download</span>
<span class="material-icons-outlined cursor" title="Download Story" onclick="document.getElementById('download_iframe').src = 'json';">file_download</span>
</div>
</div>