mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-06-05 21:59:24 +02:00
Fix save loading between v1 and v2 to v3 with wi features
This commit is contained in:
@@ -968,9 +968,9 @@ class story_settings(settings):
|
||||
else:
|
||||
logger.warning(f"Story mismatch in v2 migration. Existing file had story id {v2j['story_id']} but we have {self.story_id}")
|
||||
|
||||
self.gamesaved = True
|
||||
with open(self.save_paths.story, "w", encoding="utf-8") as file:
|
||||
file.write(self.to_json())
|
||||
self.gamesaved = True
|
||||
|
||||
def update_story_path_structure(self, path: str) -> None:
|
||||
# Upon loading a file, makes directories that are required for certain
|
||||
@@ -2357,7 +2357,8 @@ class KoboldWorldInfo(object):
|
||||
raise
|
||||
if folder not in self.world_info_folder:
|
||||
self.world_info_folder[folder] = []
|
||||
self.world_info_folder[folder].append(uid)
|
||||
if uid not in self.world_info_folder[folder]:
|
||||
self.world_info_folder[folder].append(uid)
|
||||
self.story_settings.gamesaved = False
|
||||
if sync:
|
||||
self.sync_world_info_to_old_format()
|
||||
@@ -2536,14 +2537,10 @@ class KoboldWorldInfo(object):
|
||||
file.write(base64.b64decode(image_b64))
|
||||
|
||||
data["entries"] = {k: self.upgrade_entry(v) for k,v in data["entries"].items()}
|
||||
|
||||
if folder is None:
|
||||
self.world_info_folder = data['folders']
|
||||
|
||||
#Add the item
|
||||
start_time = time.time()
|
||||
for uid, item in data['entries'].items():
|
||||
|
||||
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 [],
|
||||
@@ -2555,10 +2552,9 @@ class KoboldWorldInfo(object):
|
||||
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': {}},
|
||||
object_type=item.get("object_type"),
|
||||
v1_uid=item.get("v1_uid"),
|
||||
recalc=False, sync=False)
|
||||
if folder is None:
|
||||
#self.world_info = {int(x): data['entries'][x] for x in data['entries']}
|
||||
self.world_info_folder = data['folders']
|
||||
|
||||
logger.debug("Load World Info took {}s".format(time.time()-start_time))
|
||||
try:
|
||||
start_time = time.time()
|
||||
@@ -2577,50 +2573,52 @@ class KoboldWorldInfo(object):
|
||||
for folder in self.world_info_folder:
|
||||
folder_entries[folder] = i
|
||||
i-=1
|
||||
|
||||
|
||||
|
||||
#self.wifolders_l = [] # List of World Info folder UIDs
|
||||
self.story_settings.wifolders_l = [folder_entries[x] for x in folder_entries if x != "root"]
|
||||
|
||||
#self.worldinfo_i = [] # List of World Info key/value objects sans uninitialized entries
|
||||
self.story_settings.worldinfo_i = [{
|
||||
"comment": self.world_info[x]['comment'],
|
||||
"constant": self.world_info[x]['constant'],
|
||||
"content": self.world_info[x]['content'],
|
||||
"folder": folder_entries[self.world_info[x]['folder']],
|
||||
"init": True,
|
||||
"key": ",".join(self.world_info[x]['key']),
|
||||
"keysecondary": ",".join(self.world_info[x]['keysecondary']),
|
||||
"content": self.world_info[x]['content'],
|
||||
"comment": self.world_info[x]['comment'],
|
||||
"folder": folder_entries[self.world_info[x]['folder']] if self.world_info[x]['folder'] != "root" else None,
|
||||
"num": x,
|
||||
"init": True,
|
||||
"selective": len(self.world_info[x]['keysecondary'])>0,
|
||||
"constant": self.world_info[x]['constant'],
|
||||
"uid": self.world_info[x]['uid'] if 'v1_uid' not in self.world_info[x] or self.world_info[x]['v1_uid'] is None else self.world_info[x]['v1_uid']
|
||||
} for x in self.world_info]
|
||||
|
||||
|
||||
#self.worldinfo = [] # List of World Info key/value objects
|
||||
self.story_settings.worldinfo = [x for x in self.story_settings.worldinfo_i]
|
||||
#We have to have an uninitialized blank entry for every folder or the old method craps out
|
||||
for folder in folder_entries:
|
||||
self.story_settings.worldinfo.append({
|
||||
"comment": "",
|
||||
"constant": False,
|
||||
"content": "",
|
||||
"folder": folder_entries[folder],
|
||||
"init": False,
|
||||
"key": "",
|
||||
"keysecondary": "",
|
||||
"content": "",
|
||||
"comment": "",
|
||||
"folder": folder_entries[folder] if folder != "root" else None,
|
||||
"num": (0 if len(self.world_info) == 0 else max(self.world_info))+(folder_entries[folder]*-1),
|
||||
"init": False,
|
||||
"selective": False,
|
||||
"constant": False,
|
||||
"uid": folder_entries[folder]
|
||||
})
|
||||
|
||||
mapping = {uid: index for index, uid in enumerate(self.story_settings.wifolders_l)}
|
||||
self.story_settings.worldinfo.sort(key=lambda x: mapping[x["folder"]] if x["folder"] is not None else float("inf"))
|
||||
|
||||
#self.wifolders_d = {} # Dictionary of World Info folder UID-info pairs
|
||||
self.story_settings.wifolders_d = {folder_entries[x]: {'collapsed': False, 'name': x} for x in folder_entries}
|
||||
self.story_settings.wifolders_d = {str(folder_entries[x]): {'name': x, 'collapsed': False} for x in folder_entries if x != "root"}
|
||||
|
||||
#self.worldinfo_u = {} # Dictionary of World Info UID - key/value pairs
|
||||
self.story_settings.worldinfo_u = {x['uid']: x for x in self.story_settings.worldinfo}
|
||||
|
||||
#self.wifolders_l = [] # List of World Info folder UIDs
|
||||
self.story_settings.wifolders_l = [folder_entries[x] for x in folder_entries]
|
||||
self.story_settings.worldinfo_u = {str(y["uid"]): y for x in folder_entries for y in self.story_settings.worldinfo if y["folder"] == (folder_entries[x] if x != "root" else None)}
|
||||
|
||||
#self.wifolders_u = {} # Dictionary of pairs of folder UID - list of WI UID
|
||||
self.story_settings.wifolders_u = {folder_entries[x]: [y for y in self.story_settings.worldinfo if y['folder'] == x] for x in folder_entries}
|
||||
self.story_settings.wifolders_u = {str(folder_entries[x]): [y for y in self.story_settings.worldinfo if y['folder'] == folder_entries[x]] for x in folder_entries if x != "root"}
|
||||
|
||||
def reset_used_in_game(self):
|
||||
for key in self.world_info:
|
||||
@@ -2638,7 +2636,10 @@ class KoboldWorldInfo(object):
|
||||
self._socketio.emit("world_info_entry_used_in_game", {"uid": uid, "used_in_game": True}, broadcast=True, room="UI_2")
|
||||
|
||||
def get_used_wi(self):
|
||||
return [x['content'] for x in self.world_info if x['used_in_game']]
|
||||
# return [self.world_info[x]['content'] for x in self.world_info if self.world_info[x]['used_in_game']]
|
||||
result = [x['content'] for x in self.world_info if x['used_in_game']]
|
||||
logger.warning("get_used_wi: " + str(result))
|
||||
return result
|
||||
|
||||
def to_wi_fewshot_format(self, excluding_uid: int) -> List[str]:
|
||||
"""
|
||||
|
Reference in New Issue
Block a user