Merge branch 'UI2' of https://github.com/ebolam/KoboldAI into ui2-etc

This commit is contained in:
somebody
2022-09-07 16:08:21 -05:00
15 changed files with 3999 additions and 190 deletions

View File

@@ -259,7 +259,7 @@ app.config['SESSION_TYPE'] = 'filesystem'
app.config['TEMPLATES_AUTO_RELOAD'] = True
Session(app)
socketio = SocketIO(app, async_method="eventlet", manage_session=False, cors_allowed_origins='*')
#socketio = SocketIO(app, async_method="eventlet", logger=True, engineio_logger=True, manage_session=False)
#socketio = SocketIO(app, async_method="eventlet", manage_session=False, cors_allowed_origins='*', logger=True, engineio_logger=True)
koboldai_vars = koboldai_settings.koboldai_vars(session, socketio)
utils.koboldai_vars = koboldai_vars
@@ -6771,7 +6771,7 @@ def new_ui_index():
def ui2_connect():
#Send all variables to client
koboldai_vars.send_to_ui()
UI_2_load_tweaks()
pass
#==================================================================#
@@ -7172,7 +7172,7 @@ def UI_2_submit(data):
koboldai_vars.lua_koboldbridge.feedback = None
koboldai_vars.recentrng = koboldai_vars.recentrngm = None
if koboldai_vars.actions.action_count == -1:
actionsubmit(data['data'], actionmode=0)
actionsubmit(data['data'], actionmode=koboldai_vars.actionmode)
else:
actionsubmit(data['data'], actionmode=koboldai_vars.actionmode)
@@ -7293,7 +7293,7 @@ def UI_2_load_story_list(data):
deleteable=True, show_breadcrumbs=True, item_check=valid_story,
valid_only=True, hide_extention=True, extra_parameter_function=get_story_listing_data,
column_names=['Story Name', 'Action Count', 'Last Loaded'], show_filename=False,
column_widths=['auto', '150px', '150px'], advanced_sort=story_sort,
column_widths=['minmax(150px, auto)', '150px', '150px'], advanced_sort=story_sort,
sort="Modified", desc=True)
def get_story_listing_data(item_full_path, item, valid_selection):
@@ -7684,6 +7684,23 @@ def UI_2_sp_list_refresh(data):
def UI_2_theme_list_refresh(data):
koboldai_vars.theme_list = [".".join(f.split(".")[:-1]) for f in os.listdir("./themes") if os.path.isfile(os.path.join("./themes", f))]
#==================================================================#
# Save Tweaks
#==================================================================#
@socketio.on('save_tweaks')
def UI_2_save_tweaks(data):
with open("./settings/tweaks.settings", "w") as f:
f.write(data)
#==================================================================#
# Load Tweaks
#==================================================================#
def UI_2_load_tweaks():
if koboldai_vars.on_colab:
if os.path.exists("./settings/tweaks.settings"):
with open("./settings/tweaks.settings", "r") as f:
socketio.emit('load_tweaks', f.read(), room="UI2")
#==================================================================#
# Test
#==================================================================#

View File

