From 07a3eac668c7317e5b56dea63c79ae36ce9d5f3a Mon Sep 17 00:00:00 2001 From: somebody Date: Wed, 14 Sep 2022 17:47:18 -0500 Subject: [PATCH 01/33] Init flexbox main area --- static/koboldai.css | 36 +++++++++++++++++++++--------------- templates/index_new.html | 27 +++++++++++---------------- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/static/koboldai.css b/static/koboldai.css index fc770080..1971c304 100644 --- a/static/koboldai.css +++ b/static/koboldai.css @@ -1104,16 +1104,17 @@ body { /* ------------------- Desktop Mode --------------------------- */ .main-grid { transition: margin-left .5s; - display: grid; - height: 98vh; + + display: flex; + flex-direction: column; + + height: 100vh; + padding: 10px; + margin-left: var(--setting_menu_closed_width_no_pins_width); margin-right: var(--flyout_menu_closed_width); - grid-template-areas: "menuicon gamescreen options lefticon" - "menuicon theme theme lefticon" - "menuicon inputrow inputrow lefticon"; - grid-template-columns: 30px auto var(--story_options_size) 30px; - grid-template-rows: auto min-content 100px; } + .main-grid.settings_pinned { margin-left: var(--flyout_menu_width); grid-template-columns: 30px auto var(--story_options_size) 30px; @@ -1150,6 +1151,16 @@ body { } } +#main-container { + display: flex; + + /* Don't expand! */ + min-height: 0; + + /* Grow vertically as a child; take up as much space as we can! */ + flex-grow: 1; +} + /* ---------------------------------- GAME SCREEN ----------------------------------*/ @@ -1159,11 +1170,10 @@ body { box-shadow: var(--light_shadow_value); color: var(--gamescreen_text); width: 100%; - grid-area: gamescreen; + flex-grow: 1; display: flex; flex-direction: column; overflow-x: hidden; - margin-top: 10px; vertical-align: bottom; font-family: "Helvetica Neue",Helvetica,Arial,sans-serif; font-size: calc((1em*var(--game_screen_font_size_adjustment)) + var(--font_size_adjustment)); @@ -1176,7 +1186,7 @@ body { } .gametext { - margin-top: auto; + /* margin-top: 2%; */ padding: 0px 5px 10px 10px; vertical-align: bottom; overflow-y: scroll; @@ -1199,8 +1209,7 @@ body { } .sequence_area { - margin-top: 10px; - grid-area: options; + max-width: var(--story_options_size); background-color: var(--sequence_area_background); overflow-y: scroll; } @@ -1297,7 +1306,6 @@ body { } .inputrow { - grid-area: inputrow; z-index: 2; display: grid; grid-template-areas: "textarea statusbar statusbar statusbar" @@ -1322,11 +1330,9 @@ body { #random_game_prompt{ display: flex; flex-direction: column; - grid-area: textarea; } #themetext{ - grid-area: textarea; height: 100%; width: 100%; padding: 5px; diff --git a/templates/index_new.html b/templates/index_new.html index 2475de33..09cc0f82 100644 --- a/templates/index_new.html +++ b/templates/index_new.html @@ -45,24 +45,19 @@
-
-

Disconnected

-
- - -                          -                          -                          -                          -                          -                          -                          - +
+
+

Disconnected

+
+ +
+ + + +
- - -
+
From 6effa2113965cceea389239df156aa5a0415d723 Mon Sep 17 00:00:00 2001 From: somebody Date: Wed, 14 Sep 2022 17:53:49 -0500 Subject: [PATCH 02/33] Polish on flexbox main --- static/koboldai.css | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/static/koboldai.css b/static/koboldai.css index 1971c304..b2a33734 100644 --- a/static/koboldai.css +++ b/static/koboldai.css @@ -1109,7 +1109,7 @@ body { flex-direction: column; height: 100vh; - padding: 10px; + padding: 10px 30px; margin-left: var(--setting_menu_closed_width_no_pins_width); margin-right: var(--flyout_menu_closed_width); @@ -1186,7 +1186,6 @@ body { } .gametext { - /* margin-top: 2%; */ padding: 0px 5px 10px 10px; vertical-align: bottom; overflow-y: scroll; @@ -1330,12 +1329,14 @@ body { #random_game_prompt{ display: flex; flex-direction: column; + grid-area: textarea; } #themetext{ height: 100%; width: 100%; padding: 5px; + grid-area: textarea; border-radius: var(--radius_inputbox); } From 93c7427031e7f88c8480fbc64f61fcdf742c1c9a Mon Sep 17 00:00:00 2001 From: ebolam Date: Wed, 14 Sep 2022 19:08:59 -0400 Subject: [PATCH 03/33] Fix for race condition --- static/koboldai.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/static/koboldai.js b/static/koboldai.js index a3326a7e..77fe20c9 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -1381,6 +1381,9 @@ function load_model() { } function world_info_entry_used_in_game(data) { + if (!(data.uid in world_info_data)) { + world_info_data[data.uid] = {}; + } world_info_data[data.uid]['used_in_game'] = data['used_in_game']; world_info_card = document.getElementById("world_info_"+data.uid); if (data.used_in_game) { From 07c23a776c700374307b4419d802264e85bba5ad Mon Sep 17 00:00:00 2001 From: ebolam Date: Wed, 14 Sep 2022 19:39:52 -0400 Subject: [PATCH 04/33] Undo of Merge 128. Had unintended consequences --- static/koboldai.css | 35 +++++++++++++++++++++-------------- templates/index_new.html | 27 +++++++++++---------------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/static/koboldai.css b/static/koboldai.css index 8ac52911..f8f0c6de 100644 --- a/static/koboldai.css +++ b/static/koboldai.css @@ -1104,16 +1104,17 @@ body { /* ------------------- Desktop Mode --------------------------- */ .main-grid { transition: margin-left .5s; - display: grid; - height: 98vh; + + display: flex; + flex-direction: column; + + height: 100vh; + padding: 10px 30px; + margin-left: var(--setting_menu_closed_width_no_pins_width); margin-right: var(--flyout_menu_closed_width); - grid-template-areas: "menuicon gamescreen options lefticon" - "menuicon theme theme lefticon" - "menuicon inputrow inputrow lefticon"; - grid-template-columns: 30px auto var(--story_options_size) 30px; - grid-template-rows: auto min-content 100px; } + .main-grid.settings_pinned { margin-left: var(--flyout_menu_width); grid-template-columns: 30px auto var(--story_options_size) 30px; @@ -1150,6 +1151,16 @@ body { } } +#main-container { + display: flex; + + /* Don't expand! */ + min-height: 0; + + /* Grow vertically as a child; take up as much space as we can! */ + flex-grow: 1; +} + /* ---------------------------------- GAME SCREEN ----------------------------------*/ @@ -1159,11 +1170,10 @@ body { box-shadow: var(--light_shadow_value); color: var(--gamescreen_text); width: 100%; - grid-area: gamescreen; + flex-grow: 1; display: flex; flex-direction: column; overflow-x: hidden; - margin-top: 10px; vertical-align: bottom; font-family: "Helvetica Neue",Helvetica,Arial,sans-serif; font-size: calc((1em*var(--game_screen_font_size_adjustment)) + var(--font_size_adjustment)); @@ -1176,7 +1186,6 @@ body { } .gametext { - margin-top: auto; padding: 0px 5px 10px 10px; vertical-align: bottom; overflow-y: scroll; @@ -1199,8 +1208,7 @@ body { } .sequence_area { - margin-top: 10px; - grid-area: options; + max-width: var(--story_options_size); background-color: var(--sequence_area_background); overflow-y: scroll; } @@ -1297,7 +1305,6 @@ body { } .inputrow { - grid-area: inputrow; z-index: 2; display: grid; grid-template-areas: "textarea statusbar statusbar statusbar" @@ -1326,10 +1333,10 @@ body { } #themetext{ - grid-area: textarea; height: 100%; width: 100%; padding: 5px; + grid-area: textarea; border-radius: var(--radius_inputbox); } diff --git a/templates/index_new.html b/templates/index_new.html index 70e2d7f1..94bfd552 100644 --- a/templates/index_new.html +++ b/templates/index_new.html @@ -45,24 +45,19 @@
-
-

Disconnected

-
- - -                          -                          -                          -                          -                          -                          -                          - +
+
+

Disconnected

+
+ +
+ + + +
- - -
+
From fdd8245e39c923b717ee513f782ca551662d2db4 Mon Sep 17 00:00:00 2001 From: ebolam Date: Wed, 14 Sep 2022 19:46:19 -0400 Subject: [PATCH 05/33] Really undo merge 128 --- static/koboldai.css | 32 +++++++++++++------------------- templates/index_new.html | 18 ++++++++---------- 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/static/koboldai.css b/static/koboldai.css index f8f0c6de..d46c81d6 100644 --- a/static/koboldai.css +++ b/static/koboldai.css @@ -1104,15 +1104,15 @@ body { /* ------------------- Desktop Mode --------------------------- */ .main-grid { transition: margin-left .5s; - - display: flex; - flex-direction: column; - - height: 100vh; - padding: 10px 30px; - + display: grid; + height: 98vh; margin-left: var(--setting_menu_closed_width_no_pins_width); margin-right: var(--flyout_menu_closed_width); + grid-template-areas: "menuicon gamescreen options lefticon" + "menuicon theme theme lefticon" + "menuicon inputrow inputrow lefticon"; + grid-template-columns: 30px auto var(--story_options_size) 30px; + grid-template-rows: auto min-content 100px; } .main-grid.settings_pinned { @@ -1151,16 +1151,6 @@ body { } } -#main-container { - display: flex; - - /* Don't expand! */ - min-height: 0; - - /* Grow vertically as a child; take up as much space as we can! */ - flex-grow: 1; -} - /* ---------------------------------- GAME SCREEN ----------------------------------*/ @@ -1170,10 +1160,11 @@ body { box-shadow: var(--light_shadow_value); color: var(--gamescreen_text); width: 100%; - flex-grow: 1; + grid-area: gamescreen; display: flex; flex-direction: column; overflow-x: hidden; + margin-top: 10px; vertical-align: bottom; font-family: "Helvetica Neue",Helvetica,Arial,sans-serif; font-size: calc((1em*var(--game_screen_font_size_adjustment)) + var(--font_size_adjustment)); @@ -1186,6 +1177,7 @@ body { } .gametext { + margin-top: auto; padding: 0px 5px 10px 10px; vertical-align: bottom; overflow-y: scroll; @@ -1208,7 +1200,8 @@ body { } .sequence_area { - max-width: var(--story_options_size); + margin-top: 10px; + grid-area: options; background-color: var(--sequence_area_background); overflow-y: scroll; } @@ -1305,6 +1298,7 @@ body { } .inputrow { + grid-area: inputrow; z-index: 2; display: grid; grid-template-areas: "textarea statusbar statusbar statusbar" diff --git a/templates/index_new.html b/templates/index_new.html index 94bfd552..c4fbd8c4 100644 --- a/templates/index_new.html +++ b/templates/index_new.html @@ -45,19 +45,17 @@
-
-
-

Disconnected

-
- -
+
+

Disconnected

+
+
- - - -
+ + +
+
From d686f2d96df0f73602ab633a48b10cd35f44dd40 Mon Sep 17 00:00:00 2001 From: ebolam Date: Wed, 14 Sep 2022 20:11:26 -0400 Subject: [PATCH 06/33] Fix for pulsing on blank area in new game --- static/koboldai.js | 12 ++++++++++-- templates/index_new.html | 11 +++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/static/koboldai.js b/static/koboldai.js index 77fe20c9..f70b5d89 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -2108,16 +2108,24 @@ function select_game_text(event) { selected_game_chunk = new_selected_game_chunk } + //since we have that delete me span for initial spacing, we don't want that to be editable, so let's fix that here + if (selected_game_chunk == document.getElementById("Delete Me")) { + selected_game_chunk = null; + } + //set editting class for (item of document.getElementsByClassName("editing")) { item.classList.remove("editing"); } - selected_game_chunk.classList.add("editing"); + if (selected_game_chunk != null) { + selected_game_chunk.classList.add("editing"); + } } } function edit_game_text() { - if ((selected_game_chunk != null) && (selected_game_chunk.textContent != selected_game_chunk.original_text)) { + if ((selected_game_chunk != null) && (selected_game_chunk.textContent != selected_game_chunk.original_text) && (selected_game_chunk != document.getElementById("Delete Me"))) { + console.log(selected_game_chunk); if (selected_game_chunk.id == "story_prompt") { sync_to_server(selected_game_chunk); } else { diff --git a/templates/index_new.html b/templates/index_new.html index c4fbd8c4..9894433f 100644 --- a/templates/index_new.html +++ b/templates/index_new.html @@ -49,6 +49,17 @@

Disconnected

+ + +                          +                          +                          +                          +                          +                          +                          + +
From 8d26be517300f3935466c3c1dcbb5c62bf8d2835 Mon Sep 17 00:00:00 2001 From: ebolam Date: Wed, 14 Sep 2022 20:50:58 -0400 Subject: [PATCH 07/33] Theme updates --- themes/Darkness.css | 2 +- themes/Monochrome.css | 2 +- themes/Nostalgia.css | 194 ++++++++++++++++++++++++++++++++++++++++++ themes/Unicorn.css | 2 +- 4 files changed, 197 insertions(+), 3 deletions(-) create mode 100644 themes/Nostalgia.css diff --git a/themes/Darkness.css b/themes/Darkness.css index 55b26b10..b58fd159 100644 --- a/themes/Darkness.css +++ b/themes/Darkness.css @@ -171,7 +171,7 @@ --radius_wi_card: 10px; --radius_palette_card: 10px; --radius_settings_button: 5px; - --tabs_rounding: 6px; + --tabs_rounding: 2px; diff --git a/themes/Monochrome.css b/themes/Monochrome.css index 88d8c1cb..4f934565 100644 --- a/themes/Monochrome.css +++ b/themes/Monochrome.css @@ -170,7 +170,7 @@ --radius_wi_card: 5px; --radius_palette_card: 5px; --radius_settings_button: 2px; - --tabs_rounding: 6px; + --tabs_rounding: 2px; diff --git a/themes/Nostalgia.css b/themes/Nostalgia.css new file mode 100644 index 00000000..23a7e2e9 --- /dev/null +++ b/themes/Nostalgia.css @@ -0,0 +1,194 @@ +/* + Name: Nostalgia + Author: LightSaveUs + Version: 0.1 + Description: A theme inspired by the previous KoboldAI interface. +*/ + +:root { +/*----------------Palette Theme--------------------*/ + --primary_palette: #000000; + --on_primary_palette: #000000; + --primary_container_palette: #000000; + --on_primary_container_palette: #000000; + + --secondary_palette: #000000; + --on_secondary_palette: #000000; + --secondary_container_palette: #000000; + --on_secondary_container_palette: #000000; + + --tertiary_palette: #000000; + --on_tertiary_palette: #000000; + --tertiary_container_palette: #000000; + --on_tertiary_container_palette: #000000; + + --background_palette: #000000; + --on_background_palette:#000000; + --layer1_palette: #000000; + --layer2_palette: #000000; + --layer3_palette: #000000; + --layer4_palette: #000000; + --outline_palette: #000000; + + --middle_palette: #000000; + --on_middle_palette: #000000; + --surface_palette: #000000; + --on_surface_palette: #000000; + +/*----------------Advanced Theme--------------------*/ + /*General*/ + --background: #303030; + --gamescreen_background: #262626; + --input_background: #404040; + + --text: #fff; + --text_to_ai_color: #cdd9e0; + --text_edit: #cdf; + + --statusbar_color: #6c6c6e99; + --statusbar_text_color: #ffffff; + --scrollbar-color: #74747400; + + /*Buttons*/ + /*General*/ + --enabled_button_text: #ffffff; + --enabled_button_background_color: #337ab7; + --enabled_button_border_color: #2e6da4; + + --disabled_button_text: #303030; + --disabled_button_background_color: #495762; + --disabled_button_border_color: #686c68; + + /*Home Tab*/ + --button_text: #ffffff; + --button_background: #285f90; + + /*Alternate Button*/ + --alternate_button_text: #ffffff; + --alternate_button_background: #285f90; + + + /*Sequence, AKA Gens Per Action*/ + --sequence_area_background: #303030; + --sequence_background: #262626; + --sequence_text: #ffffff; + + /*Side Menus*/ + --tab_color: #337ab7; + + --flyout_background: #212122; + --flyout_background_pinned: #212122; + + --setting_background: #295071; + --setting_text: #ffffff; + + --sample_order_select_color: #98bcdb; + --sample_order_select_color_text: #23527c; + + --dropdown_text: #ffffff; + --dropdown_background: #337ab7; + + --rangeslider_background_color: #ffffff; + --rangeslider_color: #005dc8; + --rangeslider_circle_color: #0077ff; + + --help_icon: #ffffff;/*--tooltip_text: #000000; + --tooltip_background: #000000;*/ + --setting_category_help_text_color: #3bf723; + + --setting_footer_border_color: grey; + --setting_footer_text_color: #ffffff; + --setting_footer_background_color: #212122; + + /*Palette Card*/ + --palette_card_background: #295071; + --palette_card_text: #ffffff; + --palette_table_border: #12324f; + + /*World Info*/ + --wi_card_border_color: #12324f; + --wi_card_border_color_to_ai: #eeeeeead; + + --wi_card_bg_color: #395c7c; + --wi_card_text_color: #ffffff; + + --wi_card_tag_bg_color: #295071; + --wi_card_tag_text_color: #ffffff; + + --wi_tag_color: #3379b7; + --wi_tag_text_color: #ffffff; + + /*Popup*/ + --popup_background_color: #333; + --popup_title_bar_color: #337ab7; + --popup_title_bar_color_text: #ffffff; + + --popup_item_color: #333333; + --popup_item_color_text: #ffffff; + + --popup_hover_color: #688f1f; + --popup_hover_color_text: #ffffff; + --popup_selected_color: #688f1f; + --popup_selected_color_text: #ffffff; + + --popup_button_color: #337ab7; + --popup_button_color_text: #ffffff; + --popup_cancel_button_color: #337ab7; + --popup_cancel_button_color_text: #ffffff; + + --error: #ffb4ab; + --error_text: #690005; + --error_title: #93000a; + --error_title_text: #ffdad6; + + /*Context Bar Colors*/ + --context_colors_memory: #295071; + --context_colors_authors_notes: #337ab7; + --context_colors_world_info: #98bcdb; + --context_colors_prompt: #3bf723; + --context_colors_game_text: #688f1f; + --context_colors_submit: #ededed; + --context_colors_unused: #ffffff24; + --context_colors_soft_prompt: #262626; + + /*Parameters*/ + --scrollbar-size: 6px; + --palette_card_shadow: 0; + --wi_card_shadow: 0; + --light_shadow_value: 0; + --left_menu_strong_shadow: 0; + --right_menu_light_shadow: 0; + --right_menu_strong_shadow: 0; + --radius_inputbox: 5px; + --radius_unpinned_menu: 5px; + --radius_sequence: 5px; + --radius_settings_background: 5px; + --radius_button: 5px; + --radius_alternate_button: 5px; + --radius_item_popup: 5px; + --radius_wi_card: 5px; + --radius_palette_card: 5px; + --radius_settings_button: 5px; + --tabs_rounding: 5px; + + + + + + +/*----------------VARIABLES--------------------*/ + --flyout_menu_closed_width: 0px; + --setting_menu_closed_width_no_pins_width: 0px; + --story_options_size: 30%; + --story_pinned_areas_left:"menuicon options gamescreen lefticon" + "menuicon theme theme lefticon" + "menuicon inputrow inputrow lefticon"; + --story_pinned_areas_right:"menuicon gamescreen options lefticon" + "menuicon theme theme lefticon" + "menuicon inputrow inputrow lefticon"; + --story_pinned_area_widths_left: 30pxvar(--story_options_size) auto 30px; + --story_pinned_area_widths_right: 30pxautovar(--story_options_size) 30px; + --story_pinned_areas:var(--story_pinned_areas_left); + --story_pinned_area_widths:var(--story_pinned_area_widths_left); + --font_size_adjustment: 0px; + --game_screen_font_size_adjustment: 1;} diff --git a/themes/Unicorn.css b/themes/Unicorn.css index 16a8296c..59450ce0 100644 --- a/themes/Unicorn.css +++ b/themes/Unicorn.css @@ -178,7 +178,7 @@ --radius_wi_card: 10px; --radius_palette_card: 10px; --radius_settings_button: 10px; - --tabs_rounding: 6px; + --tabs_rounding: 2px; From c222d2055b77bbda3278c86168fd5eb15a14710d Mon Sep 17 00:00:00 2001 From: ebolam Date: Thu, 15 Sep 2022 08:02:13 -0400 Subject: [PATCH 08/33] Fix for Horde --- koboldai_settings.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/koboldai_settings.py b/koboldai_settings.py index b29db50f..b22f372b 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -439,6 +439,8 @@ class model_settings(settings): self.selected_preset = "" self.uid_presets = [] self.default_preset = {} + cluster_requested_models = [] # The models which we allow to generate during cluster mode + #dummy class to eat the tqdm output class ignore_tqdm(object): From 1ee87b5719b028f8a50dde5851ccc61e49de1e10 Mon Sep 17 00:00:00 2001 From: ebolam Date: Thu, 15 Sep 2022 08:36:35 -0400 Subject: [PATCH 09/33] Horde Fix --- aiserver.py | 8 ++++++-- koboldai_settings.py | 2 +- static/koboldai.css | 3 ++- static/koboldai.js | 29 ++++++++++++++++++++++++++--- 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/aiserver.py b/aiserver.py index e8322f4a..aaacce0d 100644 --- a/aiserver.py +++ b/aiserver.py @@ -1181,6 +1181,7 @@ def get_model_info(model, directory=""): default_url = None models_on_url = False multi_online_models = False + show_online_model_select=False gpu_count = torch.cuda.device_count() gpu_names = [] for i in range(gpu_count): @@ -1189,6 +1190,7 @@ def get_model_info(model, directory=""): url = True elif model == 'CLUSTER': models_on_url = True + show_online_model_select=True url = True key = True default_url = 'https://koboldai.net' @@ -1206,6 +1208,7 @@ def get_model_info(model, directory=""): default_url = js['oaiurl'] get_cluster_models({'model': model, 'key': key_value, 'url': default_url}) elif model in [x[1] for x in model_menu['apilist']]: + show_online_model_select=True if path.exists("settings/{}.v2_settings".format(model)): with open("settings/{}.v2_settings".format(model), "r") as file: # Check if API key exists @@ -1254,7 +1257,7 @@ def get_model_info(model, directory=""): 'gpu':gpu, 'layer_count':layer_count, 'breakmodel':breakmodel, 'multi_online_models': multi_online_models, 'default_url': default_url, 'disk_break_value': disk_blocks, 'disk_break': utils.HAS_ACCELERATE, 'break_values': break_values, 'gpu_count': gpu_count, - 'url': url, 'gpu_names': gpu_names, 'models_on_url': models_on_url}, broadcast=False, room="UI_2") + 'url': url, 'gpu_names': gpu_names, 'models_on_url': models_on_url, 'show_online_model_select': show_online_model_select}, broadcast=False, room="UI_2") @@ -1927,6 +1930,7 @@ def load_model(use_gpu=True, gpu_layers=None, disk_layers=None, initial_load=Fal if not utils.HAS_ACCELERATE: disk_layers = None koboldai_vars.reset_model() + koboldai_vars.cluster_requested_models = online_model koboldai_vars.noai = False if not use_breakmodel_args: set_aibusy(True) @@ -1990,7 +1994,7 @@ def load_model(use_gpu=True, gpu_layers=None, disk_layers=None, initial_load=Fal koboldai_vars.configname = f"{koboldai_vars.model}_{online_model.replace('/', '_')}" if path.exists(get_config_filename()): changed=False - with open("settings/{}.v2_settings".format(koboldai_vars.model), "r") as file: + with open(get_config_filename(), "r") as file: # Check if API key exists js = json.load(file) if 'online_model' in js: diff --git a/koboldai_settings.py b/koboldai_settings.py index b22f372b..30a1b74b 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -439,7 +439,7 @@ class model_settings(settings): self.selected_preset = "" self.uid_presets = [] self.default_preset = {} - cluster_requested_models = [] # The models which we allow to generate during cluster mode + self.cluster_requested_models = [] # The models which we allow to generate during cluster mode #dummy class to eat the tqdm output diff --git a/static/koboldai.css b/static/koboldai.css index d46c81d6..1e6ac338 100644 --- a/static/koboldai.css +++ b/static/koboldai.css @@ -2290,6 +2290,7 @@ h2 .material-icons-outlined { } } -.horde_trigger[model_model="ReadOnly"] { +.horde_trigger[model_model="ReadOnly"], +.horde_trigger[model_model="CLUSTER"] { display: none; } \ No newline at end of file diff --git a/static/koboldai.js b/static/koboldai.js index f70b5d89..15f838a3 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -1062,6 +1062,7 @@ function show_model_menu(data) { document.getElementById("modelurl").classList.add("hidden"); document.getElementById("use_gpu_div").classList.add("hidden"); document.getElementById("modellayers").classList.add("hidden"); + document.getElementById("oaimodel").classList.add("hidden"); var model_layer_bars = document.getElementById('model_layer_bars'); while (model_layer_bars.firstChild) { model_layer_bars.removeChild(model_layer_bars.firstChild); @@ -1169,15 +1170,27 @@ function selected_model_info(data) { document.getElementById("modelurl").classList.add("hidden"); } + //default URL loading + if (data.default_url != null) { + document.getElementById("modelurl").value = data.default_url; + } + //change model loading on url if needed if (data.models_on_url) { - document.getElementById("modelurl").onchange = function () {socket.emit('get_cluster_models', {'key': document.getElementById("modelkey").value, 'url': this.value});}; - document.getElementById("modelkey").onchange = function () {socket.emit('get_cluster_models', {'key': this.value, 'url': document.getElementById("modelurl").value});}; + document.getElementById("modelurl").onchange = function () {socket.emit('get_cluster_models', {'model': document.getElementById('btn_loadmodelaccept').getAttribute('selected_model'), 'key': document.getElementById("modelkey").value, 'url': this.value});}; + document.getElementById("modelkey").onchange = function () {socket.emit('get_cluster_models', {'model': document.getElementById('btn_loadmodelaccept').getAttribute('selected_model'), 'key': this.value, 'url': document.getElementById("modelurl").value});}; } else { document.getElementById("modelkey").ochange = function () {socket.emit('OAI_Key_Update', {'model': document.getElementById('btn_loadmodelaccept').getAttribute('selected_model'), 'key': this.value});}; document.getElementById("modelurl").ochange = null; } + //show model select for APIs + if (data.show_online_model_select) { + document.getElementById("oaimodel").classList.remove("hidden"); + } else { + document.getElementById("oaimodel").classList.add("hidden"); + } + //Multiple Model Select? if (data.multi_online_models) { document.getElementById("oaimodel").setAttribute("multiple", ""); @@ -1372,10 +1385,20 @@ function load_model() { var path = ""; } + let selected_models = []; + for (item of document.getElementById("oaimodel").selectedOptions) { + selected_models.push(item.value); + } + if (selected_models == []) { + selected_models = ""; + } else if (selected_models.length == 1) { + selected_models = selected_models[0]; + } + message = {'model': model, 'path': path, 'use_gpu': document.getElementById("use_gpu").checked, 'key': document.getElementById('modelkey').value, 'gpu_layers': gpu_layers.join(), 'disk_layers': disk_layers, 'url': document.getElementById("modelurl").value, - 'online_model': document.getElementById("oaimodel").value}; + 'online_model': selected_models}; socket.emit("load_model", message); document.getElementById("loadmodelcontainer").classList.add("hidden"); } From e46872ce896ad2bdc131e5d5d846702f4b7b0c0d Mon Sep 17 00:00:00 2001 From: ebolam Date: Thu, 15 Sep 2022 09:24:55 -0400 Subject: [PATCH 10/33] Add in better error messages for UI2 for Horde Mode --- aiserver.py | 1 + 1 file changed, 1 insertion(+) diff --git a/aiserver.py b/aiserver.py index aaacce0d..4a8c98fc 100644 --- a/aiserver.py +++ b/aiserver.py @@ -4993,6 +4993,7 @@ def sendtoapi(txt, min, max): errmsg = "KoboldAI API Error: Failed to get a reply from the server. Please check the console." print("{0}{1}{2}".format(colors.RED, json.dumps(js, indent=2), colors.END)) emit('from_server', {'cmd': 'errmsg', 'data': errmsg}, broadcast=True) + emit("error", errmsg, broadcast=True, room="UI_2") set_aibusy(0) return From a3e33c922f9a7d3b956d38e757c4d5a14a3f3822 Mon Sep 17 00:00:00 2001 From: ebolam Date: Thu, 15 Sep 2022 19:18:32 -0400 Subject: [PATCH 11/33] fix Theme list not showing all themes fix for AN depth off by 1 in context viewer --- aiserver.py | 1 + koboldai_settings.py | 2 +- themes/Darkness.css | 2 +- themes/Unicorn.css | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/aiserver.py b/aiserver.py index 4a8c98fc..580bb4d2 100644 --- a/aiserver.py +++ b/aiserver.py @@ -6846,6 +6846,7 @@ def ui2_connect(): #Send all variables to client koboldai_vars.send_to_ui() UI_2_load_cookies() + UI_2_theme_list_refresh(None) pass #==================================================================# diff --git a/koboldai_settings.py b/koboldai_settings.py index 30a1b74b..12fe6cbd 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -197,7 +197,7 @@ class koboldai_vars(object): authors_note_final = self.authornotetemplate.replace("<|>", self.authornote) used_all_tokens = False for i in range(len(self.actions)-1, -1, -1): - if len(self.actions) - i == self.andepth and self.authornote != "": + if len(self.actions) - i - 1 == self.andepth and self.authornote != "": game_text = "{}{}".format(authors_note_final, game_text) game_context.insert(0, {"type": "authors_note", "text": authors_note_final}) if self.actions.actions[i]["Selected Text Length"]+used_tokens <= token_budget and not used_all_tokens: diff --git a/themes/Darkness.css b/themes/Darkness.css index b58fd159..3f559498 100644 --- a/themes/Darkness.css +++ b/themes/Darkness.css @@ -171,7 +171,7 @@ --radius_wi_card: 10px; --radius_palette_card: 10px; --radius_settings_button: 5px; - --tabs_rounding: 2px; + --tabs_rounding: 5px; diff --git a/themes/Unicorn.css b/themes/Unicorn.css index 59450ce0..21d758fb 100644 --- a/themes/Unicorn.css +++ b/themes/Unicorn.css @@ -178,7 +178,7 @@ --radius_wi_card: 10px; --radius_palette_card: 10px; --radius_settings_button: 10px; - --tabs_rounding: 2px; + --tabs_rounding: 10px; From 98105c729b18c41c2f9b7c66bb1bc542453010bc Mon Sep 17 00:00:00 2001 From: somebody Date: Thu, 15 Sep 2022 19:04:02 -0500 Subject: [PATCH 12/33] Work on import overhaul --- aiserver.py | 185 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 184 insertions(+), 1 deletion(-) diff --git a/aiserver.py b/aiserver.py index 4a8c98fc..37e505af 100644 --- a/aiserver.py +++ b/aiserver.py @@ -6,6 +6,7 @@ #==================================================================# # External packages +from dataclasses import dataclass import eventlet eventlet.monkey_patch(all=True, thread=False, os=False) import os @@ -239,6 +240,182 @@ class Send_to_socketio(object): def flush(self): pass + +@dataclass +class ImportBuffer: + # Singleton!!! + prompt: Optional[str] = None + memory: Optional[str] = None + authors_note: Optional[str] = None + world_infos: Optional[dict] = None + + @dataclass + class PromptPlaceholder: + id: str + order: Optional[int] = None + default: Optional[str] = None + title: Optional[str] = None + description: Optional[str] = None + value: Optional[str] = None + + def to_json(self) -> dict: + return {key: getattr(self, key) for key in [ + "id", + "order", + "default", + "title", + "description" + ]} + + def request_client_configuration(self, placeholders: list[PromptPlaceholder]) -> None: + emit("request_prompt_config", [x.to_json() for x in placeholders], broadcast=False, room="UI_2") + + def extract_placeholders(self, text: str) -> list[PromptPlaceholder]: + placeholders = [] + + for match in re.finditer(r"\${(.*?)}", text): + ph_text = match.group(1) + + try: + ph_order, ph_text = ph_text.split("#") + except ValueError: + ph_order = None + + if "[" not in ph_text: + ph_id = ph_text + + # Apparently, none of these characters are supported: + # "${}[]#:@^|", however I have found some prompts using these, + # so they will be allowed. + for char in "${}[]": + if char in ph_text: + print("[eph] Weird char") + print(f"{char=}") + print(f"{ph_id=}") + return + + placeholders.append(self.PromptPlaceholder( + id=ph_id, + order=int(ph_order) if ph_order else None, + )) + continue + + ph_id, _ = ph_text.split("[") + ph_text = ph_text.replace(ph_id, "", 1) + + # Match won't match it for some reason (???), so we use finditer and next() + try: + default_match = next(re.finditer(r"\[(.*?)\]", ph_text)) + except StopIteration: + print("[eph] Weird brackets") + return placeholders + + ph_default = default_match.group(1) + ph_text = ph_text.replace(default_match.group(0), "") + + try: + ph_title, ph_desc = ph_text.split(":") + except ValueError: + ph_title = ph_text or None + ph_desc=None + + placeholders.append(self.PromptPlaceholder( + id=ph_id, + order=int(ph_order) if ph_order else None, + default=ph_default, + title=ph_title, + description=ph_desc + )) + return placeholders + + def _replace_placeholders(self, text: str, ph_ids: dict): + for ph_id, value in ph_ids.items(): + pattern = "\${(?:\d#)?{}.*}".format(ph_id) + for ph_text in re.findall(pattern, text): + text = text.replace(ph_text, value) + return text + + def replace_placeholders(self, ph_ids: dict): + self.prompt = self._replace_placeholders(self.prompt, ph_ids) + self.memory = self._replace_placeholders(self.memory, ph_ids) + self.authors_note = self._replace_placeholders(self.authors_note, ph_ids) + + for i in range(len(self.world_infos)): + for key in ["content", "comment"]: + self.world_infos[i][key] = self._replace_placeholders(self.world_infos[i][key]) + + def from_club(self, club_id): + # Maybe it is a better to parse the NAI Scenario (if available), it has more data + r = requests.get(f"https://aetherroom.club/api/{club_id}") + + if not r.ok: + # TODO: Show error message on client + print(f"[import] Got {r.status_code} on request to club :^(") + return + + j = r.json() + + self.prompt = j["promptContent"] + self.memory = j["memory"] + self.authors_note = j["authorsNote"] + + self.world_infos = [] + + for wi in j["worldInfos"]: + self.world_infos.append({ + "key_list": wi["keysList"], + "keysecondary": [], + "content": wi["entry"], + "comment": "", + "folder": wi.get("folder", None), + "num": 0, + "init": True, + "selective": wi.get("selective", False), + "constant": wi.get("constant", False), + "uid": None, + }) + + placeholders = self.extract_placeholders(self.prompt) + if not placeholders: + self.commit() + else: + self.request_client_configuration(placeholders) + + def commit(self): + # Push buffer story to actual story + exitModes() + + koboldai_vars.create_story("") + koboldai_vars.gamestarted = True + koboldai_vars.prompt = self.prompt + koboldai_vars.memory = self.memory or "" + koboldai_vars.authornote = self.authors_note or "" + + # ???: Was this supposed to increment? + num = 0 + for wi in self.world_infos: + # koboldai_vars.worldinfo += self.world_infos + + koboldai_vars.worldinfo_v2.add_item( + wi["key_list"][0], + wi["key_list"], + wi.get("keysecondary", []), + wi.get("folder", "root"), + wi.get("constant", False), + wi["content"], + wi.get("comment", "") + ) + + # Reset current save + koboldai_vars.savedir = getcwd()+"\\stories" + + # Refresh game screen + koboldai_vars.laststory = None + setgamesaved(False) + sendwi() + refresh_story() + +import_buffer = ImportBuffer() # Set logging level to reduce chatter from Flask import logging @@ -7131,6 +7308,11 @@ def get_files_sorted(path, sort, desc=False): return [key[0] for key in sorted(data.items(), key=lambda kv: (kv[1], kv[0]), reverse=desc)] +@socketio.on("configure_prompt") +def UI_2_configure_prompt(data): + import_buffer.replace_placeholders(data) + import_buffer.commit() + #==================================================================# # Event triggered when browser SocketIO detects a variable change #==================================================================# @@ -7789,7 +7971,8 @@ def UI_2_unload_userscripts(data): def UI_2_load_aidg_club(data): if koboldai_vars.debug: print("Load aidg.club: {}".format(data)) - importAidgRequest(data) + import_buffer.from_club(data) + # importAidgRequest(data) #==================================================================# From 111fa70a203bc8de621f78b36ede0273f35788a9 Mon Sep 17 00:00:00 2001 From: somebody Date: Thu, 15 Sep 2022 19:28:08 -0500 Subject: [PATCH 13/33] Start work on prompt config ui --- static/koboldai.css | 63 ++++++++++++++++++++++++++++++++++++++++++- templates/popups.html | 33 ++++++++++++++++++++++- 2 files changed, 94 insertions(+), 2 deletions(-) diff --git a/static/koboldai.css b/static/koboldai.css index 1e6ac338..0c39595b 100644 --- a/static/koboldai.css +++ b/static/koboldai.css @@ -1854,7 +1854,8 @@ body { /* Finder */ #finder-container, -#debug-file-container { +#debug-file-container, +#prompt-config-container { display: flex; justify-content: center; align-items: center; @@ -2060,6 +2061,66 @@ body { background-color: rgb(158, 2, 2); } +/* Prompt Config */ +#prompt-config { + display: flex; + flex-direction: column; + position: relative; + background-color: var(--popup_background_color); + width: 25%; + height: 75%; +} + +#prompt-config-header { + /* HACK: Need to add (or use) a theme color for this! */ + background-color: #212a33; + padding: 7px; +} + +#prompt-config-header > h3 { + margin-top: 5px; + margin-bottom: 5px; +} + +#prompt-config-placeholders { + display: flex; + flex-direction: column; + row-gap: 16px; + overflow-y: scroll; + padding: 7px; + padding-left: 14px +} + +.prompt-config-title { + display: block; + font-size: 20px; + font-weight: bold; +} + +.prompt-config-value { + padding: 7px; +} + +#prompt-config-done { + display: flex; + justify-content: center; + align-items: center; + + width: 100px; + height: 32px; + + position: absolute; + + right: 10px; + bottom: 10px; + + + cursor: pointer; + color: var(--button_text); + background-color: var(--button_background); + border-radius: var(--radius_settings_button); +} + /*---------------------------------- Global ------------------------------------------------*/ .hidden { display: none; diff --git a/templates/popups.html b/templates/popups.html index 4a0a353a..e8fefbfd 100644 --- a/templates/popups.html +++ b/templates/popups.html @@ -192,4 +192,35 @@
-
\ No newline at end of file +
+ + +
+
+
+

Prompt Configuration

+ This prompt has placeholders you need to fill in before starting. +
+ + +
+
+ Name + What is your name? + +
+
+ +
Done
+
+
+ + \ No newline at end of file From c6d3c834839f863ece20a9a3fa00d097c2711b62 Mon Sep 17 00:00:00 2001 From: somebody Date: Thu, 15 Sep 2022 21:28:25 -0500 Subject: [PATCH 14/33] JS work on new club loading --- aiserver.py | 16 ++++++++++++++- static/koboldai.js | 47 +++++++++++++++++++++++++++++++++++++++++++ templates/popups.html | 25 ++++------------------- 3 files changed, 66 insertions(+), 22 deletions(-) diff --git a/aiserver.py b/aiserver.py index 37e505af..58fdf2e7 100644 --- a/aiserver.py +++ b/aiserver.py @@ -247,6 +247,7 @@ class ImportBuffer: prompt: Optional[str] = None memory: Optional[str] = None authors_note: Optional[str] = None + notes: Optional[str] = None world_infos: Optional[dict] = None @dataclass @@ -284,6 +285,10 @@ class ImportBuffer: if "[" not in ph_text: ph_id = ph_text + # Already have it! + if any([x.id == ph_id for x in placeholders]): + continue + # Apparently, none of these characters are supported: # "${}[]#:@^|", however I have found some prompts using these, # so they will be allowed. @@ -303,6 +308,10 @@ class ImportBuffer: ph_id, _ = ph_text.split("[") ph_text = ph_text.replace(ph_id, "", 1) + # Already have it! + if any([x.id == ph_id for x in placeholders]): + continue + # Match won't match it for some reason (???), so we use finditer and next() try: default_match = next(re.finditer(r"\[(.*?)\]", ph_text)) @@ -330,12 +339,15 @@ class ImportBuffer: def _replace_placeholders(self, text: str, ph_ids: dict): for ph_id, value in ph_ids.items(): - pattern = "\${(?:\d#)?{}.*}".format(ph_id) + print(f"iterating upon {ph_id=}") + pattern = "\${(?:\d#)?%s.*?}" % ph_id for ph_text in re.findall(pattern, text): + print(f"instance of {ph_id} in text, replaceing with {value}") text = text.replace(ph_text, value) return text def replace_placeholders(self, ph_ids: dict): + print(f"Replacing with {ph_ids}") self.prompt = self._replace_placeholders(self.prompt, ph_ids) self.memory = self._replace_placeholders(self.memory, ph_ids) self.authors_note = self._replace_placeholders(self.authors_note, ph_ids) @@ -358,6 +370,7 @@ class ImportBuffer: self.prompt = j["promptContent"] self.memory = j["memory"] self.authors_note = j["authorsNote"] + self.notes = j["description"] self.world_infos = [] @@ -390,6 +403,7 @@ class ImportBuffer: koboldai_vars.prompt = self.prompt koboldai_vars.memory = self.memory or "" koboldai_vars.authornote = self.authors_note or "" + koboldai_vars.notes = self.notes # ???: Was this supposed to increment? num = 0 diff --git a/static/koboldai.js b/static/koboldai.js index 15f838a3..c60a9a50 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -28,6 +28,7 @@ socket.on("error", function(data){show_error_message(data);}); socket.on('load_cookies', function(data){load_cookies(data)}); socket.on('load_tweaks', function(data){load_tweaks(data);}); socket.on("wi_results", updateWISearchListings); +socket.on("request_prompt_config", configurePrompt); //socket.onAny(function(event_name, data) {console.log({"event": event_name, "class": data.classname, "data": data});}); var presets = {}; @@ -3432,6 +3433,52 @@ async function downloadDebugFile(redact=true) { downloadString(JSON.stringify(debug_info, null, 4), "kobold_debug.json"); } +function configurePrompt(placeholderData) { + console.log(placeholderData); + const container = document.querySelector("#prompt-config-container"); + container.classList.remove("hidden"); + + const placeholders = document.querySelector("#prompt-config-placeholders"); + + for (const phData of placeholderData) { + let placeholder = $e("div", placeholders, {classes: ["prompt-config-ph"]}); + + + // ${character.name} is an AI Dungeon thing, although I believe NAI + // supports it as well. Many prompts use it. I think this is the only + // hardcoded thing like this. + let titleText = phData.title || phData.id; + if (titleText === "character.name") titleText = "Character Name"; + + let title = $e("span", placeholder, {classes: ["prompt-config-title"], innerText: titleText}); + + if (phData.description) $e("span", placeholder, { + classes: ["prompt-config-desc", "help_text"], + innerText: phData.description + }); + + let input = $e("input", placeholder, { + classes: ["prompt-config-value"], + value: phData.default || "", + placeholder: phData.default || "", + "placeholder-id": phData.id + }); + } +} + +function sendPromptConfiguration() { + let data = {}; + for (const configInput of document.querySelectorAll(".prompt-config-value")) { + data[configInput.getAttribute("placeholder-id")] = configInput.value; + } + + socket.emit("configure_prompt", data); + + document.querySelector("#popup").classList.add("hidden"); + document.querySelector("#prompt-config-container").classList.add("hidden"); + $(".prompt-config-ph").remove(); +} + function loadNAILorebook(data, filename) { let lorebookVersion = data.lorebookVersion; let wi_data = {folders: {[filename]: []}, entries: {}}; diff --git a/templates/popups.html b/templates/popups.html index e8fefbfd..e8d5c3e1 100644 --- a/templates/popups.html +++ b/templates/popups.html @@ -195,7 +195,7 @@
-
+ - - \ No newline at end of file +
\ No newline at end of file From b7dc60bff8c816300736c22b7a7e0a7c396a1f62 Mon Sep 17 00:00:00 2001 From: somebody Date: Thu, 15 Sep 2022 21:28:44 -0500 Subject: [PATCH 15/33] Fix typo in create_story --- koboldai_settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/koboldai_settings.py b/koboldai_settings.py index 30a1b74b..f64f2429 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -90,7 +90,7 @@ class koboldai_vars(object): else: self._story_settings[story_name] = story_settings(self.socketio) if json_data is not None: - self.load_story(sotry_name, json_data) + self.load_story(story_name, json_data) self._story_settings['default'].send_to_ui() def story_list(self): From 73b1e551fa210e05375364fbee49d3bb3fb15f8d Mon Sep 17 00:00:00 2001 From: somebody Date: Thu, 15 Sep 2022 22:13:54 -0500 Subject: [PATCH 16/33] Polish and bugfixes on import variables --- aiserver.py | 5 +---- static/koboldai.js | 1 - templates/popups.html | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/aiserver.py b/aiserver.py index 58fdf2e7..732f67a2 100644 --- a/aiserver.py +++ b/aiserver.py @@ -339,15 +339,12 @@ class ImportBuffer: def _replace_placeholders(self, text: str, ph_ids: dict): for ph_id, value in ph_ids.items(): - print(f"iterating upon {ph_id=}") - pattern = "\${(?:\d#)?%s.*?}" % ph_id + pattern = "\${(?:\d#)?%s.*?}" % re.escape(ph_id) for ph_text in re.findall(pattern, text): - print(f"instance of {ph_id} in text, replaceing with {value}") text = text.replace(ph_text, value) return text def replace_placeholders(self, ph_ids: dict): - print(f"Replacing with {ph_ids}") self.prompt = self._replace_placeholders(self.prompt, ph_ids) self.memory = self._replace_placeholders(self.memory, ph_ids) self.authors_note = self._replace_placeholders(self.authors_note, ph_ids) diff --git a/static/koboldai.js b/static/koboldai.js index c60a9a50..079ee749 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -3474,7 +3474,6 @@ function sendPromptConfiguration() { socket.emit("configure_prompt", data); - document.querySelector("#popup").classList.add("hidden"); document.querySelector("#prompt-config-container").classList.add("hidden"); $(".prompt-config-ph").remove(); } diff --git a/templates/popups.html b/templates/popups.html index e8d5c3e1..2ea3b71b 100644 --- a/templates/popups.html +++ b/templates/popups.html @@ -113,7 +113,7 @@
From 04b6ad83007b1cff75d821b45fa5a84ff29b5d23 Mon Sep 17 00:00:00 2001 From: ebolam Date: Fri, 16 Sep 2022 09:16:56 -0400 Subject: [PATCH 17/33] Fix for content editing. Highlighting is removed properly now. Still have weird line on top --- static/koboldai.js | 51 ++++++++++++---------------------------- templates/index_new.html | 2 +- 2 files changed, 16 insertions(+), 37 deletions(-) diff --git a/static/koboldai.js b/static/koboldai.js index 15f838a3..aa6e0f19 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -2127,28 +2127,29 @@ function select_game_text(event) { if ((new_selected_game_chunk != selected_game_chunk) && (selected_game_chunk != null)) { edit_game_text(); } - if (new_selected_game_chunk != selected_game_chunk) { - selected_game_chunk = new_selected_game_chunk - } - //since we have that delete me span for initial spacing, we don't want that to be editable, so let's fix that here - if (selected_game_chunk == document.getElementById("Delete Me")) { + //Check to see if new selection is a game chunk or something else + + if (((new_selected_game_chunk.id == "story_prompt") || (new_selected_game_chunk.id.slice(0,20) == "Selected Text Chunk ")) && (document.activeElement.isContentEditable)) { + if (new_selected_game_chunk != selected_game_chunk) { + for (item of document.getElementsByClassName("editing")) { + item.classList.remove("editing"); + } + selected_game_chunk = new_selected_game_chunk; + selected_game_chunk.classList.add("editing"); + } + + } else { selected_game_chunk = null; - } - - //set editting class - for (item of document.getElementsByClassName("editing")) { - item.classList.remove("editing"); - } - if (selected_game_chunk != null) { - selected_game_chunk.classList.add("editing"); + for (item of document.getElementsByClassName("editing")) { + item.classList.remove("editing"); + } } } } function edit_game_text() { if ((selected_game_chunk != null) && (selected_game_chunk.textContent != selected_game_chunk.original_text) && (selected_game_chunk != document.getElementById("Delete Me"))) { - console.log(selected_game_chunk); if (selected_game_chunk.id == "story_prompt") { sync_to_server(selected_game_chunk); } else { @@ -2159,28 +2160,6 @@ function edit_game_text() { } } -function clear_edit_game_text_tag() { - let id = null; - if (document.selection) { - if (document.selection.createRange().parentElement().id == 'story_prompt') { - id = document.selection.createRange().parentElement().id; - } else { - id = document.selection.createRange().parentElement().parentElement().id; - } - } else { - if (window.getSelection().anchorNode.parentNode.id == 'story_prompt') { - id = window.getSelection().anchorNode.parentNode.id; - } else { - id = window.getSelection().anchorNode.parentNode.parentNode.id; - } - } - if ((id != 'story_prompt') && (id.slice(0, 20) != "Selected Text Chunk ")) { - for (item of document.getElementsByClassName("editing")) { - item.classList.remove("editing"); - } - } -} - function save_preset() { socket.emit("save_new_preset", {"preset": document.getElementById("new_preset_name").value, "description": document.getElementById("new_preset_description").value}); document.getElementById('save_preset').classList.add('hidden'); diff --git a/templates/index_new.html b/templates/index_new.html index 9894433f..837f5527 100644 --- a/templates/index_new.html +++ b/templates/index_new.html @@ -47,7 +47,7 @@

Disconnected

-
+
From 278b6733079f2eab44476541556910544dff1a1d Mon Sep 17 00:00:00 2001 From: ebolam Date: Fri, 16 Sep 2022 09:21:17 -0400 Subject: [PATCH 18/33] Fix for dummy text area ("delete me" span) --- static/koboldai.js | 1 + templates/index_new.html | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/static/koboldai.js b/static/koboldai.js index 856f5039..52ee9cb9 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -123,6 +123,7 @@ function reset_story() { text += "\xa0 "; } dummy_span.textContent = text; + dummy_span.setAttribute("contenteditable", false); story_area.append(dummy_span); var option_area = document.getElementById("Select Options"); while (option_area.firstChild) { diff --git a/templates/index_new.html b/templates/index_new.html index 837f5527..519cf21a 100644 --- a/templates/index_new.html +++ b/templates/index_new.html @@ -49,7 +49,7 @@

Disconnected

- +                                                   From d96dd5ede26761314a91a49bb14b277bf630563d Mon Sep 17 00:00:00 2001 From: ebolam Date: Fri, 16 Sep 2022 09:42:05 -0400 Subject: [PATCH 19/33] Bug fix for merge (disabled functions) --- aiserver.py | 107 +++++++++++++++++++++++-------------------- koboldai_settings.py | 13 +++++- 2 files changed, 68 insertions(+), 52 deletions(-) diff --git a/aiserver.py b/aiserver.py index 31e945c5..25e4aab8 100644 --- a/aiserver.py +++ b/aiserver.py @@ -268,74 +268,74 @@ class ImportBuffer: "description" ]} - def request_client_configuration(self, placeholders: list[PromptPlaceholder]) -> None: - emit("request_prompt_config", [x.to_json() for x in placeholders], broadcast=False, room="UI_2") + #def request_client_configuration(self, placeholders: list[PromptPlaceholder]) -> None: + # emit("request_prompt_config", [x.to_json() for x in placeholders], broadcast=False, room="UI_2") - def extract_placeholders(self, text: str) -> list[PromptPlaceholder]: - placeholders = [] + #def extract_placeholders(self, text: str) -> list[PromptPlaceholder]: + # placeholders = [] - for match in re.finditer(r"\${(.*?)}", text): - ph_text = match.group(1) + # for match in re.finditer(r"\${(.*?)}", text): + # ph_text = match.group(1) - try: - ph_order, ph_text = ph_text.split("#") - except ValueError: - ph_order = None + # try: + # ph_order, ph_text = ph_text.split("#") + # except ValueError: + # ph_order = None - if "[" not in ph_text: - ph_id = ph_text + # if "[" not in ph_text: + # ph_id = ph_text # Already have it! - if any([x.id == ph_id for x in placeholders]): - continue + # if any([x.id == ph_id for x in placeholders]): + # continue # Apparently, none of these characters are supported: # "${}[]#:@^|", however I have found some prompts using these, # so they will be allowed. - for char in "${}[]": - if char in ph_text: - print("[eph] Weird char") - print(f"{char=}") - print(f"{ph_id=}") - return + # for char in "${}[]": + # if char in ph_text: + # print("[eph] Weird char") + # print(f"{char=}") + # print(f"{ph_id=}") + # return - placeholders.append(self.PromptPlaceholder( - id=ph_id, - order=int(ph_order) if ph_order else None, - )) - continue + # placeholders.append(self.PromptPlaceholder( + # id=ph_id, + # order=int(ph_order) if ph_order else None, + # )) + # continue - ph_id, _ = ph_text.split("[") - ph_text = ph_text.replace(ph_id, "", 1) + # ph_id, _ = ph_text.split("[") + # ph_text = ph_text.replace(ph_id, "", 1) # Already have it! - if any([x.id == ph_id for x in placeholders]): - continue + # if any([x.id == ph_id for x in placeholders]): + # continue # Match won't match it for some reason (???), so we use finditer and next() - try: - default_match = next(re.finditer(r"\[(.*?)\]", ph_text)) - except StopIteration: - print("[eph] Weird brackets") - return placeholders + # try: + # default_match = next(re.finditer(r"\[(.*?)\]", ph_text)) + # except StopIteration: + # print("[eph] Weird brackets") + # return placeholders - ph_default = default_match.group(1) - ph_text = ph_text.replace(default_match.group(0), "") + # ph_default = default_match.group(1) + # ph_text = ph_text.replace(default_match.group(0), "") - try: - ph_title, ph_desc = ph_text.split(":") - except ValueError: - ph_title = ph_text or None - ph_desc=None + # try: + # ph_title, ph_desc = ph_text.split(":") + # except ValueError: + # ph_title = ph_text or None + # ph_desc=None - placeholders.append(self.PromptPlaceholder( - id=ph_id, - order=int(ph_order) if ph_order else None, - default=ph_default, - title=ph_title, - description=ph_desc - )) - return placeholders + # placeholders.append(self.PromptPlaceholder( + # id=ph_id, + # order=int(ph_order) if ph_order else None, + # default=ph_default, + # title=ph_title, + # description=ph_desc + # )) + # return placeholders def _replace_placeholders(self, text: str, ph_ids: dict): for ph_id, value in ph_ids.items(): @@ -7592,7 +7592,7 @@ def get_story_listing_data(item_full_path, item, valid_selection): if js.get("file_version", 1) == 1: return [title, action_count, last_loaded] - action_count = 0 if js['actions']['action_count'] == -1 else js['actions']['action_count'] + action_count = js['actions']['action_count']+1 return [title, action_count, last_loaded] @@ -8071,6 +8071,13 @@ def get_model_size(model_name): elif "1.3B" in model_name: return "1.3B" +#==================================================================# +# Save New Preset +#==================================================================# +@socketio.on('save_revision') +def UI_2_save_revision(data): + koboldai_vars.save_revision() + #==================================================================# # Test #==================================================================# diff --git a/koboldai_settings.py b/koboldai_settings.py index f06db8fb..a98544eb 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -77,10 +77,12 @@ class koboldai_vars(object): with open("settings/system_settings.v2_settings", "w") as settings_file: settings_file.write(self._system_settings.to_json()) - def save_story(self): self._story_settings['default'].save_story() + def save_revision(self): + self._story_settings['default'].save_revision() + def create_story(self, story_name, json_data=None): #Story name here is intended for multiple users on multiple stories. Now always uses default #If we can figure out a way to get flask sessions into/through the lua bridge we could re-enable @@ -505,7 +507,7 @@ class model_settings(settings): process_variable_changes(self.socketio, self.__class__.__name__.replace("_settings", ""), name, value, old_value) class story_settings(settings): - local_only_variables = ['socketio', 'tokenizer', 'koboldai_vars', 'no_save'] + local_only_variables = ['socketio', 'tokenizer', 'koboldai_vars', 'no_save', 'revisions'] no_save_variables = ['socketio', 'tokenizer', 'koboldai_vars', 'context', 'no_save'] settings_name = "story" def __init__(self, socketio, koboldai_vars, tokenizer=None): @@ -568,6 +570,7 @@ class story_settings(settings): self.prompt_in_ai = False self.context = [] self.last_story_load = None + self.revisions = [] #must be at bottom self.no_save = False #Temporary disable save (doesn't save with the file) @@ -595,6 +598,12 @@ class story_settings(settings): settings_file.write(self.to_json()) self.gamesaved = True + def save_revision(self): + game = json.loads(self.to_json()) + del game['revisions'] + self.revisions.append(game) + self.gamesaved = False + def reset(self): self.no_save = True self.socketio.emit("reset_story", {}, broadcast=True, room="UI_2") From eabd418439c65baf38c957fc9a67ad28b7085af6 Mon Sep 17 00:00:00 2001 From: ebolam Date: Fri, 16 Sep 2022 13:58:49 -0400 Subject: [PATCH 20/33] Bug Fix --- environments/huggingface.yml | 2 +- static/koboldai.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/environments/huggingface.yml b/environments/huggingface.yml index 7261cada..47eb2e97 100644 --- a/environments/huggingface.yml +++ b/environments/huggingface.yml @@ -23,7 +23,7 @@ dependencies: - flask-cloudflared - flask-ngrok - lupa==1.10 - - transformers>=4.20.1 + - transformers==4.21.3 - accelerate - flask-session - python-socketio[client] \ No newline at end of file diff --git a/static/koboldai.js b/static/koboldai.js index 52ee9cb9..8463512b 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -2146,6 +2146,7 @@ function select_game_text(event) { for (item of document.getElementsByClassName("editing")) { item.classList.remove("editing"); } + window.getSelection().removeAllRanges() } } } From c43b24042dc3030ad8483a4a0ce2dd09e6ca8d5d Mon Sep 17 00:00:00 2001 From: somebody Date: Fri, 16 Sep 2022 16:16:17 -0500 Subject: [PATCH 21/33] Fix type annotations and cleanup import buffer --- aiserver.py | 114 +++++++++++++++++++++++++--------------------------- 1 file changed, 55 insertions(+), 59 deletions(-) diff --git a/aiserver.py b/aiserver.py index 25e4aab8..cefc8f1b 100644 --- a/aiserver.py +++ b/aiserver.py @@ -268,74 +268,74 @@ class ImportBuffer: "description" ]} - #def request_client_configuration(self, placeholders: list[PromptPlaceholder]) -> None: - # emit("request_prompt_config", [x.to_json() for x in placeholders], broadcast=False, room="UI_2") + def request_client_configuration(self, placeholders: List[PromptPlaceholder]) -> None: + emit("request_prompt_config", [x.to_json() for x in placeholders], broadcast=False, room="UI_2") - #def extract_placeholders(self, text: str) -> list[PromptPlaceholder]: - # placeholders = [] + def extract_placeholders(self, text: str) -> List[PromptPlaceholder]: + placeholders = [] - # for match in re.finditer(r"\${(.*?)}", text): - # ph_text = match.group(1) + for match in re.finditer(r"\${(.*?)}", text): + ph_text = match.group(1) - # try: - # ph_order, ph_text = ph_text.split("#") - # except ValueError: - # ph_order = None + try: + ph_order, ph_text = ph_text.split("#") + except ValueError: + ph_order = None - # if "[" not in ph_text: - # ph_id = ph_text + if "[" not in ph_text: + ph_id = ph_text - # Already have it! - # if any([x.id == ph_id for x in placeholders]): - # continue + # Already have it! + if any([x.id == ph_id for x in placeholders]): + continue - # Apparently, none of these characters are supported: - # "${}[]#:@^|", however I have found some prompts using these, - # so they will be allowed. - # for char in "${}[]": - # if char in ph_text: - # print("[eph] Weird char") - # print(f"{char=}") - # print(f"{ph_id=}") - # return + # Apparently, none of these characters are supported: + # "${}[]#:@^|", however I have found some prompts using these, + # so they will be allowed. + for char in "${}[]": + if char in ph_text: + print("[eph] Weird char") + print(f"{char=}") + print(f"{ph_id=}") + return - # placeholders.append(self.PromptPlaceholder( - # id=ph_id, - # order=int(ph_order) if ph_order else None, - # )) - # continue + placeholders.append(self.PromptPlaceholder( + id=ph_id, + order=int(ph_order) if ph_order else None, + )) + continue - # ph_id, _ = ph_text.split("[") - # ph_text = ph_text.replace(ph_id, "", 1) + ph_id, _ = ph_text.split("[") + ph_text = ph_text.replace(ph_id, "", 1) - # Already have it! - # if any([x.id == ph_id for x in placeholders]): - # continue + # Already have it! + if any([x.id == ph_id for x in placeholders]): + continue - # Match won't match it for some reason (???), so we use finditer and next() - # try: - # default_match = next(re.finditer(r"\[(.*?)\]", ph_text)) - # except StopIteration: - # print("[eph] Weird brackets") - # return placeholders + # Match won't match it for some reason (???), so we use finditer and next() + try: + default_match = next(re.finditer(r"\[(.*?)\]", ph_text)) + except StopIteration: + print("[eph] Weird brackets") + return placeholders - # ph_default = default_match.group(1) - # ph_text = ph_text.replace(default_match.group(0), "") + ph_default = default_match.group(1) + ph_text = ph_text.replace(default_match.group(0), "") - # try: - # ph_title, ph_desc = ph_text.split(":") - # except ValueError: - # ph_title = ph_text or None - # ph_desc=None + try: + ph_title, ph_desc = ph_text.split(":") + except ValueError: + ph_title = ph_text or None + ph_desc=None - # placeholders.append(self.PromptPlaceholder( - # id=ph_id, - # order=int(ph_order) if ph_order else None, - # default=ph_default, - # title=ph_title, - # description=ph_desc - # )) - # return placeholders + placeholders.append(self.PromptPlaceholder( + id=ph_id, + order=int(ph_order) if ph_order else None, + default=ph_default, + title=ph_title, + description=ph_desc + )) + return placeholders def _replace_placeholders(self, text: str, ph_ids: dict): for ph_id, value in ph_ids.items(): @@ -402,11 +402,7 @@ class ImportBuffer: koboldai_vars.authornote = self.authors_note or "" koboldai_vars.notes = self.notes - # ???: Was this supposed to increment? - num = 0 for wi in self.world_infos: - # koboldai_vars.worldinfo += self.world_infos - koboldai_vars.worldinfo_v2.add_item( wi["key_list"][0], wi["key_list"], From f70095f34f26739520e4b196a5f81ae78014b81b Mon Sep 17 00:00:00 2001 From: somebody Date: Fri, 16 Sep 2022 17:26:19 -0500 Subject: [PATCH 22/33] Yet more fixes for import buffer --- aiserver.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aiserver.py b/aiserver.py index cefc8f1b..900cb63e 100644 --- a/aiserver.py +++ b/aiserver.py @@ -295,8 +295,8 @@ class ImportBuffer: for char in "${}[]": if char in ph_text: print("[eph] Weird char") - print(f"{char=}") - print(f"{ph_id=}") + print(f"Char: {char}") + print(f"Ph_id: {ph_id}") return placeholders.append(self.PromptPlaceholder( From da750fbc99cbe9a5d602930f9b5a4d47898893ec Mon Sep 17 00:00:00 2001 From: ebolam Date: Fri, 16 Sep 2022 18:38:30 -0400 Subject: [PATCH 23/33] test delete me fix --- static/koboldai.js | 10 +++++++--- templates/index_new.html | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/static/koboldai.js b/static/koboldai.js index 8463512b..8e8f5d70 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -2119,10 +2119,14 @@ function select_game_text(event) { new_selected_game_chunk = document.selection.createRange().parentElement().parentElement(); } } else { - if (window.getSelection().anchorNode.parentNode.id == 'story_prompt') { - new_selected_game_chunk = window.getSelection().anchorNode.parentNode; + if(window.getSelection().anchorNode.parentNode) { + if (window.getSelection().anchorNode.parentNode.id == 'story_prompt') { + new_selected_game_chunk = window.getSelection().anchorNode.parentNode; + } else { + new_selected_game_chunk = window.getSelection().anchorNode.parentNode.parentNode; + } } else { - new_selected_game_chunk = window.getSelection().anchorNode.parentNode.parentNode; + new_selected_game_chunk = null; } } //if we've moved to a new game chunk we need to save the old chunk diff --git a/templates/index_new.html b/templates/index_new.html index 519cf21a..47bf3483 100644 --- a/templates/index_new.html +++ b/templates/index_new.html @@ -49,7 +49,7 @@

Disconnected

- +                                                   From ba805401aa54058bbbcd1604a9a061dea5869d46 Mon Sep 17 00:00:00 2001 From: ebolam Date: Fri, 16 Sep 2022 19:04:44 -0400 Subject: [PATCH 24/33] Fix for border highlighting in game text --- static/koboldai.css | 1 + templates/index_new.html | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/static/koboldai.css b/static/koboldai.css index 0c39595b..63efe15c 100644 --- a/static/koboldai.css +++ b/static/koboldai.css @@ -1181,6 +1181,7 @@ body { padding: 0px 5px 10px 10px; vertical-align: bottom; overflow-y: scroll; + outline: none; -ms-overflow-style: none; /* IE and Edge */ scrollbar-width: none; /* Firefox */ } diff --git a/templates/index_new.html b/templates/index_new.html index 47bf3483..65f697ac 100644 --- a/templates/index_new.html +++ b/templates/index_new.html @@ -49,7 +49,7 @@

Disconnected

- +                                                   From ec8435b6eec2783f995a9e366d43ac069fe273e5 Mon Sep 17 00:00:00 2001 From: ebolam Date: Fri, 16 Sep 2022 19:05:56 -0400 Subject: [PATCH 25/33] and again --- static/koboldai.js | 1 + 1 file changed, 1 insertion(+) diff --git a/static/koboldai.js b/static/koboldai.js index 8e8f5d70..3fd86e11 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -118,6 +118,7 @@ function reset_story() { } dummy_span = document.createElement("span"); dummy_span.id = "Delete Me"; + dummy_span.classList.add("noselect"); text = ""; for (i=0;i<154;i++) { text += "\xa0 "; From e89c59fe92800af01daa1279e5a502fcd9ec4315 Mon Sep 17 00:00:00 2001 From: ebolam Date: Fri, 16 Sep 2022 19:50:57 -0400 Subject: [PATCH 26/33] Changed deleteme to div --- aiserver.py | 8 ++++++++ static/koboldai.js | 10 ++++++++-- templates/index_new.html | 4 ++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/aiserver.py b/aiserver.py index 900cb63e..4b1b73ce 100644 --- a/aiserver.py +++ b/aiserver.py @@ -470,6 +470,14 @@ def emit(*args, **kwargs): except AttributeError: return socketio.emit(*args, **kwargs) +#replacement for tpool.execute to maintain request contexts +def replacement_tpool_execute(function, *args, **kwargs): + + +def replacement_tpool_execute_2(function, queue, *args, **kwargs): + return_data = function(*args, **kwargs) + queue.put(return_data) + # marshmallow/apispec setup from apispec import APISpec from apispec.ext.marshmallow import MarshmallowPlugin diff --git a/static/koboldai.js b/static/koboldai.js index 3fd86e11..4e075d7c 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -116,7 +116,7 @@ function reset_story() { while (story_area.lastChild.id != 'story_prompt') { story_area.removeChild(story_area.lastChild); } - dummy_span = document.createElement("span"); + dummy_span = document.createElement("div"); dummy_span.id = "Delete Me"; dummy_span.classList.add("noselect"); text = ""; @@ -2116,6 +2116,9 @@ function select_game_text(event) { if (document.selection) { if (document.selection.createRange().parentElement().id == 'story_prompt') { new_selected_game_chunk = document.selection.createRange().parentElement(); + } else if (document.selection.createRange().parentElement().id == 'gamescreen') { + new_selected_game_chunk = null; + console.log("Do nothing"); } else { new_selected_game_chunk = document.selection.createRange().parentElement().parentElement(); } @@ -2123,6 +2126,9 @@ function select_game_text(event) { if(window.getSelection().anchorNode.parentNode) { if (window.getSelection().anchorNode.parentNode.id == 'story_prompt') { new_selected_game_chunk = window.getSelection().anchorNode.parentNode; + } else if (window.getSelection().anchorNode.parentNode.id == "gamescreen") { + new_selected_game_chunk = null; + console.log("Do nothing"); } else { new_selected_game_chunk = window.getSelection().anchorNode.parentNode.parentNode; } @@ -2137,7 +2143,7 @@ function select_game_text(event) { //Check to see if new selection is a game chunk or something else - if (((new_selected_game_chunk.id == "story_prompt") || (new_selected_game_chunk.id.slice(0,20) == "Selected Text Chunk ")) && (document.activeElement.isContentEditable)) { + if ((new_selected_game_chunk == null) || (((new_selected_game_chunk.id == "story_prompt") || (new_selected_game_chunk.id.slice(0,20) == "Selected Text Chunk ")) && (document.activeElement.isContentEditable))) { if (new_selected_game_chunk != selected_game_chunk) { for (item of document.getElementsByClassName("editing")) { item.classList.remove("editing"); diff --git a/templates/index_new.html b/templates/index_new.html index 65f697ac..4509f069 100644 --- a/templates/index_new.html +++ b/templates/index_new.html @@ -49,7 +49,7 @@

Disconnected

- +
                                                  @@ -59,7 +59,7 @@                                                   - +
From a330d2069fd7b7e6803cc4266eef52981346aba0 Mon Sep 17 00:00:00 2001 From: ebolam Date: Fri, 16 Sep 2022 20:02:15 -0400 Subject: [PATCH 27/33] Possible relay fix :) --- aiserver.py | 28 +++++++++++++++------------- koboldai_settings.py | 1 + 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/aiserver.py b/aiserver.py index 4b1b73ce..f330d18d 100644 --- a/aiserver.py +++ b/aiserver.py @@ -472,11 +472,13 @@ def emit(*args, **kwargs): #replacement for tpool.execute to maintain request contexts def replacement_tpool_execute(function, *args, **kwargs): + temp = {} + socketio.start_background_task(replacement_tpool_execute_2, function, temp, *args, **kwargs).join() + print(temp) + return temp[1] - -def replacement_tpool_execute_2(function, queue, *args, **kwargs): - return_data = function(*args, **kwargs) - queue.put(return_data) +def replacement_tpool_execute_2(function, temp, *args, **kwargs): + temp[1] = function(*args, **kwargs) # marshmallow/apispec setup from apispec import APISpec @@ -3024,8 +3026,8 @@ def load_lua_scripts(): try: koboldai_vars.lua_koboldbridge.obliterate_multiverse() - tpool.execute(koboldai_vars.lua_koboldbridge.load_corescript, koboldai_vars.corescript) - koboldai_vars.has_genmod = tpool.execute(koboldai_vars.lua_koboldbridge.load_userscripts, filenames, modulenames, descriptions) + replacement_tpool_execute(koboldai_vars.lua_koboldbridge.load_corescript, koboldai_vars.corescript) + koboldai_vars.has_genmod = replacement_tpool_execute(koboldai_vars.lua_koboldbridge.load_userscripts, filenames, modulenames, descriptions) koboldai_vars.lua_running = True except lupa.LuaError as e: try: @@ -3523,7 +3525,7 @@ def execute_inmod(): koboldai_vars.lua_edited = set() koboldai_vars.lua_deleted = set() try: - tpool.execute(koboldai_vars.lua_koboldbridge.execute_inmod) + replacement_tpool_execute(koboldai_vars.lua_koboldbridge.execute_inmod) except lupa.LuaError as e: koboldai_vars.lua_koboldbridge.obliterate_multiverse() koboldai_vars.lua_running = False @@ -3542,7 +3544,7 @@ def execute_outmod(): setgamesaved(False) emit('from_server', {'cmd': 'hidemsg', 'data': ''}, broadcast=True, room="UI_1") try: - tpool.execute(koboldai_vars.lua_koboldbridge.execute_outmod) + replacement_tpool_execute(koboldai_vars.lua_koboldbridge.execute_outmod) except lupa.LuaError as e: koboldai_vars.lua_koboldbridge.obliterate_multiverse() koboldai_vars.lua_running = False @@ -4409,7 +4411,7 @@ def apiactionsubmit_generate(txt, minimum, maximum): torch.cuda.empty_cache() # Submit input text to generator - _genout, already_generated = tpool.execute(_generate, txt, minimum, maximum, set()) + _genout, already_generated = replacement_tpool_execute(_generate, txt, minimum, maximum, set()) genout = [applyoutputformatting(utils.decodenewlines(tokenizer.decode(tokens[-already_generated:]))) for tokens in _genout] @@ -4434,7 +4436,7 @@ def apiactionsubmit_tpumtjgenerate(txt, minimum, maximum): # Submit input text to generator soft_tokens = tpumtjgetsofttokens() - genout = tpool.execute( + genout = replacement_tpool_execute( tpu_mtj_backend.infer_static, np.uint32(txt), gen_len = maximum-minimum+1, @@ -4927,7 +4929,7 @@ def generate(txt, minimum, maximum, found_entries=None): # Submit input text to generator try: - genout, already_generated = tpool.execute(_generate, txt, minimum, maximum, found_entries) + genout, already_generated = replacement_tpool_execute(_generate, txt, minimum, maximum, found_entries) except Exception as e: if(issubclass(type(e), lupa.LuaError)): koboldai_vars.lua_koboldbridge.obliterate_multiverse() @@ -5352,7 +5354,7 @@ def tpumtjgenerate(txt, minimum, maximum, found_entries=None): past = np.empty((koboldai_vars.numseqs, 0), dtype=np.uint32) while(True): - genout, n_generated, regeneration_required, halt = tpool.execute( + genout, n_generated, regeneration_required, halt = replacement_tpool_execute( tpu_mtj_backend.infer_dynamic, context, gen_len = maximum-minimum+1, @@ -5394,7 +5396,7 @@ def tpumtjgenerate(txt, minimum, maximum, found_entries=None): ) else: - genout = tpool.execute( + genout = replacement_tpool_execute( tpu_mtj_backend.infer_static, np.uint32(txt), gen_len = maximum-minimum+1, diff --git a/koboldai_settings.py b/koboldai_settings.py index a98544eb..183b3083 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -34,6 +34,7 @@ def process_variable_changes(socketio, classname, name, value, old_value, debug_ 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 not has_request_context(): + print("Had to use relay :(") data = ["var_changed", {"classname": classname, "name": name, "old_value": clean_var_for_emit(old_value), "value": clean_var_for_emit(value)}, {"include_self":True, "broadcast":True, "room":"UI_2"}] if queue is not None: queue.put(data) From 7379141ca0d8122cf2bccc0afdc7d9399cad19c9 Mon Sep 17 00:00:00 2001 From: ebolam Date: Fri, 16 Sep 2022 21:05:39 -0400 Subject: [PATCH 28/33] Fix for editing --- static/koboldai.js | 3 +++ templates/index_new.html | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/static/koboldai.js b/static/koboldai.js index 4e075d7c..d0f2a34e 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -119,6 +119,7 @@ function reset_story() { dummy_span = document.createElement("div"); dummy_span.id = "Delete Me"; dummy_span.classList.add("noselect"); + document.getElementById("Selected Text").setAttribute("contenteditable", "false"); text = ""; for (i=0;i<154;i++) { text += "\xa0 "; @@ -313,6 +314,8 @@ function do_prompt(data) { if (document.getElementById("Delete Me")) { document.getElementById("Delete Me").remove(); } + //enable editing + document.getElementById("Selected Text").setAttribute("contenteditable", "true"); } else { document.getElementById('input_text').placeholder = "Enter Prompt Here (shift+enter for new line)"; document.getElementById('input_text').disabled = false; diff --git a/templates/index_new.html b/templates/index_new.html index 4509f069..82171801 100644 --- a/templates/index_new.html +++ b/templates/index_new.html @@ -47,7 +47,7 @@

Disconnected

-
+
From 3f2c64208c10177dd8063a5182b59ada36bcf26c Mon Sep 17 00:00:00 2001 From: ebolam Date: Sat, 17 Sep 2022 16:06:43 -0400 Subject: [PATCH 29/33] Undo last commit --- aiserver.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/aiserver.py b/aiserver.py index f330d18d..249a2d8f 100644 --- a/aiserver.py +++ b/aiserver.py @@ -471,13 +471,13 @@ def emit(*args, **kwargs): return socketio.emit(*args, **kwargs) #replacement for tpool.execute to maintain request contexts -def replacement_tpool_execute(function, *args, **kwargs): +def tpool.execute(function, *args, **kwargs): temp = {} - socketio.start_background_task(replacement_tpool_execute_2, function, temp, *args, **kwargs).join() + socketio.start_background_task(tpool.execute_2, function, temp, *args, **kwargs).join() print(temp) return temp[1] -def replacement_tpool_execute_2(function, temp, *args, **kwargs): +def tpool.execute_2(function, temp, *args, **kwargs): temp[1] = function(*args, **kwargs) # marshmallow/apispec setup @@ -3026,8 +3026,8 @@ def load_lua_scripts(): try: koboldai_vars.lua_koboldbridge.obliterate_multiverse() - replacement_tpool_execute(koboldai_vars.lua_koboldbridge.load_corescript, koboldai_vars.corescript) - koboldai_vars.has_genmod = replacement_tpool_execute(koboldai_vars.lua_koboldbridge.load_userscripts, filenames, modulenames, descriptions) + tpool.execute(koboldai_vars.lua_koboldbridge.load_corescript, koboldai_vars.corescript) + koboldai_vars.has_genmod = tpool.execute(koboldai_vars.lua_koboldbridge.load_userscripts, filenames, modulenames, descriptions) koboldai_vars.lua_running = True except lupa.LuaError as e: try: @@ -3525,7 +3525,7 @@ def execute_inmod(): koboldai_vars.lua_edited = set() koboldai_vars.lua_deleted = set() try: - replacement_tpool_execute(koboldai_vars.lua_koboldbridge.execute_inmod) + tpool.execute(koboldai_vars.lua_koboldbridge.execute_inmod) except lupa.LuaError as e: koboldai_vars.lua_koboldbridge.obliterate_multiverse() koboldai_vars.lua_running = False @@ -3544,7 +3544,7 @@ def execute_outmod(): setgamesaved(False) emit('from_server', {'cmd': 'hidemsg', 'data': ''}, broadcast=True, room="UI_1") try: - replacement_tpool_execute(koboldai_vars.lua_koboldbridge.execute_outmod) + tpool.execute(koboldai_vars.lua_koboldbridge.execute_outmod) except lupa.LuaError as e: koboldai_vars.lua_koboldbridge.obliterate_multiverse() koboldai_vars.lua_running = False @@ -4411,7 +4411,7 @@ def apiactionsubmit_generate(txt, minimum, maximum): torch.cuda.empty_cache() # Submit input text to generator - _genout, already_generated = replacement_tpool_execute(_generate, txt, minimum, maximum, set()) + _genout, already_generated = tpool.execute(_generate, txt, minimum, maximum, set()) genout = [applyoutputformatting(utils.decodenewlines(tokenizer.decode(tokens[-already_generated:]))) for tokens in _genout] @@ -4436,7 +4436,7 @@ def apiactionsubmit_tpumtjgenerate(txt, minimum, maximum): # Submit input text to generator soft_tokens = tpumtjgetsofttokens() - genout = replacement_tpool_execute( + genout = tpool.execute( tpu_mtj_backend.infer_static, np.uint32(txt), gen_len = maximum-minimum+1, @@ -4929,7 +4929,7 @@ def generate(txt, minimum, maximum, found_entries=None): # Submit input text to generator try: - genout, already_generated = replacement_tpool_execute(_generate, txt, minimum, maximum, found_entries) + genout, already_generated = tpool.execute(_generate, txt, minimum, maximum, found_entries) except Exception as e: if(issubclass(type(e), lupa.LuaError)): koboldai_vars.lua_koboldbridge.obliterate_multiverse() @@ -5354,7 +5354,7 @@ def tpumtjgenerate(txt, minimum, maximum, found_entries=None): past = np.empty((koboldai_vars.numseqs, 0), dtype=np.uint32) while(True): - genout, n_generated, regeneration_required, halt = replacement_tpool_execute( + genout, n_generated, regeneration_required, halt = tpool.execute( tpu_mtj_backend.infer_dynamic, context, gen_len = maximum-minimum+1, @@ -5396,7 +5396,7 @@ def tpumtjgenerate(txt, minimum, maximum, found_entries=None): ) else: - genout = replacement_tpool_execute( + genout = tpool.execute( tpu_mtj_backend.infer_static, np.uint32(txt), gen_len = maximum-minimum+1, From a2971b3f9c82ca1246596f619f249a3f602c1183 Mon Sep 17 00:00:00 2001 From: ebolam Date: Sat, 17 Sep 2022 16:08:32 -0400 Subject: [PATCH 30/33] fix --- aiserver.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aiserver.py b/aiserver.py index 249a2d8f..533e9a65 100644 --- a/aiserver.py +++ b/aiserver.py @@ -471,13 +471,13 @@ def emit(*args, **kwargs): return socketio.emit(*args, **kwargs) #replacement for tpool.execute to maintain request contexts -def tpool.execute(function, *args, **kwargs): +def replacement_tpool_execute(function, *args, **kwargs): temp = {} socketio.start_background_task(tpool.execute_2, function, temp, *args, **kwargs).join() print(temp) return temp[1] -def tpool.execute_2(function, temp, *args, **kwargs): +def replacement_tpool_execute_2(function, temp, *args, **kwargs): temp[1] = function(*args, **kwargs) # marshmallow/apispec setup From 3e5bf472bee26e845360adf3931e49654a046d78 Mon Sep 17 00:00:00 2001 From: ebolam Date: Sat, 17 Sep 2022 16:10:01 -0400 Subject: [PATCH 31/33] Remove relay debug message --- koboldai_settings.py | 1 - 1 file changed, 1 deletion(-) diff --git a/koboldai_settings.py b/koboldai_settings.py index 183b3083..a98544eb 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -34,7 +34,6 @@ def process_variable_changes(socketio, classname, name, value, old_value, debug_ 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 not has_request_context(): - print("Had to use relay :(") data = ["var_changed", {"classname": classname, "name": name, "old_value": clean_var_for_emit(old_value), "value": clean_var_for_emit(value)}, {"include_self":True, "broadcast":True, "room":"UI_2"}] if queue is not None: queue.put(data) From c3909a4d9c5192cf520c9f3c40553c3fa2f2bdc8 Mon Sep 17 00:00:00 2001 From: ebolam Date: Sat, 17 Sep 2022 18:29:08 -0400 Subject: [PATCH 32/33] Move save preset button --- static/koboldai.css | 10 ++++++++++ templates/settings flyout.html | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/static/koboldai.css b/static/koboldai.css index 63efe15c..dc43fc30 100644 --- a/static/koboldai.css +++ b/static/koboldai.css @@ -2355,4 +2355,14 @@ h2 .material-icons-outlined { .horde_trigger[model_model="ReadOnly"], .horde_trigger[model_model="CLUSTER"] { display: none; +} + +.preset_area { + width: 100%; + padding: 10px; + text-align: center; +} + +.preset_area .settings_button { + transform: translateY(6px); } \ No newline at end of file diff --git a/templates/settings flyout.html b/templates/settings flyout.html index 75212d09..71ef97a4 100644 --- a/templates/settings flyout.html +++ b/templates/settings flyout.html @@ -107,12 +107,12 @@ Download debug dump