From 53dc1d8197a0a2f9a803dccf9457f9b1b04dbc26 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Tue, 9 Jan 2024 18:59:04 -0800 Subject: [PATCH 1/8] UI: Do not save unchanged settings to settings.yaml --- modules/shared.py | 2 ++ modules/ui.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/modules/shared.py b/modules/shared.py index b4194107..1c53ba38 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -1,4 +1,5 @@ import argparse +import copy import os import sys from collections import OrderedDict @@ -65,6 +66,7 @@ settings = { 'default_extensions': ['gallery'], } +default_settings = copy.deepcopy(settings) # Parser copied from https://github.com/vladmandic/automatic parser = argparse.ArgumentParser(description="Text generation web UI", conflict_handler='resolve', add_help=True, formatter_class=lambda prog: argparse.HelpFormatter(prog, max_help_position=55, indent_increment=2, width=200)) diff --git a/modules/ui.py b/modules/ui.py index 486a5b98..176d27a2 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -234,6 +234,11 @@ def save_settings(state, preset, extensions_list, show_controls, theme_state): _id = f"{extension_name}-{param}" output[_id] = params[param] + # Do not save unchanged settings + for key in list(output.keys()): + if key in shared.default_settings and output[key] == shared.default_settings[key]: + output.pop(key) + return yaml.dump(output, sort_keys=False, width=float("inf")) From a4c51b5a05b7ad6bb159f3811013077bff14932c Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Tue, 9 Jan 2024 19:02:45 -0800 Subject: [PATCH 2/8] API: add "user_name" and "bot_name" aliases for name1 and name2 --- extensions/openai/typing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/openai/typing.py b/extensions/openai/typing.py index f8a5203f..5725ece8 100644 --- a/extensions/openai/typing.py +++ b/extensions/openai/typing.py @@ -99,8 +99,8 @@ class ChatCompletionRequestParams(BaseModel): instruction_template_str: str | None = Field(default=None, description="A Jinja2 instruction template. If set, will take precedence over everything else.") character: str | None = Field(default=None, description="A character defined under text-generation-webui/characters. If not set, the default \"Assistant\" character will be used.") - name1: str | None = Field(default=None, description="Your name (the user). By default, it's \"You\".") - name2: str | None = Field(default=None, description="Overwrites the value set by character.") + name1: str | None = Field(default=None, description="Your name (the user). By default, it's \"You\".", alias=['user_name']) + name2: str | None = Field(default=None, description="Overwrites the value set by character.", alias=['bot_name']) context: str | None = Field(default=None, description="Overwrites the value set by character.") greeting: str | None = Field(default=None, description="Overwrites the value set by character.") chat_template_str: str | None = Field(default=None, description="Jinja2 template for chat.") From 4332e247407d433c162e2225d7ae20a786e4b005 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Tue, 9 Jan 2024 19:06:11 -0800 Subject: [PATCH 3/8] API: Make user_name/bot_name the official and name1/name2 the alias --- extensions/openai/typing.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/extensions/openai/typing.py b/extensions/openai/typing.py index 5725ece8..cd997106 100644 --- a/extensions/openai/typing.py +++ b/extensions/openai/typing.py @@ -99,10 +99,10 @@ class ChatCompletionRequestParams(BaseModel): instruction_template_str: str | None = Field(default=None, description="A Jinja2 instruction template. If set, will take precedence over everything else.") character: str | None = Field(default=None, description="A character defined under text-generation-webui/characters. If not set, the default \"Assistant\" character will be used.") - name1: str | None = Field(default=None, description="Your name (the user). By default, it's \"You\".", alias=['user_name']) - name2: str | None = Field(default=None, description="Overwrites the value set by character.", alias=['bot_name']) - context: str | None = Field(default=None, description="Overwrites the value set by character.") - greeting: str | None = Field(default=None, description="Overwrites the value set by character.") + user_name: str | None = Field(default=None, description="Your name (the user). By default, it's \"You\".", alias=['name1']) + bot_name: str | None = Field(default=None, description="Overwrites the value set by character field.", alias=['name2']) + context: str | None = Field(default=None, description="Overwrites the value set by character field.") + greeting: str | None = Field(default=None, description="Overwrites the value set by character field.") chat_template_str: str | None = Field(default=None, description="Jinja2 template for chat.") chat_instruct_command: str | None = None From bb2c4707c4c72b9d0fee8b6c1428c87c870e20a8 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Tue, 9 Jan 2024 19:08:02 -0800 Subject: [PATCH 4/8] API: fix bug after previous commit --- extensions/openai/completions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/openai/completions.py b/extensions/openai/completions.py index 26017f37..c5ef36e6 100644 --- a/extensions/openai/completions.py +++ b/extensions/openai/completions.py @@ -235,9 +235,9 @@ def chat_completions_common(body: dict, is_legacy: bool = False, stream=False) - # Chat character character = body['character'] or shared.settings['character'] character = "Assistant" if character == "None" else character - name1 = body['name1'] or shared.settings['name1'] + name1 = body['user_name'] or shared.settings['name1'] name1, name2, _, greeting, context = load_character_memoized(character, name1, '') - name2 = body['name2'] or name2 + name2 = body['bot_name'] or name2 context = body['context'] or context greeting = body['greeting'] or greeting From b3fc2cd8873b5dcf48c78a437581da46585fb3bb Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Wed, 10 Jan 2024 03:48:30 -0800 Subject: [PATCH 5/8] UI: Do not save unchanged extension settings to settings.yaml --- modules/extensions.py | 17 ++++++++++------- modules/ui.py | 4 +++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/modules/extensions.py b/modules/extensions.py index 2a3b0bb1..0af5e5fe 100644 --- a/modules/extensions.py +++ b/modules/extensions.py @@ -19,10 +19,9 @@ def apply_settings(extension, name): for param in extension.params: _id = f"{name}-{param}" - if _id not in shared.settings: - continue - - extension.params[param] = shared.settings[_id] + shared.default_settings[_id] = extension.params[param] + if _id in shared.settings: + extension.params[param] = shared.settings[_id] def load_extensions(): @@ -40,10 +39,14 @@ def load_extensions(): raise extension = getattr(extensions, name).script - apply_settings(extension, name) - if extension not in setup_called and hasattr(extension, "setup"): + + # Only run setup() and apply settings from settings.yaml once + if extension not in setup_called: + apply_settings(extension, name) + if hasattr(extension, "setup"): + extension.setup() + setup_called.add(extension) - extension.setup() state[name] = [True, i] except: diff --git a/modules/ui.py b/modules/ui.py index 176d27a2..3c978225 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -232,7 +232,9 @@ def save_settings(state, preset, extensions_list, show_controls, theme_state): params = getattr(extension, 'params') for param in params: _id = f"{extension_name}-{param}" - output[_id] = params[param] + # Only save if different from default value + if param not in shared.default_settings or params[param] != shared.default_settings[param]: + output[_id] = params[param] # Do not save unchanged settings for key in list(output.keys()): From ec2da5adef351153216987deae8fdb4cb8a74568 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Wed, 10 Jan 2024 03:57:32 -0800 Subject: [PATCH 6/8] Docs: document keyboard shortcuts --- docs/13 - Keyboard Shortcuts.md | 20 ++++++++++++++++++++ js/main.js | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 docs/13 - Keyboard Shortcuts.md diff --git a/docs/13 - Keyboard Shortcuts.md b/docs/13 - Keyboard Shortcuts.md new file mode 100644 index 00000000..b48c7da7 --- /dev/null +++ b/docs/13 - Keyboard Shortcuts.md @@ -0,0 +1,20 @@ +# Keyboard Shortcuts + +#### General + +| Shortcut | Description | +|-------------------------|--------------------------------------------------| +| Esc | Stop generation | +| Tab | Switch between current tab and Parameters tab | + +#### Chat tab + +| Shortcut | Description | +|-------------------------|--------------------------------------------------| +| Ctrl + S | Show/hide chat controls | +| Ctrl + Enter | Regenerate | +| Alt + Enter | Continue | +| Ctrl + Shift + Backspace| Remove last | +| Ctrl + Shift + K | Copy last | +| Ctrl + Shift + L | Replace last | +| Ctrl + Shift + M | Impersonate | diff --git a/js/main.js b/js/main.js index bc8c785d..45f5021f 100644 --- a/js/main.js +++ b/js/main.js @@ -99,7 +99,7 @@ document.addEventListener("keydown", function(event) { } // Switch between tabs on Tab - else if (!event.ctrlKey && !event.shiftKey && event.key === "Tab") { + else if (!event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey && event.key === "Tab") { event.preventDefault(); var parametersButton = document.getElementById("parameters-button"); var parentContainer = parametersButton.parentNode; From e1dd5ee2decb346cfa0ac4c0718afedcc958e6f8 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Wed, 10 Jan 2024 05:12:49 -0800 Subject: [PATCH 7/8] UI: focus on the chat input when switching to the chat tab --- js/main.js | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/js/main.js b/js/main.js index 45f5021f..e2fb850d 100644 --- a/js/main.js +++ b/js/main.js @@ -104,6 +104,7 @@ document.addEventListener("keydown", function(event) { var parametersButton = document.getElementById("parameters-button"); var parentContainer = parametersButton.parentNode; var selectedChild = parentContainer.querySelector(".selected"); + if (selectedChild.id == "parameters-button") { document.getElementById(previousTabId).click(); } else { @@ -318,7 +319,29 @@ document.getElementById("show-controls").parentNode.style.bottom = "0px"; //------------------------------------------------ // Focus on the chat input //------------------------------------------------ -document.querySelector("#chat-input textarea").focus(); +const chatTextArea = document.getElementById("chat-input").querySelector("textarea"); + +function respondToChatInputVisibility(element, callback) { + var options = { + root: document.documentElement, + }; + + var observer = new IntersectionObserver((entries, observer) => { + entries.forEach(entry => { + callback(entry.intersectionRatio > 0); + }); + }, options); + + observer.observe(element); +} + +function handleChatInputVisibilityChange(isVisible) { + if (isVisible) { + chatTextArea.focus(); + } +} + +respondToChatInputVisibility(chatTextArea, handleChatInputVisibilityChange); //------------------------------------------------ // Show enlarged character picture when the profile @@ -403,7 +426,7 @@ window.addEventListener("resize", updateDocumentWidth); //------------------------------------------------ const renameTextArea = document.getElementById("rename-row").querySelector("textarea"); -function respondToVisibility(element, callback) { +function respondToRenameVisibility(element, callback) { var options = { root: document.documentElement, }; @@ -424,4 +447,4 @@ function handleVisibilityChange(isVisible) { } } -respondToVisibility(renameTextArea, handleVisibilityChange); +respondToRenameVisibility(renameTextArea, handleVisibilityChange); From d80b191b1c98590ed793f30f8def510a64410763 Mon Sep 17 00:00:00 2001 From: Rimmy J <100532722+Ahrimdon@users.noreply.github.com> Date: Sat, 13 Jan 2024 19:47:13 -0500 Subject: [PATCH 8/8] Add requirement jinja2==3.1.* to fix error as described in issue #5240 (#5249) --------- Co-authored-by: oobabooga <112222186+oobabooga@users.noreply.github.com> Co-authored-by: Rim --- requirements.txt | 1 + requirements_amd.txt | 1 + requirements_amd_noavx2.txt | 1 + requirements_apple_intel.txt | 1 + requirements_apple_silicon.txt | 1 + requirements_cpu_only.txt | 1 + requirements_cpu_only_noavx2.txt | 1 + requirements_noavx2.txt | 1 + requirements_nowheels.txt | 1 + 9 files changed, 9 insertions(+) diff --git a/requirements.txt b/requirements.txt index 37df488d..d384acf4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,6 +5,7 @@ einops exllamav2==0.0.11; platform_system != "Darwin" and platform_machine != "x86_64" gradio==3.50.* hqq==0.1.2 +jinja2==3.1.2 lm_eval==0.3.0 markdown numpy==1.24.* diff --git a/requirements_amd.txt b/requirements_amd.txt index 632104de..845cb0b9 100644 --- a/requirements_amd.txt +++ b/requirements_amd.txt @@ -5,6 +5,7 @@ einops exllamav2==0.0.11; platform_system == "Windows" or python_version < "3.10" or python_version > "3.11" or platform_machine != "x86_64" gradio==3.50.* hqq==0.1.2 +jinja2==3.1.2 lm_eval==0.3.0 markdown numpy==1.24.* diff --git a/requirements_amd_noavx2.txt b/requirements_amd_noavx2.txt index 3234c8aa..5136be3c 100644 --- a/requirements_amd_noavx2.txt +++ b/requirements_amd_noavx2.txt @@ -5,6 +5,7 @@ einops exllamav2==0.0.11; platform_system == "Windows" or python_version < "3.10" or python_version > "3.11" or platform_machine != "x86_64" gradio==3.50.* hqq==0.1.2 +jinja2==3.1.2 lm_eval==0.3.0 markdown numpy==1.24.* diff --git a/requirements_apple_intel.txt b/requirements_apple_intel.txt index 9d26f0a7..14467b95 100644 --- a/requirements_apple_intel.txt +++ b/requirements_apple_intel.txt @@ -5,6 +5,7 @@ einops exllamav2==0.0.11 gradio==3.50.* hqq==0.1.2 +jinja2==3.1.2 lm_eval==0.3.0 markdown numpy==1.24.* diff --git a/requirements_apple_silicon.txt b/requirements_apple_silicon.txt index 034225ec..2e676eff 100644 --- a/requirements_apple_silicon.txt +++ b/requirements_apple_silicon.txt @@ -5,6 +5,7 @@ einops exllamav2==0.0.11 gradio==3.50.* hqq==0.1.2 +jinja2==3.1.2 lm_eval==0.3.0 markdown numpy==1.24.* diff --git a/requirements_cpu_only.txt b/requirements_cpu_only.txt index af1b4043..38306ca9 100644 --- a/requirements_cpu_only.txt +++ b/requirements_cpu_only.txt @@ -5,6 +5,7 @@ einops exllamav2==0.0.11 gradio==3.50.* hqq==0.1.2 +jinja2==3.1.2 lm_eval==0.3.0 markdown numpy==1.24.* diff --git a/requirements_cpu_only_noavx2.txt b/requirements_cpu_only_noavx2.txt index cbcabb2f..b0bdd089 100644 --- a/requirements_cpu_only_noavx2.txt +++ b/requirements_cpu_only_noavx2.txt @@ -5,6 +5,7 @@ einops exllamav2==0.0.11 gradio==3.50.* hqq==0.1.2 +jinja2==3.1.2 lm_eval==0.3.0 markdown numpy==1.24.* diff --git a/requirements_noavx2.txt b/requirements_noavx2.txt index 780e5d9c..37ff0518 100644 --- a/requirements_noavx2.txt +++ b/requirements_noavx2.txt @@ -5,6 +5,7 @@ einops exllamav2==0.0.11; platform_system != "Darwin" and platform_machine != "x86_64" gradio==3.50.* hqq==0.1.2 +jinja2==3.1.2 lm_eval==0.3.0 markdown numpy==1.24.* diff --git a/requirements_nowheels.txt b/requirements_nowheels.txt index 234387d6..9df2ef0b 100644 --- a/requirements_nowheels.txt +++ b/requirements_nowheels.txt @@ -5,6 +5,7 @@ einops exllamav2==0.0.11 gradio==3.50.* hqq==0.1.2 +jinja2==3.1.2 lm_eval==0.3.0 markdown numpy==1.24.*