@@ -345,13 +345,13 @@ gensettingstf = [
"uitype": "dropdown",
"unit": "text",
"label": "Story Mode",
"id": "actionmode",
"id": "storymode",
"default": 0,
"tooltip": "Choose the mode of KoboldAI.",
"menu_path": "Home",
"sub_path": "",
"classname": "story",
"name": "actionmode",
"name": "storymode",
'children': [{'text': 'Story', 'value': 0}, {'text':'Adventure','value':1}, {'text':'Chat', 'value':2}]
},
{

View File

@@ -85,12 +85,11 @@ class koboldai_vars(object):
#If we can figure out a way to get flask sessions into/through the lua bridge we could re-enable
story_name = 'default'
if story_name in self._story_settings:
self._story_settings[story_name].reset()
else:
self._story_settings[story_name] = story_settings(self.socketio)
if json_data is not None:
self._story_settings[story_name].from_json(json_data)
self.load_story(sotry_name, json_data)
self._story_settings['default'].send_to_ui()
def story_list(self):
@@ -431,7 +430,7 @@ class model_settings(settings):
self.badwordsids = []
self.fp32_model = False # Whether or not the most recently loaded HF model was in fp32 format
self.modeldim = -1 # Embedding dimension of your model (e.g. it's 4096 for GPT-J-6B and 2560 for GPT-Neo-2.7B)
self.sampler_order = [0, 1, 2, 3, 4, 5]
self.sampler_order = [6, 0, 1, 2, 3, 4, 5]
self.newlinemode = "n"
self.lazy_load = True # Whether or not to use torch_lazy_loader.py for transformers models in order to reduce CPU memory usage
self.revision = None
@@ -517,7 +516,6 @@ class story_settings(settings):
self.gamestarted = False # Whether the game has started (disables UI elements)
self.gamesaved = True # Whether or not current game is saved
self.autosave = False # Whether or not to automatically save after each action
self.no_save = False #Temporary disable save (doesn't save with the file)
self.prompt = "" # Prompt
self.memory = "" # Text submitted to memory field
self.authornote = "" # Text submitted to Author's Note field
@@ -552,6 +550,7 @@ class story_settings(settings):
self.chatname = "You"
self.adventure = False
self.actionmode = 0
self.storymode = 0
self.dynamicscan = False
self.recentedit = False
self.notes = "" #Notes for the story. Does nothing but save
@@ -567,6 +566,9 @@ class story_settings(settings):
self.context = []
self.last_story_load = None
#must be at bottom
self.no_save = False #Temporary disable save (doesn't save with the file)
def save_story(self):
if not self.no_save:
if self.prompt != "" or self.memory != "" or self.authornote != "" or len(self.actions) > 0 or len(self.worldinfo_v2) > 0:
@@ -591,8 +593,10 @@ class story_settings(settings):
self.gamesaved = True
def reset(self):
self.no_save = True
self.socketio.emit("reset_story", {}, broadcast=True, room="UI_2")
self.__init__(self.socketio, self.koboldai_vars, tokenizer=self.tokenizer)
self.no_save = False
def __setattr__(self, name, value):
new_variable = name not in self.__dict__
@@ -638,7 +642,7 @@ class story_settings(settings):
ignore = self.koboldai_vars.calc_ai_text()
#Because we have seperate variables for action types, this syncs them
elif name == 'actionmode':
elif name == 'storymode':
if value == 0:
self.adventure = False
self.chatmode = False
@@ -650,14 +654,14 @@ class story_settings(settings):
self.chatmode = True
elif name == 'adventure' and value == True:
self.chatmode = False
self.actionmode = 1
self.storymode = 1
elif name == 'adventure' and value == False and self.chatmode == False:
self.actionmode = 0
self.storymode = 0
elif name == 'chatmode' and value == True:
self.adventure = False
self.actionmode = 2
self.storymode = 2
elif name == 'chatmode' and value == False and self.adventure == False:
self.actionmode = 0
self.storymode = 0
class user_settings(settings):
local_only_variables = ['socketio', 'importjs']
@@ -805,12 +809,10 @@ class system_settings(settings):
random.seed()
if os.path.exists('./KoboldAI-Horde/venv/scripts/python.exe'):
self._horde_pid = subprocess.Popen(['./KoboldAI-Horde/venv/scripts/python.exe', './KoboldAI-Horde/bridge.py',
'--username', '{}'.format(random.randint(-1000000000000, 1000000000000)), '--password', '{}'.format(random.randint(-1000000000000, 1000000000000)),
'--kai_name', '{}'.format(random.randint(-1000000000000, 1000000000000)), '--kai_url', 'http://127.0.0.1:{}'.format(self.port), '--cluster_url', "http://koboldai.net"])
'--kai_url', 'http://127.0.0.1:{}'.format(self.port), '--cluster_url', "http://koboldai.net"])
else:
self._horde_pid = subprocess.Popen(['./KoboldAI-Horde/venv/bin/python', './KoboldAI-Horde/bridge.py',
'--username', '{}'.format(random.randint(-1000000000000, 1000000000000)), '--password', '{}'.format(random.randint(-1000000000000, 1000000000000)),
'--kai_name', '{}'.format(random.randint(-1000000000000, 1000000000000)), '--kai_url', 'http://127.0.0.1:{}'.format(self.port), '--cluster_url', "http://koboldai.net"])
'--kai_url', 'http://127.0.0.1:{}'.format(self.port), '--cluster_url', "http://koboldai.net"])
else:
if self._horde_pid is not None:
print("kill bridge")

