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/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 diff --git a/extensions/openai/typing.py b/extensions/openai/typing.py index f8a5203f..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\".") - name2: str | None = Field(default=None, description="Overwrites the value set by character.") - 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 diff --git a/js/main.js b/js/main.js index bc8c785d..e2fb850d 100644 --- a/js/main.js +++ b/js/main.js @@ -99,11 +99,12 @@ 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; 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); 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/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..3c978225 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -232,7 +232,14 @@ 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()): + 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")) 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.*