mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-06-05 21:59:24 +02:00
Initial World Info showing in new ui
Added model download status to old ui
This commit is contained in:
109
aiserver.py
109
aiserver.py
@@ -1187,9 +1187,57 @@ def patch_causallm(model):
|
|||||||
Embedding._koboldai_patch_causallm_model = model
|
Embedding._koboldai_patch_causallm_model = model
|
||||||
return model
|
return model
|
||||||
|
|
||||||
|
def patch_transformers_download():
|
||||||
|
global transformers
|
||||||
|
import copy, requests, tqdm, time
|
||||||
|
class Send_to_socketio(object):
|
||||||
|
def write(self, bar):
|
||||||
|
bar = bar.replace("\r", "")
|
||||||
|
try:
|
||||||
|
emit('from_server', {'cmd': 'model_load_status', 'data': bar.replace(" ", " ")}, broadcast=True, room="UI_1")
|
||||||
|
eventlet.sleep(seconds=0)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
def http_get(
|
||||||
|
url: str,
|
||||||
|
temp_file: transformers.utils.hub.BinaryIO,
|
||||||
|
proxies=None,
|
||||||
|
resume_size=0,
|
||||||
|
headers: transformers.utils.hub.Optional[transformers.utils.hub.Dict[str, str]] = None,
|
||||||
|
file_name: transformers.utils.hub.Optional[str] = None,
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Download remote file. Do not gobble up errors.
|
||||||
|
"""
|
||||||
|
headers = copy.deepcopy(headers)
|
||||||
|
if resume_size > 0:
|
||||||
|
headers["Range"] = f"bytes={resume_size}-"
|
||||||
|
r = requests.get(url, stream=True, proxies=proxies, headers=headers)
|
||||||
|
transformers.utils.hub._raise_for_status(r)
|
||||||
|
content_length = r.headers.get("Content-Length")
|
||||||
|
total = resume_size + int(content_length) if content_length is not None else None
|
||||||
|
# `tqdm` behavior is determined by `utils.logging.is_progress_bar_enabled()`
|
||||||
|
# and can be set using `utils.logging.enable/disable_progress_bar()`
|
||||||
|
progress = tqdm.tqdm(
|
||||||
|
unit="B",
|
||||||
|
unit_scale=True,
|
||||||
|
unit_divisor=1024,
|
||||||
|
total=total,
|
||||||
|
initial=resume_size,
|
||||||
|
desc=f"Downloading {file_name}" if file_name is not None else "Downloading",
|
||||||
|
file=Send_to_socketio(),
|
||||||
|
)
|
||||||
|
for chunk in r.iter_content(chunk_size=1024):
|
||||||
|
if chunk: # filter out keep-alive new chunks
|
||||||
|
progress.update(len(chunk))
|
||||||
|
temp_file.write(chunk)
|
||||||
|
progress.close()
|
||||||
|
|
||||||
|
transformers.utils.hub.http_get = http_get
|
||||||
|
|
||||||
def patch_transformers():
|
def patch_transformers():
|
||||||
global transformers
|
global transformers
|
||||||
|
patch_transformers_download()
|
||||||
old_from_pretrained = PreTrainedModel.from_pretrained.__func__
|
old_from_pretrained = PreTrainedModel.from_pretrained.__func__
|
||||||
@classmethod
|
@classmethod
|
||||||
def new_from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs):
|
def new_from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs):
|
||||||
@@ -5158,7 +5206,7 @@ def saveRequest(savpath, savepins=True):
|
|||||||
js["anotetemplate"] = koboldai_vars.authornotetemplate
|
js["anotetemplate"] = koboldai_vars.authornotetemplate
|
||||||
js["actions"] = tuple(koboldai_vars.actions.values())
|
js["actions"] = tuple(koboldai_vars.actions.values())
|
||||||
if savepins:
|
if savepins:
|
||||||
js["actions_metadata"] = koboldai_vars.actions_metadata
|
js["actions_metadata"] = koboldai_vars.actions.options(ui_version=1)
|
||||||
js["worldinfo"] = []
|
js["worldinfo"] = []
|
||||||
js["wifolders_d"] = koboldai_vars.wifolders_d
|
js["wifolders_d"] = koboldai_vars.wifolders_d
|
||||||
js["wifolders_l"] = koboldai_vars.wifolders_l
|
js["wifolders_l"] = koboldai_vars.wifolders_l
|
||||||
@@ -5292,7 +5340,8 @@ def load_story_v1(js):
|
|||||||
_filename = filename[:-5]
|
_filename = filename[:-5]
|
||||||
session['story'] = _filename
|
session['story'] = _filename
|
||||||
#create the story
|
#create the story
|
||||||
koboldai_vars.create_story(session['story'])
|
#koboldai_vars.create_story(session['story'])
|
||||||
|
koboldai_vars.create_story('default')
|
||||||
|
|
||||||
koboldai_vars.laststory = _filename
|
koboldai_vars.laststory = _filename
|
||||||
#set the story_name
|
#set the story_name
|
||||||
@@ -5303,8 +5352,9 @@ def load_story_v1(js):
|
|||||||
koboldai_vars.gamestarted = js["gamestarted"]
|
koboldai_vars.gamestarted = js["gamestarted"]
|
||||||
koboldai_vars.prompt = js["prompt"]
|
koboldai_vars.prompt = js["prompt"]
|
||||||
koboldai_vars.memory = js["memory"]
|
koboldai_vars.memory = js["memory"]
|
||||||
|
koboldai_vars.worldinfo_v2.reset()
|
||||||
koboldai_vars.worldinfo = []
|
koboldai_vars.worldinfo = []
|
||||||
koboldai_vars.worldinfo = []
|
koboldai_vars.worldinfo_i = []
|
||||||
koboldai_vars.worldinfo_u = {}
|
koboldai_vars.worldinfo_u = {}
|
||||||
koboldai_vars.wifolders_d = {int(k): v for k, v in js.get("wifolders_d", {}).items()}
|
koboldai_vars.wifolders_d = {int(k): v for k, v in js.get("wifolders_d", {}).items()}
|
||||||
koboldai_vars.wifolders_l = js.get("wifolders_l", [])
|
koboldai_vars.wifolders_l = js.get("wifolders_l", [])
|
||||||
@@ -5317,36 +5367,6 @@ def load_story_v1(js):
|
|||||||
actions = collections.deque(js["actions"])
|
actions = collections.deque(js["actions"])
|
||||||
|
|
||||||
|
|
||||||
if "actions_metadata" in js:
|
|
||||||
|
|
||||||
if type(js["actions_metadata"]) == dict:
|
|
||||||
temp = js["actions_metadata"]
|
|
||||||
koboldai_vars.actions_metadata = {}
|
|
||||||
#we need to redo the numbering of the actions_metadata since the actions list doesn't preserve it's number on saving
|
|
||||||
if len(temp) > 0:
|
|
||||||
counter = 0
|
|
||||||
temp = {int(k):v for k,v in temp.items()}
|
|
||||||
for i in range(max(temp)+1):
|
|
||||||
if i in temp:
|
|
||||||
koboldai_vars.actions_metadata[counter] = temp[i]
|
|
||||||
counter += 1
|
|
||||||
del temp
|
|
||||||
else:
|
|
||||||
#fix if we're using the old metadata format
|
|
||||||
koboldai_vars.actions_metadata = {}
|
|
||||||
i = 0
|
|
||||||
|
|
||||||
for text in js['actions']:
|
|
||||||
koboldai_vars.actions_metadata[i] = {'Selected Text': text, 'Alternative Text': []}
|
|
||||||
i+=1
|
|
||||||
else:
|
|
||||||
koboldai_vars.actions_metadata = {}
|
|
||||||
i = 0
|
|
||||||
|
|
||||||
for text in js['actions']:
|
|
||||||
koboldai_vars.actions_metadata[i] = {'Selected Text': text, 'Alternative Text': []}
|
|
||||||
i+=1
|
|
||||||
|
|
||||||
|
|
||||||
if(len(koboldai_vars.prompt.strip()) == 0):
|
if(len(koboldai_vars.prompt.strip()) == 0):
|
||||||
while(len(actions)):
|
while(len(actions)):
|
||||||
@@ -5360,6 +5380,14 @@ def load_story_v1(js):
|
|||||||
for s in actions:
|
for s in actions:
|
||||||
koboldai_vars.actions.append(s)
|
koboldai_vars.actions.append(s)
|
||||||
|
|
||||||
|
if "actions_metadata" in js:
|
||||||
|
if type(js["actions_metadata"]) == dict:
|
||||||
|
for key in js["actions_metadata"]:
|
||||||
|
if js["actions_metadata"][key]["Alternative Text"] != []:
|
||||||
|
data = js["actions_metadata"][key]["Alternative Text"]
|
||||||
|
data["text"] = data.pop("Text")
|
||||||
|
koboldai_vars.actions.set_options(self, data, key)
|
||||||
|
|
||||||
# Try not to break older save files
|
# Try not to break older save files
|
||||||
if("authorsnote" in js):
|
if("authorsnote" in js):
|
||||||
koboldai_vars.authornote = js["authorsnote"]
|
koboldai_vars.authornote = js["authorsnote"]
|
||||||
@@ -5385,6 +5413,18 @@ def load_story_v1(js):
|
|||||||
"constant": wi.get("constant", False),
|
"constant": wi.get("constant", False),
|
||||||
"uid": None,
|
"uid": None,
|
||||||
})
|
})
|
||||||
|
koboldai_vars.worldinfo_v2.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),
|
||||||
|
})
|
||||||
|
|
||||||
while(True):
|
while(True):
|
||||||
uid = int.from_bytes(os.urandom(4), "little", signed=True)
|
uid = int.from_bytes(os.urandom(4), "little", signed=True)
|
||||||
if(uid not in koboldai_vars.worldinfo_u):
|
if(uid not in koboldai_vars.worldinfo_u):
|
||||||
@@ -5401,7 +5441,10 @@ def load_story_v1(js):
|
|||||||
uid = int.from_bytes(os.urandom(4), "little", signed=True)
|
uid = int.from_bytes(os.urandom(4), "little", signed=True)
|
||||||
if(uid not in koboldai_vars.worldinfo_u):
|
if(uid not in koboldai_vars.worldinfo_u):
|
||||||
break
|
break
|
||||||
|
try:
|
||||||
koboldai_vars.worldinfo_u[uid] = koboldai_vars.worldinfo[-1]
|
koboldai_vars.worldinfo_u[uid] = koboldai_vars.worldinfo[-1]
|
||||||
|
except:
|
||||||
|
print(koboldai_vars.worldinfo)
|
||||||
koboldai_vars.worldinfo[-1]["uid"] = uid
|
koboldai_vars.worldinfo[-1]["uid"] = uid
|
||||||
if(koboldai_vars.worldinfo[-1]["folder"] is not None):
|
if(koboldai_vars.worldinfo[-1]["folder"] is not None):
|
||||||
koboldai_vars.wifolders_u[koboldai_vars.worldinfo[-1]["folder"]].append(koboldai_vars.worldinfo[-1])
|
koboldai_vars.wifolders_u[koboldai_vars.worldinfo[-1]["folder"]].append(koboldai_vars.worldinfo[-1])
|
||||||
|
@@ -9,8 +9,10 @@ port = 5000
|
|||||||
|
|
||||||
|
|
||||||
def clean_var_for_emit(value):
|
def clean_var_for_emit(value):
|
||||||
if isinstance(value, KoboldStoryRegister):
|
if isinstance(value, KoboldStoryRegister) or isinstance(value, KoboldWorldInfo):
|
||||||
return value.to_json()
|
return value.to_json()
|
||||||
|
elif isinstance(value, KoboldWorldInfoEntry):
|
||||||
|
return value.to_dict()
|
||||||
elif isinstance(value, set):
|
elif isinstance(value, set):
|
||||||
return list(value)
|
return list(value)
|
||||||
else:
|
else:
|
||||||
@@ -30,6 +32,10 @@ def process_variable_changes(socketio, classname, name, value, old_value, debug_
|
|||||||
socketio.emit("var_changed", {"classname": "actions", "name": "Selected Text", "old_value": None, "value": {"id": i, "text": value[i]}}, include_self=True, broadcast=True, room="UI_2")
|
socketio.emit("var_changed", {"classname": "actions", "name": "Selected Text", "old_value": None, "value": {"id": i, "text": value[i]}}, include_self=True, broadcast=True, room="UI_2")
|
||||||
socketio.emit("var_changed", {"classname": "actions", "name": "Options", "old_value": None, "value": {"id": i, "options": value.actions[i]['Options']}}, include_self=True, broadcast=True, room="UI_2")
|
socketio.emit("var_changed", {"classname": "actions", "name": "Options", "old_value": None, "value": {"id": i, "options": value.actions[i]['Options']}}, include_self=True, broadcast=True, room="UI_2")
|
||||||
socketio.emit("var_changed", {"classname": "actions", "name": "Selected Text Length", "old_value": None, "value": {"id": i, 'length': value.actions[i]['Selected Text Length']}}, include_self=True, broadcast=True, room="UI_2")
|
socketio.emit("var_changed", {"classname": "actions", "name": "Selected Text Length", "old_value": None, "value": {"id": i, 'length': value.actions[i]['Selected Text Length']}}, include_self=True, broadcast=True, room="UI_2")
|
||||||
|
elif isinstance(value, KoboldWorldInfo):
|
||||||
|
for item in value.to_json():
|
||||||
|
for name in item:
|
||||||
|
process_variable_changes(socketio, "world_info", "{}_{}".format(name, item['uid']), item[name], None)
|
||||||
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():
|
||||||
@@ -139,6 +145,8 @@ class settings(object):
|
|||||||
def to_base64(data):
|
def to_base64(data):
|
||||||
if isinstance(data, KoboldStoryRegister):
|
if isinstance(data, KoboldStoryRegister):
|
||||||
return data.to_json()
|
return data.to_json()
|
||||||
|
elif isinstance(data, KoboldWorldInfo):
|
||||||
|
return data.to_json()
|
||||||
output = BytesIO()
|
output = BytesIO()
|
||||||
pickle.dump(data, output)
|
pickle.dump(data, output)
|
||||||
output.seek(0)
|
output.seek(0)
|
||||||
@@ -164,8 +172,10 @@ class settings(object):
|
|||||||
value = bool(value)
|
value = bool(value)
|
||||||
elif type(getattr(self, key)) == str:
|
elif type(getattr(self, key)) == str:
|
||||||
value = str(value)
|
value = str(value)
|
||||||
if isinstance(getattr(self, key), KoboldStoryRegister):
|
elif isinstance(getattr(self, key), KoboldStoryRegister):
|
||||||
self.actions.load_json(value)
|
self.actions.load_json(value)
|
||||||
|
elif isinstance(getattr(self, key), KoboldWorldInfo):
|
||||||
|
self.world_info.load_json(value)
|
||||||
else:
|
else:
|
||||||
setattr(self, key, value)
|
setattr(self, key, value)
|
||||||
|
|
||||||
@@ -286,6 +296,7 @@ class story_settings(settings):
|
|||||||
# Selected Text: (text the user had selected. None when this is a newly generated action)
|
# Selected Text: (text the user had selected. None when this is a newly generated action)
|
||||||
# Alternative Generated Text: {Text, Pinned, Previous Selection, Edited}
|
# Alternative Generated Text: {Text, Pinned, Previous Selection, Edited}
|
||||||
#
|
#
|
||||||
|
self.worldinfo_v2 = KoboldWorldInfo(socketio)
|
||||||
self.worldinfo = [] # List of World Info key/value objects
|
self.worldinfo = [] # List of World Info key/value objects
|
||||||
self.worldinfo_i = [] # List of World Info key/value objects sans uninitialized entries
|
self.worldinfo_i = [] # List of World Info key/value objects sans uninitialized entries
|
||||||
self.worldinfo_u = {} # Dictionary of World Info UID - key/value pairs
|
self.worldinfo_u = {} # Dictionary of World Info UID - key/value pairs
|
||||||
@@ -316,6 +327,11 @@ class story_settings(settings):
|
|||||||
|
|
||||||
def __setattr__(self, name, value):
|
def __setattr__(self, name, value):
|
||||||
new_variable = name not in self.__dict__
|
new_variable = name not in self.__dict__
|
||||||
|
if name == 'worldinfo_v2' and not new_variable:
|
||||||
|
super().__setattr__('worldinfo', KoboldWorldInfo(self.socketio))
|
||||||
|
for i in range(len(value)):
|
||||||
|
self.worldinfo[i] = value[i]
|
||||||
|
else:
|
||||||
old_value = getattr(self, name, None)
|
old_value = getattr(self, name, None)
|
||||||
super().__setattr__(name, value)
|
super().__setattr__(name, value)
|
||||||
#Put variable change actions here
|
#Put variable change actions here
|
||||||
@@ -326,7 +342,8 @@ class story_settings(settings):
|
|||||||
if not new_variable and old_value != value:
|
if not new_variable and old_value != value:
|
||||||
if name == 'actions':
|
if name == 'actions':
|
||||||
self.actions.story_settings = self
|
self.actions.story_settings = self
|
||||||
if self.tokenizer is not None:
|
#Recalc token length
|
||||||
|
if name in ['authornote', 'memory' ,'prompt', 'tokenizer'] and self.tokenizer is not None:
|
||||||
if name == 'tokenizer' and not new_variable:
|
if name == 'tokenizer' and not new_variable:
|
||||||
self.memory_length = len(self.tokenizer.encode(self.memory))
|
self.memory_length = len(self.tokenizer.encode(self.memory))
|
||||||
self.prompt_length = len(self.tokenizer.encode(self.prompt))
|
self.prompt_length = len(self.tokenizer.encode(self.prompt))
|
||||||
@@ -360,7 +377,6 @@ class story_settings(settings):
|
|||||||
elif name == 'chatmode' and value == False and self.adventure == False:
|
elif name == 'chatmode' and value == False and self.adventure == False:
|
||||||
self.actionmode = 0
|
self.actionmode = 0
|
||||||
|
|
||||||
|
|
||||||
class user_settings(settings):
|
class user_settings(settings):
|
||||||
local_only_variables = ['socketio']
|
local_only_variables = ['socketio']
|
||||||
no_save_variables = ['socketio']
|
no_save_variables = ['socketio']
|
||||||
@@ -460,7 +476,7 @@ class system_settings(settings):
|
|||||||
class KoboldStoryRegister(object):
|
class KoboldStoryRegister(object):
|
||||||
def __init__(self, socketio, tokenizer=None, sequence=[]):
|
def __init__(self, socketio, tokenizer=None, sequence=[]):
|
||||||
self.socketio = socketio
|
self.socketio = socketio
|
||||||
self.actions = {} #keys = "Selected Text", "Options", "Selected Text Length"
|
self.actions = {} #keys = "Selected Text", "Options", "Selected Text Length" with options being a dict with keys of "text", "Pinned", "Previous Selection", "Edited"
|
||||||
self.action_count = -1
|
self.action_count = -1
|
||||||
self.tokenizer = tokenizer
|
self.tokenizer = tokenizer
|
||||||
for item in sequence:
|
for item in sequence:
|
||||||
@@ -521,6 +537,12 @@ class KoboldStoryRegister(object):
|
|||||||
def values(self):
|
def values(self):
|
||||||
return [self.actions[k]["Selected Text"] for k in self.actions]
|
return [self.actions[k]["Selected Text"] for k in self.actions]
|
||||||
|
|
||||||
|
def options(self, ui_version=2):
|
||||||
|
if ui_version == 1:
|
||||||
|
return [{"Selected Text": self.actions[k]["Selected Text"], "Alternative Text": self.actions[k]["Options"]} for k in self.actions]
|
||||||
|
else:
|
||||||
|
return [self.actions[k]["Options"] for k in self.actions]
|
||||||
|
|
||||||
def to_json(self):
|
def to_json(self):
|
||||||
return {"action_count": self.action_count, "actions": self.actions}
|
return {"action_count": self.action_count, "actions": self.actions}
|
||||||
|
|
||||||
@@ -589,6 +611,12 @@ class KoboldStoryRegister(object):
|
|||||||
process_variable_changes(self.socketio, "actions", "Options", {"id": self.action_count+1, "options": self.actions[self.action_count+1]["Options"]}, {"id": self.action_count+1, "options": old_options})
|
process_variable_changes(self.socketio, "actions", "Options", {"id": self.action_count+1, "options": self.actions[self.action_count+1]["Options"]}, {"id": self.action_count+1, "options": old_options})
|
||||||
self.set_game_saved()
|
self.set_game_saved()
|
||||||
|
|
||||||
|
def set_options(self, option_list, action_id):
|
||||||
|
if action_id not in self.actions:
|
||||||
|
self.action_id[action_id] = {"Selected Text": "", "Options": option_list}
|
||||||
|
else:
|
||||||
|
self.action_id[action_id]['Options'] = option_list
|
||||||
|
|
||||||
def clear_unused_options(self, pointer=None):
|
def clear_unused_options(self, pointer=None):
|
||||||
new_options = []
|
new_options = []
|
||||||
old_options = None
|
old_options = None
|
||||||
@@ -779,6 +807,124 @@ class KoboldStoryRegister(object):
|
|||||||
#We set the tokenizer, recalculate all of the item lengths
|
#We set the tokenizer, recalculate all of the item lengths
|
||||||
self.recalc_token_length()
|
self.recalc_token_length()
|
||||||
|
|
||||||
|
class KoboldWorldInfoEntry(object):
|
||||||
|
#if we call info with a [x] get the world info data for x
|
||||||
|
def __init__(self, socketio, uid):
|
||||||
|
self._socketio = socketio
|
||||||
|
self.uid = uid
|
||||||
|
self.folder = "root"
|
||||||
|
|
||||||
|
def __getitem__(self, i):
|
||||||
|
return getattr(self, i)
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
return {name: value for (name, value) in vars(self).items() if name[0] != "_"}
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return str(self.to_dict())
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return str(self.to_dict())
|
||||||
|
|
||||||
|
#allow for setting the entire world info to a dictionary of values
|
||||||
|
def __setitem__(self, i, data):
|
||||||
|
setattr(self, i, data)
|
||||||
|
|
||||||
|
def __setattr__(self, name, value):
|
||||||
|
new_variable = name not in self.__dict__
|
||||||
|
old_value = getattr(self, name, None)
|
||||||
|
super().__setattr__(name, value)
|
||||||
|
#Put variable change actions here
|
||||||
|
if name[0] != "_":
|
||||||
|
process_variable_changes(self._socketio, "world_info", "{}_{}".format(name, self.uid), value, old_value)
|
||||||
|
|
||||||
|
class KoboldWorldInfo(object):
|
||||||
|
|
||||||
|
def __init__(self, socketio):
|
||||||
|
self.world_info = {}
|
||||||
|
self._socketio = socketio
|
||||||
|
self.maxuid = 0
|
||||||
|
|
||||||
|
def reset(self):
|
||||||
|
self.__init__(self._socketio)
|
||||||
|
|
||||||
|
#if we call info with a [x] get the world info data for x as a dictionary
|
||||||
|
def __getitem__(self, i):
|
||||||
|
return self.world_info[i].to_dict()
|
||||||
|
|
||||||
|
#allow for setting the entire world info to a dictionary of values
|
||||||
|
def __setitem__(self, i, data):
|
||||||
|
print("setting {} to {}".format(i, data))
|
||||||
|
if i not in self.world_info:
|
||||||
|
i = self.append(data)
|
||||||
|
for key in data:
|
||||||
|
self.world_info[i][key] = data[key]
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
return len(self.world_info)
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
self._itter = -1
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __next__(self):
|
||||||
|
self._itter += 1
|
||||||
|
if self._itter < len(self.world_info):
|
||||||
|
return {x: self.world_info[self._itter].__dict__[x] for x in self.world_info[self._itter].__dict__ if x[0] != "_"}
|
||||||
|
else:
|
||||||
|
raise StopIteration
|
||||||
|
|
||||||
|
def get_folders(self, ui_version=2):
|
||||||
|
if ui_version == 1:
|
||||||
|
return {i: {'collapsed': True, 'name': x} for i, x in enumerate(set([x['folder'] for x in self.world_info]))}
|
||||||
|
return list(set([x['folder'] for x in self.world_info]))
|
||||||
|
|
||||||
|
def get_folder_items(self, folder):
|
||||||
|
items = [item.to_dict() for item in self.world_info if item['folder'] == folder]
|
||||||
|
return sorted(items, key=lambda d: d['sort_order'])
|
||||||
|
|
||||||
|
def reorder(self, uid, after_uid):
|
||||||
|
if uid not in self.world_info or after_uid not in self.world_info:
|
||||||
|
return
|
||||||
|
folder = self.world_info[uid]['folder']
|
||||||
|
after_sort_number = self.world_info[after_uid]['sort']
|
||||||
|
for item in world_info:
|
||||||
|
if item['folder'] == folder and item['sort'] > after_sort_number:
|
||||||
|
item['sort'] = item['sort']+1
|
||||||
|
self.world_info[uid]['sort'] = after_sort_number+1
|
||||||
|
|
||||||
|
def set_folder(self, uid, folder, after_uid=None):
|
||||||
|
max_sort = max([x['sort'] for x in self.world_info if x['folder'] == folder])
|
||||||
|
old_folder = self.world_info[uid]['folder']
|
||||||
|
self.world_info[uid]['folder'] = folder
|
||||||
|
self.world_info[uid]['sort'] = max_sort
|
||||||
|
if after_uid is not None:
|
||||||
|
self.reorder(folder, uid, after_uid)
|
||||||
|
self.resort(folder)
|
||||||
|
self.resort(old_folder)
|
||||||
|
|
||||||
|
def resort(self, folder):
|
||||||
|
for i in range(max([x['sort'] for x in self.world_info if x['folder'] == folder])+1):
|
||||||
|
if i > len([x['sort'] for x in self.world_info if x['folder'] == folder]):
|
||||||
|
break
|
||||||
|
elif i not in [x['sort'] for x in self.world_info if x['folder'] == folder]:
|
||||||
|
for item in world_info:
|
||||||
|
if item['folder'] == folder and item['sort'] > i:
|
||||||
|
item['sort'] = item['sort']-1
|
||||||
|
|
||||||
|
def append(self, data):
|
||||||
|
uid = self.maxuid+1
|
||||||
|
self.maxuid += 1
|
||||||
|
self.world_info[uid] = KoboldWorldInfoEntry(self._socketio, uid)
|
||||||
|
for key in data:
|
||||||
|
self.world_info[uid][key] = data[key]
|
||||||
|
return uid
|
||||||
|
|
||||||
|
def to_json(self):
|
||||||
|
return [self.world_info[x].to_dict() for x in self.world_info]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
badwordsids_default = [[13460], [6880], [50256], [42496], [4613], [17414], [22039], [16410], [27], [29], [38430], [37922], [15913], [24618], [28725], [58], [47175], [36937], [26700], [12878], [16471], [37981], [5218], [29795], [13412], [45160], [3693], [49778], [4211], [20598], [36475], [33409], [44167], [32406], [29847], [29342], [42669], [685], [25787], [7359], [3784], [5320], [33994], [33490], [34516], [43734], [17635], [24293], [9959], [23785], [21737], [28401], [18161], [26358], [32509], [1279], [38155], [18189], [26894], [6927], [14610], [23834], [11037], [14631], [26933], [46904], [22330], [25915], [47934], [38214], [1875], [14692], [41832], [13163], [25970], [29565], [44926], [19841], [37250], [49029], [9609], [44438], [16791], [17816], [30109], [41888], [47527], [42924], [23984], [49074], [33717], [31161], [49082], [30138], [31175], [12240], [14804], [7131], [26076], [33250], [3556], [38381], [36338], [32756], [46581], [17912], [49146]] # Tokenized array of badwords used to prevent AI artifacting
|
badwordsids_default = [[13460], [6880], [50256], [42496], [4613], [17414], [22039], [16410], [27], [29], [38430], [37922], [15913], [24618], [28725], [58], [47175], [36937], [26700], [12878], [16471], [37981], [5218], [29795], [13412], [45160], [3693], [49778], [4211], [20598], [36475], [33409], [44167], [32406], [29847], [29342], [42669], [685], [25787], [7359], [3784], [5320], [33994], [33490], [34516], [43734], [17635], [24293], [9959], [23785], [21737], [28401], [18161], [26358], [32509], [1279], [38155], [18189], [26894], [6927], [14610], [23834], [11037], [14631], [26933], [46904], [22330], [25915], [47934], [38214], [1875], [14692], [41832], [13163], [25970], [29565], [44926], [19841], [37250], [49029], [9609], [44438], [16791], [17816], [30109], [41888], [47527], [42924], [23984], [49074], [33717], [31161], [49082], [30138], [31175], [12240], [14804], [7131], [26076], [33250], [3556], [38381], [36338], [32756], [46581], [17912], [49146]] # Tokenized array of badwords used to prevent AI artifacting
|
||||||
badwordsids_neox = [[0], [1], [44162], [9502], [12520], [31841], [36320], [49824], [34417], [6038], [34494], [24815], [26635], [24345], [3455], [28905], [44270], [17278], [32666], [46880], [7086], [43189], [37322], [17778], [20879], [49821], [3138], [14490], [4681], [21391], [26786], [43134], [9336], [683], [48074], [41256], [19181], [29650], [28532], [36487], [45114], [46275], [16445], [15104], [11337], [1168], [5647], [29], [27482], [44965], [43782], [31011], [42944], [47389], [6334], [17548], [38329], [32044], [35487], [2239], [34761], [7444], [1084], [12399], [18990], [17636], [39083], [1184], [35830], [28365], [16731], [43467], [47744], [1138], [16079], [40116], [45564], [18297], [42368], [5456], [18022], [42696], [34476], [23505], [23741], [39334], [37944], [45382], [38709], [33440], [26077], [43600], [34418], [36033], [6660], [48167], [48471], [15775], [19884], [41533], [1008], [31053], [36692], [46576], [20095], [20629], [31759], [46410], [41000], [13488], [30952], [39258], [16160], [27655], [22367], [42767], [43736], [49694], [13811], [12004], [46768], [6257], [37471], [5264], [44153], [33805], [20977], [21083], [25416], [14277], [31096], [42041], [18331], [33376], [22372], [46294], [28379], [38475], [1656], [5204], [27075], [50001], [16616], [11396], [7748], [48744], [35402], [28120], [41512], [4207], [43144], [14767], [15640], [16595], [41305], [44479], [38958], [18474], [22734], [30522], [46267], [60], [13976], [31830], [48701], [39822], [9014], [21966], [31422], [28052], [34607], [2479], [3851], [32214], [44082], [45507], [3001], [34368], [34758], [13380], [38363], [4299], [46802], [30996], [12630], [49236], [7082], [8795], [5218], [44740], [9686], [9983], [45301], [27114], [40125], [1570], [26997], [544], [5290], [49193], [23781], [14193], [40000], [2947], [43781], [9102], [48064], [42274], [18772], [49384], [9884], [45635], [43521], [31258], [32056], [47686], [21760], [13143], [10148], [26119], [44308], [31379], [36399], [23983], [46694], [36134], [8562], [12977], [35117], [28591], [49021], [47093], [28653], [29013], [46468], [8605], [7254], [25896], [5032], [8168], [36893], [38270], [20499], [27501], [34419], [29547], [28571], [36586], [20871], [30537], [26842], [21375], [31148], [27618], [33094], [3291], [31789], [28391], [870], [9793], [41361], [47916], [27468], [43856], [8850], [35237], [15707], [47552], [2730], [41449], [45488], [3073], [49806], [21938], [24430], [22747], [20924], [46145], [20481], [20197], [8239], [28231], [17987], [42804], [47269], [29972], [49884], [21382], [46295], [36676], [34616], [3921], [26991], [27720], [46265], [654], [9855], [40354], [5291], [34904], [44342], [2470], [14598], [880], [19282], [2498], [24237], [21431], [16369], [8994], [44524], [45662], [13663], [37077], [1447], [37786], [30863], [42854], [1019], [20322], [4398], [12159], [44072], [48664], [31547], [18736], [9259], [31], [16354], [21810], [4357], [37982], [5064], [2033], [32871], [47446], [62], [22158], [37387], [8743], [47007], [17981], [11049], [4622], [37916], [36786], [35138], [29925], [14157], [18095], [27829], [1181], [22226], [5709], [4725], [30189], [37014], [1254], [11380], [42989], [696], [24576], [39487], [30119], [1092], [8088], [2194], [9899], [14412], [21828], [3725], [13544], [5180], [44679], [34398], [3891], [28739], [14219], [37594], [49550], [11326], [6904], [17266], [5749], [10174], [23405], [9955], [38271], [41018], [13011], [48392], [36784], [24254], [21687], [23734], [5413], [41447], [45472], [10122], [17555], [15830], [47384], [12084], [31350], [47940], [11661], [27988], [45443], [905], [49651], [16614], [34993], [6781], [30803], [35869], [8001], [41604], [28118], [46462], [46762], [16262], [17281], [5774], [10943], [5013], [18257], [6750], [4713], [3951], [11899], [38791], [16943], [37596], [9318], [18413], [40473], [13208], [16375]]
|
badwordsids_neox = [[0], [1], [44162], [9502], [12520], [31841], [36320], [49824], [34417], [6038], [34494], [24815], [26635], [24345], [3455], [28905], [44270], [17278], [32666], [46880], [7086], [43189], [37322], [17778], [20879], [49821], [3138], [14490], [4681], [21391], [26786], [43134], [9336], [683], [48074], [41256], [19181], [29650], [28532], [36487], [45114], [46275], [16445], [15104], [11337], [1168], [5647], [29], [27482], [44965], [43782], [31011], [42944], [47389], [6334], [17548], [38329], [32044], [35487], [2239], [34761], [7444], [1084], [12399], [18990], [17636], [39083], [1184], [35830], [28365], [16731], [43467], [47744], [1138], [16079], [40116], [45564], [18297], [42368], [5456], [18022], [42696], [34476], [23505], [23741], [39334], [37944], [45382], [38709], [33440], [26077], [43600], [34418], [36033], [6660], [48167], [48471], [15775], [19884], [41533], [1008], [31053], [36692], [46576], [20095], [20629], [31759], [46410], [41000], [13488], [30952], [39258], [16160], [27655], [22367], [42767], [43736], [49694], [13811], [12004], [46768], [6257], [37471], [5264], [44153], [33805], [20977], [21083], [25416], [14277], [31096], [42041], [18331], [33376], [22372], [46294], [28379], [38475], [1656], [5204], [27075], [50001], [16616], [11396], [7748], [48744], [35402], [28120], [41512], [4207], [43144], [14767], [15640], [16595], [41305], [44479], [38958], [18474], [22734], [30522], [46267], [60], [13976], [31830], [48701], [39822], [9014], [21966], [31422], [28052], [34607], [2479], [3851], [32214], [44082], [45507], [3001], [34368], [34758], [13380], [38363], [4299], [46802], [30996], [12630], [49236], [7082], [8795], [5218], [44740], [9686], [9983], [45301], [27114], [40125], [1570], [26997], [544], [5290], [49193], [23781], [14193], [40000], [2947], [43781], [9102], [48064], [42274], [18772], [49384], [9884], [45635], [43521], [31258], [32056], [47686], [21760], [13143], [10148], [26119], [44308], [31379], [36399], [23983], [46694], [36134], [8562], [12977], [35117], [28591], [49021], [47093], [28653], [29013], [46468], [8605], [7254], [25896], [5032], [8168], [36893], [38270], [20499], [27501], [34419], [29547], [28571], [36586], [20871], [30537], [26842], [21375], [31148], [27618], [33094], [3291], [31789], [28391], [870], [9793], [41361], [47916], [27468], [43856], [8850], [35237], [15707], [47552], [2730], [41449], [45488], [3073], [49806], [21938], [24430], [22747], [20924], [46145], [20481], [20197], [8239], [28231], [17987], [42804], [47269], [29972], [49884], [21382], [46295], [36676], [34616], [3921], [26991], [27720], [46265], [654], [9855], [40354], [5291], [34904], [44342], [2470], [14598], [880], [19282], [2498], [24237], [21431], [16369], [8994], [44524], [45662], [13663], [37077], [1447], [37786], [30863], [42854], [1019], [20322], [4398], [12159], [44072], [48664], [31547], [18736], [9259], [31], [16354], [21810], [4357], [37982], [5064], [2033], [32871], [47446], [62], [22158], [37387], [8743], [47007], [17981], [11049], [4622], [37916], [36786], [35138], [29925], [14157], [18095], [27829], [1181], [22226], [5709], [4725], [30189], [37014], [1254], [11380], [42989], [696], [24576], [39487], [30119], [1092], [8088], [2194], [9899], [14412], [21828], [3725], [13544], [5180], [44679], [34398], [3891], [28739], [14219], [37594], [49550], [11326], [6904], [17266], [5749], [10174], [23405], [9955], [38271], [41018], [13011], [48392], [36784], [24254], [21687], [23734], [5413], [41447], [45472], [10122], [17555], [15830], [47384], [12084], [31350], [47940], [11661], [27988], [45443], [905], [49651], [16614], [34993], [6781], [30803], [35869], [8001], [41604], [28118], [46462], [46762], [16262], [17281], [5774], [10943], [5013], [18257], [6750], [4713], [3951], [11899], [38791], [16943], [37596], [9318], [18413], [40473], [13208], [16375]]
|
||||||
badwordsids_opt = [[44717], [46613], [48513], [49923], [50185], [48755], [8488], [43303], [49659], [48601], [49817], [45405], [48742], [49925], [47720], [11227], [48937], [48784], [50017], [42248], [49310], [48082], [49895], [50025], [49092], [49007], [8061], [44226], [0], [742], [28578], [15698], [49784], [46679], [39365], [49281], [49609], [48081], [48906], [46161], [48554], [49670], [48677], [49721], [49632], [48610], [48462], [47457], [10975], [46077], [28696], [48709], [43839], [49798], [49154], [48203], [49625], [48395], [50155], [47161], [49095], [48833], [49420], [49666], [48443], [22176], [49242], [48651], [49138], [49750], [40389], [48021], [21838], [49070], [45333], [40862], [1], [49915], [33525], [49858], [50254], [44403], [48992], [48872], [46117], [49853], [47567], [50206], [41552], [50068], [48999], [49703], [49940], [49329], [47620], [49868], [49962], [2], [44082], [50236], [31274], [50260], [47052], [42645], [49177], [17523], [48691], [49900], [49069], [49358], [48794], [47529], [46479], [48457], [646], [49910], [48077], [48935], [46386], [48902], [49151], [48759], [49803], [45587], [48392], [47789], [48654], [49836], [49230], [48188], [50264], [46844], [44690], [48505], [50161], [27779], [49995], [41833], [50154], [49097], [48520], [50018], [8174], [50084], [49366], [49526], [50193], [7479], [49982], [3]]
|
badwordsids_opt = [[44717], [46613], [48513], [49923], [50185], [48755], [8488], [43303], [49659], [48601], [49817], [45405], [48742], [49925], [47720], [11227], [48937], [48784], [50017], [42248], [49310], [48082], [49895], [50025], [49092], [49007], [8061], [44226], [0], [742], [28578], [15698], [49784], [46679], [39365], [49281], [49609], [48081], [48906], [46161], [48554], [49670], [48677], [49721], [49632], [48610], [48462], [47457], [10975], [46077], [28696], [48709], [43839], [49798], [49154], [48203], [49625], [48395], [50155], [47161], [49095], [48833], [49420], [49666], [48443], [22176], [49242], [48651], [49138], [49750], [40389], [48021], [21838], [49070], [45333], [40862], [1], [49915], [33525], [49858], [50254], [44403], [48992], [48872], [46117], [49853], [47567], [50206], [41552], [50068], [48999], [49703], [49940], [49329], [47620], [49868], [49962], [2], [44082], [50236], [31274], [50260], [47052], [42645], [49177], [17523], [48691], [49900], [49069], [49358], [48794], [47529], [46479], [48457], [646], [49910], [48077], [48935], [46386], [48902], [49151], [48759], [49803], [45587], [48392], [47789], [48654], [49836], [49230], [48188], [50264], [46844], [44690], [48505], [50161], [27779], [49995], [41833], [50154], [49097], [48520], [50018], [8174], [50084], [49366], [49526], [50193], [7479], [49982], [3]]
|
@@ -300,6 +300,9 @@ function var_changed(data) {
|
|||||||
do_presets(data);
|
do_presets(data);
|
||||||
} else if ((data.classname == "model") && (data.name == "selected_preset")) {
|
} else if ((data.classname == "model") && (data.name == "selected_preset")) {
|
||||||
selected_preset(data);
|
selected_preset(data);
|
||||||
|
//Special Case for World Info
|
||||||
|
} else if (data.classname == 'world_info') {
|
||||||
|
world_info(data);
|
||||||
//Basic Data Syncing
|
//Basic Data Syncing
|
||||||
} else {
|
} else {
|
||||||
var elements_to_change = document.getElementsByClassName("var_sync_"+data.classname.replace(" ", "_")+"_"+data.name.replace(" ", "_"));
|
var elements_to_change = document.getElementsByClassName("var_sync_"+data.classname.replace(" ", "_")+"_"+data.name.replace(" ", "_"));
|
||||||
@@ -921,6 +924,46 @@ function buildload(data) {
|
|||||||
console.log(data);
|
console.log(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function world_info(data) {
|
||||||
|
var world_info_area = document.getElementById("story_menu_wi");
|
||||||
|
var wiid = data.name.split("_")[data.name.split("_").length-1];
|
||||||
|
var name = data.name.split("_").slice(0, data.name.split("_").length-1).join('_');
|
||||||
|
//first check to see if we have the world info id already
|
||||||
|
if (document.getElementById("world_info_"+wiid)) {
|
||||||
|
table = document.getElementById("world_info_"+wiid);
|
||||||
|
if (document.getElementById("world_info_"+wiid+"_"+name)) {
|
||||||
|
tr = document.getElementById("world_info_"+wiid+"_"+name);
|
||||||
|
tr.lastChild.textContent = data.value
|
||||||
|
} else {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------UI to Server Functions----------------------------------
|
//--------------------------------------------UI to Server Functions----------------------------------
|
||||||
function sync_to_server(item) {
|
function sync_to_server(item) {
|
||||||
//get value
|
//get value
|
||||||
|
12
utils.py
12
utils.py
@@ -169,6 +169,16 @@ def num_layers(config):
|
|||||||
#==================================================================#
|
#==================================================================#
|
||||||
# Downloads huggingface checkpoints using aria2c if possible
|
# Downloads huggingface checkpoints using aria2c if possible
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
|
from flask_socketio import emit
|
||||||
|
class Send_to_socketio(object):
|
||||||
|
def write(self, bar):
|
||||||
|
print("should be emitting: ", bar, end="")
|
||||||
|
time.sleep(0.01)
|
||||||
|
try:
|
||||||
|
emit('from_server', {'cmd': 'model_load_status', 'data': bar.replace(" ", " ")}, broadcast=True, room="UI_1")
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
def aria2_hook(pretrained_model_name_or_path: str, force_download=False, cache_dir=None, proxies=None, resume_download=False, local_files_only=False, use_auth_token=None, user_agent=None, revision=None, mirror=None, **kwargs):
|
def aria2_hook(pretrained_model_name_or_path: str, force_download=False, cache_dir=None, proxies=None, resume_download=False, local_files_only=False, use_auth_token=None, user_agent=None, revision=None, mirror=None, **kwargs):
|
||||||
import transformers
|
import transformers
|
||||||
import transformers.modeling_utils
|
import transformers.modeling_utils
|
||||||
@@ -265,7 +275,7 @@ def aria2_hook(pretrained_model_name_or_path: str, force_download=False, cache_d
|
|||||||
done = True
|
done = True
|
||||||
break
|
break
|
||||||
if bar is None:
|
if bar is None:
|
||||||
bar = tqdm(total=total_length, desc=f"[aria2] Downloading model", unit="B", unit_scale=True, unit_divisor=1000)
|
bar = tqdm(total=total_length, desc=f"[aria2] Downloading model", unit="B", unit_scale=True, unit_divisor=1000, file=Send_to_socketio())
|
||||||
visited = set()
|
visited = set()
|
||||||
for x in r:
|
for x in r:
|
||||||
filename = x["files"][0]["path"]
|
filename = x["files"][0]["path"]
|
||||||
|
Reference in New Issue
Block a user