File diff suppressed because it is too large Load Diff

View File

@@ -98,8 +98,8 @@ input[type="range"]::-ms-fill-upper {
display: inline-block;
position: relative;
z-index: 0;
border-top-left-radius: 6px;
border-top-right-radius: 6px;
border-top-left-radius: var(--tabs_rounding);
border-top-right-radius: var(--tabs_rounding);
box-shadow: 0 3px 3px rgba(0, 0, 0, 0.4), inset 0 1px 0 #AAA;
text-shadow: 0 1px #AAA;
margin: 0 -5px;
@@ -199,6 +199,10 @@ input[type="range"]::-ms-fill-upper {
margin: 2px;
}
.chat_mode[story_chatmode="false"] {
display: none;
}
#story_menu_author .setting_container {
display: grid;
grid-template-areas: "label value"
@@ -1305,6 +1309,17 @@ body {
gap: 1px;
}
.inputrow[story_storymode="1"] {
grid-template-areas: "adventure_mode textarea statusbar statusbar statusbar"
"adventure_mode textarea submit submit submit"
"adventure_mode textarea back redo retry";
grid-template-columns: 80px auto 30px 30px 30px;
grid-template-rows: 0px 60px 40px;
gap: 1px;
}
#random_game_prompt{
display: flex;
flex-direction: column;
@@ -1319,6 +1334,16 @@ body {
border-radius: var(--radius_inputbox);
}
#adventure_mode {
grid-area: adventure_mode
}
#adventure_mode[story_storymode]:not([story_storymode="1"]) {
display: none;
}
#input_text {
grid-area: textarea;
background-color: var(--input_background);
@@ -1491,6 +1516,8 @@ body {
flex-grow: 1;
flex-shrink: 1;
flex-basis: auto;
color: var(--popup_item_color_text);
}
.popup .model_item {
@@ -2112,3 +2139,7 @@ h2 .material-icons-outlined {
padding: 3px;
}
}
.horde_trigger[model_model="ReadOnly"] {
display: none;
}

View File

@@ -25,6 +25,7 @@ socket.on("world_info_folder", function(data){world_info_folder(data);});
socket.on("delete_new_world_info_entry", function(data){document.getElementById("world_info_-1").remove();});
socket.on("delete_world_info_entry", function(data){document.getElementById("world_info_"+data).remove();});
socket.on("error", function(data){show_error_message(data);});
socket.on('load_tweaks', function(data){load_tweaks(data);});
//socket.onAny(function(event_name, data) {console.log({"event": event_name, "class": data.classname, "data": data});});
var presets = {};
@@ -127,7 +128,7 @@ function reset_story() {
world_info_folder({"root": []});
document.getElementById("story_prompt").setAttribute("world_info_uids", "");
document.getElementById('themerow').classList.remove("hidden");
document.getElementById('input_text').placeholder = "Enter Prompt Here";
document.getElementById('input_text').placeholder = "Enter Prompt Here (shift+enter for new line)";
}
function fix_text(val) {
@@ -309,14 +310,14 @@ function do_prompt(data) {
}
//if we have a prompt we need to disable the theme area, or enable it if we don't
if (data.value != "") {
document.getElementById('input_text').placeholder = "Enter text here";
document.getElementById('input_text').placeholder = "Enter text here (shift+enter for new line)";
document.getElementById('themerow').classList.add("hidden");
document.getElementById('themetext').value = "";
if (document.getElementById("Delete Me")) {
document.getElementById("Delete Me").remove();
}
} else {
document.getElementById('input_text').placeholder = "Enter Prompt Here";
document.getElementById('input_text').placeholder = "Enter Prompt Here (shift+enter for new line)";
document.getElementById('input_text').disabled = false;
document.getElementById('themerow').classList.remove("hidden");
}
@@ -510,6 +511,14 @@ function var_changed(data) {
//Special case for context viewer
} else if (data.classname == "story" && data.name == "context") {
update_context(data.value);
//special case for story_actionmode
} else if (data.classname == "story" && data.name == "actionmode") {
const button = document.getElementById('adventure_mode');
if (data.value == 1) {
button.childNodes[1].textContent = "Adventure";
} else {
button.childNodes[1].textContent = "Story";
}
//Basic Data Syncing
} else {
var elements_to_change = document.getElementsByClassName("var_sync_"+data.classname.replace(" ", "_")+"_"+data.name.replace(" ", "_"));
@@ -2007,6 +2016,29 @@ function send_world_info(uid) {
socket.emit("edit_world_info", world_info_data[uid]);
}
function load_tweaks(data) {
}
function toggle_adventure_mode(button) {
if (button.textContent == "Mode: Story") {
button.childNodes[1].textContent = "Adventure";
var actionmode = 1
} else {
button.childNodes[1].textContent = "Story";
var actionmode = 0
}
button.classList.add("pulse");
socket.emit("var_change", {"ID": "story_actionmode", "value": actionmode}, (response) => {
if ('status' in response) {
if (response['status'] == 'Saved') {
document.getElementById("adventure_mode").classList.remove("pulse");
}
}
});
}
//--------------------------------------------General UI Functions------------------------------------
function autoResize(element) {
element.style.height = 'auto';
@@ -3062,8 +3094,9 @@ function detect_enter_submit(e) {
} else {
e.cancelBubble = true;
}
document.getElementById("btnsend").onclick();
document.getElementById('input_text').value = ''
console.log("submitting");
document.getElementById("btnsubmit").onclick();
setTimeout(function() {document.getElementById('input_text').value = '';}, 1);
}
}
@@ -3356,6 +3389,9 @@ $(document).ready(function(){
}
setCookie("enabledTweaks", JSON.stringify(out));
if (document.getElementById("on_colab").textContent == "true") {
socket.emit("save_tweaks", JSON.stringify(out));
}
}

View File

@@ -19,6 +19,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<span class="hidden var_sync_system_on_colab" id="on_colab">false</span>
<!------------ Left Flyout Menu--------------------->
<div id="SideMenu" class="SideMenu pinned">
<!------------ Menu Pin --------------------->
@@ -68,13 +69,14 @@
</div>
</div>
<!------------ Input Area--------------------->
<div class="inputrow" id="inputrow_container">
<div class="inputrow var_sync_alt_story_storymode" id="inputrow_container">
<div id="random_game_prompt" class="hidden">
<input type="text" autocomplete="off" id="themetext" placeholder="Theme for Random Story" oninput='if (this.value != "") {
document.getElementById("input_text").value = "";}'/>
<span class="help_text" style="margin:0px;margin-top:5px;">The AI can create a prompt for you! Optionally type in one or more themes above, or let the AI do it's thing.</span>
</div>
<textarea autocomplete="off" row=5 id="input_text" placeholder="Enter Prompt Here" oninput='if (this.value != "") {
<button class="var_sync_alt_story_storymode action_button" id="adventure_mode" onclick="toggle_adventure_mode(this);"><span style="font-weight: bold;">Mode: </span><span>Story</span></button>
<textarea autocomplete="off" row=5 id="input_text" placeholder="Enter Prompt Here (shift+enter for new line)" oninput='if (this.value != "") {
document.getElementById("themetext").value = "";
}'
onkeyup="calc_token_usage()"></textarea>

View File

@@ -65,8 +65,8 @@
The story name you have entered already exists. Would you like to overwrite?
</div>
<div class="popup_load_cancel">
<button type="button" class="btn btn-primary" onclick='socket.emit("save_story", "overwrite"); document.getElementById("save-confirm").classList.add("hidden");'>Overwrite</button>
<button type="button" class="btn btn-primary" onclick="document.getElementById('save-confirm').classList.add('hidden');">Cancel</button>
<button type="button" class="btn btn-primary popup_load_cancel_button" onclick='socket.emit("save_story", "overwrite"); document.getElementById("save-confirm").classList.add("hidden");'>Overwrite</button>
<button type="button" class="btn btn-primary popup_load_cancel_button" onclick="document.getElementById('save-confirm').classList.add('hidden');">Cancel</button>
</div>
</div>
<!---------------- Import aidg.club Prompt ---------------------->
@@ -81,8 +81,8 @@
<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>
<button type="button" class="btn btn-primary popup_load_cancel_button" 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 popup_load_cancel_button" onclick="this.parentElement.parentElement.classList.add('hidden');">Cancel</button>
</div>
</div>
@@ -95,7 +95,7 @@
</div>
<div class="popup_load_cancel">
<button type="button" class="btn btn-primary" onclick="document.getElementById('error_message').classList.add('hidden');">Ok</button>
<button type="button" class="btn btn-primary popup_load_cancel_button" onclick="document.getElementById('error_message').classList.add('hidden');">Ok</button>
</div>
</div>
<!---------------- Advanced Theme Editor ---------------------->
@@ -107,7 +107,7 @@
<table border=1 id="advanced_theme_editor_table"></table>
</div>
<div class="popup_load_cancel">
<button type="button" class="btn btn-primary" onclick="document.getElementById('advanced_theme_editor').classList.add('hidden');">Ok</button>
<button type="button" class="btn btn-primary popup_load_cancel_button" onclick="document.getElementById('advanced_theme_editor').classList.add('hidden');">Ok</button>
</div>
</div>
<!---------------- Context Viewer ---------------------->

View File

@@ -44,7 +44,7 @@
</button>
<select class="var_sync_model_selected_preset settings_select presets" onchange='sync_to_server(this)'><option>Preset</option></select>
{% if not on_colab %}
<br/><input type=checkbox data-size="mini" data-onstyle="success" data-toggle="toggle" class='var_sync_system_horde_share' onchange='sync_to_server(this)'> Share with Horde
<div class="horde_trigger var_sync_alt_model_model"><input type=checkbox data-size="mini" data-onstyle="success" data-toggle="toggle" class='var_sync_system_horde_share' onchange='sync_to_server(this)'> Share with Horde </div>
<span class="helpicon material-icons-outlined" title="Shares your GPU with other KoboldAI users. Does not share data/stories.">help_icon</span>
{% endif %}
</div>
@@ -76,8 +76,6 @@
<span class="material-icons-outlined cursor var_sync_alt_story_gamesaved" title="Save Story">save</span>
<span class="button_label">Save Story</span>
</button>
</div>
</div>
<hr/>
@@ -88,6 +86,20 @@
{% include 'settings item.html' %}
{% endwith %}
{% endwith %}
<div class="setting_container chat_mode var_sync_alt_story_chatmode">
<!---Top Row---->
<span class="setting_label">
<span style="white-space: pre-wrap;">Chat Name: </span>
<span class="helpicon material-icons-outlined" title="Your name for chat mode.">help_icon</span>
</span>
<!---Bottom Row---->
<span class="setting_item" style="height: 25px;">
<input autocomplete="off" id="var_sync_story_chatname" class="var_sync_story_chatname settings_select" onclick="sync_to_server(this);">
</span>
<!---Slider Labels--->
<span class="setting_minlabel"><span style="top: -4px; position: relative;"></span></span>
<span class="setting_maxlabel"><span style="top: -4px; position: relative;"></span></span>
</div>
</div>
<div id="probabilities">
@@ -112,6 +124,9 @@
</div>
<div class="setting_tile_area">
<span class="help_text">Change how the AI decides what to say.</span>
{% with sub_path='Sampling' %}
{% include 'settings item.html' %}
{% endwith %}
<div class="setting_container_single">
<!---Top Row---->
<span class="setting_label">
@@ -137,9 +152,6 @@
</div>
</span>
</div>
{% with sub_path='Sampling' %}
{% include 'settings item.html' %}
{% endwith %}
</div>
<div class="collapsable_header" onclick="toggle_setting_category(this);">
@@ -312,15 +324,26 @@
<td><input class="Theme_Input" autocomplete="off" type=color id="tertiary_container_palette" onchange="palette_color(this)"></td>
<td><input class="Theme_Input" autocomplete="off" type=color id="on_tertiary_container_palette" onchange="palette_color(this)"></td>
</tr>
</table>
<table id="Palette_Table" border=1 style="border-color: var(--palette_table_border);">
<tr>
<td>Error</td>
<td><input class="Theme_Input" autocomplete="off" type=color id="error_palette" onchange="palette_color(this)"></td>
<td><input class="Theme_Input" autocomplete="off" type=color id="on_error_palette" onchange="palette_color(this)"></td>
<td><input class="Theme_Input" autocomplete="off" type=color id="error_container_palette" onchange="palette_color(this)"></td>
<td><input class="Theme_Input" autocomplete="off" type=color id="on_error_container_palette" onchange="palette_color(this)"></td>
<td colspan=5 style="text-align: center;">Backgrounds</td>
</tr>
<tr>
<td>Base</td>
<td>Layer 1</td>
<td>Layer 2</td>
<td>Layer 3</td>
<td>Layer 4</td>
</tr>
<tr>
<td><input class="Theme_Input" autocomplete="off" type=color id="background_palette" onchange="palette_color(this)"></td>
<td><input class="Theme_Input" autocomplete="off" type=color id="layer1_palette" onchange="palette_color(this)"></td>
<td><input class="Theme_Input" autocomplete="off" type=color id="layer2_palette" onchange="palette_color(this)"></td>
<td><input class="Theme_Input" autocomplete="off" type=color id="layer3_palette" onchange="palette_color(this)"></td>
<td><input class="Theme_Input" autocomplete="off" type=color id="layer4_palette" onchange="palette_color(this)"></td>
</tr>
</table>
</div>
</div>
<div class="advanced_theme cursor" onclick='document.getElementById("advanced_theme_editor").classList.remove("hidden");'>

View File

@@ -71,7 +71,7 @@
</span>
</div>
</div>
<div id="token-breakdown-container" style="border-top:2px;border-top-color:grey;border-top-style: solid;padding-top: 10px;">
<div id="token-breakdown-container" class="settings_footer" style="padding-top: 10px;">
<div class="token_breakdown">
<div id="soft_prompt_tokens" style="width:0%; background-color: var(--context_colors_soft_prompt);"></div>
<div id="memory_tokens" style="width:40%; background-color: var(--context_colors_memory);"></div>

View File

@@ -171,6 +171,7 @@
--radius_wi_card: 10px;
--radius_palette_card: 10px;
--radius_settings_button: 5px;
--tabs_rounding: 6px;

View File

@@ -184,6 +184,7 @@
--radius_settings_button: 0px;
--radius_alternate_button: 0px;
--radius_palette_card: 0px;
--tabs_rounding: 6px;
/* Variables */
--flyout_menu_closed_width: 0px;

View File

@@ -177,6 +177,7 @@
--radius_wi_card: 5px;
--radius_palette_card: 5px;
--radius_settings_button: 5px;
--tabs_rounding: 6px;

View File

@@ -170,6 +170,7 @@
--radius_wi_card: 5px;
--radius_palette_card: 5px;
--radius_settings_button: 2px;
--tabs_rounding: 6px;

View File

@@ -178,6 +178,7 @@
--radius_wi_card: 10px;
--radius_palette_card: 10px;
--radius_settings_button: 10px;
--tabs_rounding: 6px;