diff --git a/.gitignore b/.gitignore index ba4939d..1127dd6 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ venv/ *.log settings.json +settings.yaml notification.mp3 img_bot* img_me* diff --git a/README.md b/README.md index f767411..580323c 100644 --- a/README.md +++ b/README.md @@ -207,7 +207,7 @@ Optionally, you can use the following command-line flags: | `--lora-dir LORA_DIR` | Path to directory with all the loras. | | `--model-menu` | Show a model menu in the terminal when the web UI is first launched. | | `--no-stream` | Don't stream the text output in real time. | -| `--settings SETTINGS_FILE` | Load the default interface settings from this json file. See `settings-template.json` for an example. If you create a file called `settings.json`, this file will be loaded by default without the need to use the `--settings` flag. | +| `--settings SETTINGS_FILE` | Load the default interface settings from this yaml file. See `settings-template.yaml` for an example. If you create a file called `settings.yaml`, this file will be loaded by default without the need to use the `--settings` flag. | | `--extensions EXTENSIONS [EXTENSIONS ...]` | The list of extensions to load. If you want to load more than one extension, write the names separated by spaces. | | `--verbose` | Print the prompts to the terminal. | diff --git a/modules/chat.py b/modules/chat.py index be5eb9a..2a25327 100644 --- a/modules/chat.py +++ b/modules/chat.py @@ -641,7 +641,7 @@ def save_character(name, greeting, context, picture, filename, instruct=False): data = {k: v for k, v in data.items() if v} # Strip falsy filepath = Path(f'{folder}/{filename}.yaml') with filepath.open('w') as f: - yaml.dump(data, f) + yaml.dump(data, f, sort_keys=False) logger.info(f'Wrote {filepath}') path_to_img = Path(f'{folder}/{filename}.png') diff --git a/modules/shared.py b/modules/shared.py index 99391f6..a48238f 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -65,18 +65,9 @@ settings = { 'chat_generation_attempts_min': 1, 'chat_generation_attempts_max': 10, 'default_extensions': [], - 'chat_default_extensions': ["gallery"], - 'presets': { - 'default': 'Default', - '.*(alpaca|llama|llava|vicuna)': "LLaMA-Precise", - '.*pygmalion': 'NovelAI-Storywriter', - '.*RWKV.*\.pth': 'Naive', - '.*moss': 'MOSS', - }, - 'prompts': { - 'default': 'QA', - '.*(gpt4chan|gpt-4chan|4chan)': 'GPT-4chan', - } + 'chat_default_extensions': ['gallery'], + 'preset': 'LLaMA-Precise', + 'prompt': 'QA', } @@ -103,7 +94,7 @@ parser.add_argument("--model-dir", type=str, default='models/', help="Path to di parser.add_argument("--lora-dir", type=str, default='loras/', help="Path to directory with all the loras") parser.add_argument('--model-menu', action='store_true', help='Show a model menu in the terminal when the web UI is first launched.') parser.add_argument('--no-stream', action='store_true', help='Don\'t stream the text output in real time.') -parser.add_argument('--settings', type=str, help='Load the default interface settings from this json file. See settings-template.json for an example. If you create a file called settings.json, this file will be loaded by default without the need to use the --settings flag.') +parser.add_argument('--settings', type=str, help='Load the default interface settings from this yaml file. See settings-template.yaml for an example. If you create a file called settings.yaml, this file will be loaded by default without the need to use the --settings flag.') parser.add_argument('--extensions', type=str, nargs="+", help='The list of extensions to load. If you want to load more than one extension, write the names separated by spaces.') parser.add_argument('--verbose', action='store_true', help='Print the prompts to the terminal.') diff --git a/modules/utils.py b/modules/utils.py index 6722022..84ca997 100644 --- a/modules/utils.py +++ b/modules/utils.py @@ -29,7 +29,7 @@ def get_available_models(): def get_available_presets(): - return sorted(set((k.stem for k in Path('presets').glob('*.txt'))), key=natural_keys) + return sorted(set((k.stem for k in Path('presets').glob('*.yaml'))), key=natural_keys) def get_available_prompts(): diff --git a/presets/Contrastive Search.txt b/presets/Contrastive Search.txt deleted file mode 100644 index 832bc9c..0000000 --- a/presets/Contrastive Search.txt +++ /dev/null @@ -1,3 +0,0 @@ -do_sample=False -penalty_alpha=0.6 -top_k=4 diff --git a/presets/Contrastive Search.yaml b/presets/Contrastive Search.yaml new file mode 100644 index 0000000..290342e --- /dev/null +++ b/presets/Contrastive Search.yaml @@ -0,0 +1,3 @@ +do_sample: False +penalty_alpha: 0.6 +top_k: 4 diff --git a/presets/Debug-deterministic.txt b/presets/Debug-deterministic.txt deleted file mode 100644 index 6673b71..0000000 --- a/presets/Debug-deterministic.txt +++ /dev/null @@ -1 +0,0 @@ -do_sample=False diff --git a/presets/Debug-deterministic.yaml b/presets/Debug-deterministic.yaml new file mode 100644 index 0000000..e5ccac6 --- /dev/null +++ b/presets/Debug-deterministic.yaml @@ -0,0 +1 @@ +do_sample: False diff --git a/presets/Default.txt b/presets/Default.txt deleted file mode 100644 index d28ce62..0000000 --- a/presets/Default.txt +++ /dev/null @@ -1,6 +0,0 @@ -do_sample=True -top_p=0.5 -top_k=40 -temperature=0.7 -repetition_penalty=1.2 -typical_p=1.0 diff --git a/presets/Default.yaml b/presets/Default.yaml new file mode 100644 index 0000000..0b1b8b7 --- /dev/null +++ b/presets/Default.yaml @@ -0,0 +1,6 @@ +do_sample: true +top_p: 0.5 +top_k: 40 +temperature: 0.7 +repetition_penalty: 1.2 +typical_p: 1.0 diff --git a/presets/Kobold-Godlike.txt b/presets/Kobold-Godlike.txt deleted file mode 100644 index 0ba5b79..0000000 --- a/presets/Kobold-Godlike.txt +++ /dev/null @@ -1,6 +0,0 @@ -do_sample=True -top_p=0.5 -top_k=0 -temperature=0.7 -repetition_penalty=1.1 -typical_p=0.19 diff --git a/presets/Kobold-Godlike.yaml b/presets/Kobold-Godlike.yaml new file mode 100644 index 0000000..3d2bdf2 --- /dev/null +++ b/presets/Kobold-Godlike.yaml @@ -0,0 +1,6 @@ +do_sample: true +top_p: 0.5 +top_k: 0 +temperature: 0.7 +repetition_penalty: 1.1 +typical_p: 0.19 diff --git a/presets/Kobold-Liminal Drift.txt b/presets/Kobold-Liminal Drift.txt deleted file mode 100644 index be4dd3b..0000000 --- a/presets/Kobold-Liminal Drift.txt +++ /dev/null @@ -1,6 +0,0 @@ -do_sample=True -top_p=1.0 -top_k=0 -temperature=0.66 -repetition_penalty=1.1 -typical_p=0.6 diff --git a/presets/Kobold-Liminal Drift.yaml b/presets/Kobold-Liminal Drift.yaml new file mode 100644 index 0000000..3dbcd5c --- /dev/null +++ b/presets/Kobold-Liminal Drift.yaml @@ -0,0 +1,6 @@ +do_sample: true +top_p: 1.0 +top_k: 0 +temperature: 0.66 +repetition_penalty: 1.1 +typical_p: 0.6 diff --git a/presets/LLaMA-Precise.txt b/presets/LLaMA-Precise.txt deleted file mode 100644 index 8098b39..0000000 --- a/presets/LLaMA-Precise.txt +++ /dev/null @@ -1,6 +0,0 @@ -do_sample=True -top_p=0.1 -top_k=40 -temperature=0.7 -repetition_penalty=1.18 -typical_p=1.0 diff --git a/presets/LLaMA-Precise.yaml b/presets/LLaMA-Precise.yaml new file mode 100644 index 0000000..2d0c2bd --- /dev/null +++ b/presets/LLaMA-Precise.yaml @@ -0,0 +1,6 @@ +do_sample: true +top_p: 0.1 +top_k: 40 +temperature: 0.7 +repetition_penalty: 1.18 +typical_p: 1.0 diff --git a/presets/MOSS.txt b/presets/MOSS.txt deleted file mode 100644 index e895e88..0000000 --- a/presets/MOSS.txt +++ /dev/null @@ -1,3 +0,0 @@ -temperature=0.7 -top_p=0.8 -repetition_penalty=1.02 diff --git a/presets/MOSS.yaml b/presets/MOSS.yaml new file mode 100644 index 0000000..6eccc94 --- /dev/null +++ b/presets/MOSS.yaml @@ -0,0 +1,3 @@ +temperature: 0.7 +top_p: 0.8 +repetition_penalty: 1.02 diff --git a/presets/Naive.txt b/presets/Naive.txt deleted file mode 100644 index aa8c058..0000000 --- a/presets/Naive.txt +++ /dev/null @@ -1,4 +0,0 @@ -do_sample=True -temperature=0.7 -top_p=0.85 -top_k=50 diff --git a/presets/Naive.yaml b/presets/Naive.yaml new file mode 100644 index 0000000..af98420 --- /dev/null +++ b/presets/Naive.yaml @@ -0,0 +1,4 @@ +do_sample: true +temperature: 0.7 +top_p: 0.85 +top_k: 50 diff --git a/presets/NovelAI-Best Guess.txt b/presets/NovelAI-Best Guess.txt deleted file mode 100644 index db3fa75..0000000 --- a/presets/NovelAI-Best Guess.txt +++ /dev/null @@ -1,6 +0,0 @@ -do_sample=True -top_p=0.9 -top_k=100 -temperature=0.8 -repetition_penalty=1.15 -typical_p=1.0 diff --git a/presets/NovelAI-Best Guess.yaml b/presets/NovelAI-Best Guess.yaml new file mode 100644 index 0000000..2c21d13 --- /dev/null +++ b/presets/NovelAI-Best Guess.yaml @@ -0,0 +1,6 @@ +do_sample: true +top_p: 0.9 +top_k: 100 +temperature: 0.8 +repetition_penalty: 1.15 +typical_p: 1.0 diff --git a/presets/NovelAI-Decadence.txt b/presets/NovelAI-Decadence.txt deleted file mode 100644 index d3109f3..0000000 --- a/presets/NovelAI-Decadence.txt +++ /dev/null @@ -1,6 +0,0 @@ -do_sample=True -top_p=1.0 -top_k=100 -temperature=2 -repetition_penalty=1 -typical_p=0.97 diff --git a/presets/NovelAI-Decadence.yaml b/presets/NovelAI-Decadence.yaml new file mode 100644 index 0000000..28e1a21 --- /dev/null +++ b/presets/NovelAI-Decadence.yaml @@ -0,0 +1,6 @@ +do_sample: true +top_p: 1.0 +top_k: 100 +temperature: 2 +repetition_penalty: 1 +typical_p: 0.97 diff --git a/presets/NovelAI-Genesis.txt b/presets/NovelAI-Genesis.txt deleted file mode 100644 index cc7376b..0000000 --- a/presets/NovelAI-Genesis.txt +++ /dev/null @@ -1,6 +0,0 @@ -do_sample=True -top_p=0.98 -top_k=0 -temperature=0.63 -repetition_penalty=1.05 -typical_p=1.0 diff --git a/presets/NovelAI-Genesis.yaml b/presets/NovelAI-Genesis.yaml new file mode 100644 index 0000000..41ee4c6 --- /dev/null +++ b/presets/NovelAI-Genesis.yaml @@ -0,0 +1,6 @@ +do_sample: true +top_p: 0.98 +top_k: 0 +temperature: 0.63 +repetition_penalty: 1.05 +typical_p: 1.0 diff --git a/presets/NovelAI-Lycaenidae.txt b/presets/NovelAI-Lycaenidae.txt deleted file mode 100644 index 0134569..0000000 --- a/presets/NovelAI-Lycaenidae.txt +++ /dev/null @@ -1,6 +0,0 @@ -do_sample=True -top_p=0.85 -top_k=12 -temperature=2 -repetition_penalty=1.15 -typical_p=1.0 diff --git a/presets/NovelAI-Lycaenidae.yaml b/presets/NovelAI-Lycaenidae.yaml new file mode 100644 index 0000000..be296d7 --- /dev/null +++ b/presets/NovelAI-Lycaenidae.yaml @@ -0,0 +1,6 @@ +do_sample: true +top_p: 0.85 +top_k: 12 +temperature: 2 +repetition_penalty: 1.15 +typical_p: 1.0 diff --git a/presets/NovelAI-Ouroboros.txt b/presets/NovelAI-Ouroboros.txt deleted file mode 100644 index 1e944b5..0000000 --- a/presets/NovelAI-Ouroboros.txt +++ /dev/null @@ -1,6 +0,0 @@ -do_sample=True -top_p=1.0 -top_k=100 -temperature=1.07 -repetition_penalty=1.05 -typical_p=1.0 diff --git a/presets/NovelAI-Ouroboros.yaml b/presets/NovelAI-Ouroboros.yaml new file mode 100644 index 0000000..53846a1 --- /dev/null +++ b/presets/NovelAI-Ouroboros.yaml @@ -0,0 +1,6 @@ +do_sample: true +top_p: 1.0 +top_k: 100 +temperature: 1.07 +repetition_penalty: 1.05 +typical_p: 1.0 diff --git a/presets/NovelAI-Pleasing Results.txt b/presets/NovelAI-Pleasing Results.txt deleted file mode 100644 index 330114a..0000000 --- a/presets/NovelAI-Pleasing Results.txt +++ /dev/null @@ -1,6 +0,0 @@ -do_sample=True -top_p=1.0 -top_k=0 -temperature=0.44 -repetition_penalty=1.15 -typical_p=1.0 diff --git a/presets/NovelAI-Pleasing Results.yaml b/presets/NovelAI-Pleasing Results.yaml new file mode 100644 index 0000000..ca7408d --- /dev/null +++ b/presets/NovelAI-Pleasing Results.yaml @@ -0,0 +1,6 @@ +do_sample: true +top_p: 1.0 +top_k: 0 +temperature: 0.44 +repetition_penalty: 1.15 +typical_p: 1.0 diff --git a/presets/NovelAI-Sphinx Moth.txt b/presets/NovelAI-Sphinx Moth.txt deleted file mode 100644 index bace1e2..0000000 --- a/presets/NovelAI-Sphinx Moth.txt +++ /dev/null @@ -1,6 +0,0 @@ -do_sample=True -top_p=0.18 -top_k=30 -temperature=2.0 -repetition_penalty=1.15 -typical_p=1.0 diff --git a/presets/NovelAI-Sphinx Moth.yaml b/presets/NovelAI-Sphinx Moth.yaml new file mode 100644 index 0000000..8efd5a7 --- /dev/null +++ b/presets/NovelAI-Sphinx Moth.yaml @@ -0,0 +1,6 @@ +do_sample: true +top_p: 0.18 +top_k: 30 +temperature: 2.0 +repetition_penalty: 1.15 +typical_p: 1.0 diff --git a/presets/NovelAI-Storywriter.txt b/presets/NovelAI-Storywriter.txt deleted file mode 100644 index 2df5f81..0000000 --- a/presets/NovelAI-Storywriter.txt +++ /dev/null @@ -1,6 +0,0 @@ -do_sample=True -top_p=0.73 -top_k=0 -temperature=0.72 -repetition_penalty=1.1 -typical_p=1.0 diff --git a/presets/NovelAI-Storywriter.yaml b/presets/NovelAI-Storywriter.yaml new file mode 100644 index 0000000..34d11ec --- /dev/null +++ b/presets/NovelAI-Storywriter.yaml @@ -0,0 +1,6 @@ +do_sample: true +top_p: 0.73 +top_k: 0 +temperature: 0.72 +repetition_penalty: 1.1 +typical_p: 1.0 diff --git a/presets/Verbose (Beam Search).txt b/presets/Verbose (Beam Search).txt deleted file mode 100644 index 464a4a5..0000000 --- a/presets/Verbose (Beam Search).txt +++ /dev/null @@ -1,9 +0,0 @@ -num_beams=10 -min_length=200 -length_penalty=1.4 -no_repeat_ngram_size=2 -early_stopping=True -temperature=0.7 -top_k=150 -top_p=0.92 -repetition_penalty=4.5 diff --git a/presets/Verbose (Beam Search).yaml b/presets/Verbose (Beam Search).yaml new file mode 100644 index 0000000..bd75fca --- /dev/null +++ b/presets/Verbose (Beam Search).yaml @@ -0,0 +1,9 @@ +num_beams: 10 +min_length: 200 +length_penalty: 1.4 +no_repeat_ngram_size: 2 +early_stopping: true +temperature: 0.7 +top_k: 150 +top_p: 0.92 +repetition_penalty: 4.5 diff --git a/server.py b/server.py index 72d0923..1bfd304 100644 --- a/server.py +++ b/server.py @@ -103,12 +103,11 @@ def load_preset_values(preset_menu, state, return_dict=False): 'mirostat_eta': 0.1, } - with open(Path(f'presets/{preset_menu}.txt'), 'r') as infile: - preset = infile.read() - for i in preset.splitlines(): - i = i.rstrip(',').strip().split('=') - if len(i) == 2 and i[0].strip() != 'tokens': - generate_params[i[0].strip()] = eval(i[1].strip()) + with open(Path(f'presets/{preset_menu}.yaml'), 'r') as infile: + preset = yaml.safe_load(infile) + + for k in preset: + generate_params[k] = preset[k] generate_params['temperature'] = min(1.99, generate_params['temperature']) if return_dict: @@ -301,7 +300,7 @@ def save_model_settings(model, state): shared.model_config[model_regex][k] = state[k] with open(p, 'w') as f: - f.write(yaml.dump(user_config)) + f.write(yaml.dump(user_config, sort_keys=False)) yield (f"Settings for {model} saved to {p}") @@ -551,11 +550,8 @@ def create_interface(): # Defining some variables gen_events = [] - default_preset = shared.settings['presets'][next((k for k in shared.settings['presets'] if re.match(k.lower(), shared.model_name.lower())), 'default')] - if len(shared.lora_names) == 1: - default_text = load_prompt(shared.settings['prompts'][next((k for k in shared.settings['prompts'] if re.match(k.lower(), shared.lora_names[0].lower())), 'default')]) - else: - default_text = load_prompt(shared.settings['prompts'][next((k for k in shared.settings['prompts'] if re.match(k.lower(), shared.model_name.lower())), 'default')]) + default_preset = shared.settings['preset'] + default_text = load_prompt(shared.settings['prompt']) title = 'Text generation web UI' # Authentication variables @@ -1016,16 +1012,19 @@ if __name__ == "__main__": settings_file = None if shared.args.settings is not None and Path(shared.args.settings).exists(): settings_file = Path(shared.args.settings) + elif Path('settings.yaml').exists(): + settings_file = Path('settings.yaml') elif Path('settings.json').exists(): settings_file = Path('settings.json') if settings_file is not None: logger.info(f"Loading settings from {settings_file}...") - new_settings = json.loads(open(settings_file, 'r').read()) + file_contents = open(settings_file, 'r', encoding='utf-8').read() + new_settings = json.loads(file_contents) if settings_file.suffix == "json" else yaml.safe_load(file_contents) for item in new_settings: shared.settings[item] = new_settings[item] - # Set default model settings based on settings.json + # Set default model settings based on settings file shared.model_config['.*'] = { 'wbits': 'None', 'model_type': 'None', diff --git a/settings-template.json b/settings-template.json deleted file mode 100644 index 0860d85..0000000 --- a/settings-template.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "dark_theme": false, - "autoload_model": true, - "max_new_tokens": 200, - "max_new_tokens_min": 1, - "max_new_tokens_max": 2000, - "seed": -1, - "character": "None", - "name1": "You", - "name2": "Assistant", - "context": "This is a conversation with your Assistant. It is a computer program designed to help you with various tasks such as answering questions, providing recommendations, and helping with decision making. You can ask it anything you want and it will do its best to give you accurate and relevant information.", - "greeting": "", - "turn_template": "", - "custom_stopping_strings": "", - "stop_at_newline": false, - "add_bos_token": true, - "ban_eos_token": false, - "skip_special_tokens": true, - "truncation_length": 2048, - "truncation_length_min": 0, - "truncation_length_max": 8192, - "mode": "chat", - "chat_style": "cai-chat", - "instruction_template": "None", - "chat-instruct_command": "Continue the chat dialogue below. Write a single reply for the character \"<|character|>\".\n\n<|prompt|>", - "chat_prompt_size": 2048, - "chat_prompt_size_min": 0, - "chat_prompt_size_max": 2048, - "chat_generation_attempts": 1, - "chat_generation_attempts_min": 1, - "chat_generation_attempts_max": 10, - "default_extensions": [], - "chat_default_extensions": [ - "gallery" - ], - "presets": { - "default": "Default", - ".*(alpaca|llama|llava|vicuna)": "LLaMA-Precise", - ".*pygmalion": "NovelAI-Storywriter", - ".*RWKV.*\.pth": "Naive", - ".*moss": "MOSS" - }, - "prompts": { - "default": "QA", - ".*(gpt4chan|gpt-4chan|4chan)": "GPT-4chan" - } -} diff --git a/settings-template.yaml b/settings-template.yaml new file mode 100644 index 0000000..aba2f48 --- /dev/null +++ b/settings-template.yaml @@ -0,0 +1,42 @@ +dark_theme: false +autoload_model: true +max_new_tokens: 200 +max_new_tokens_min: 1 +max_new_tokens_max: 2000 +seed: -1 +character: None +name1: You +name2: Assistant +context: This is a conversation with your Assistant. It is a computer program designed + to help you with various tasks such as answering questions, providing recommendations, + and helping with decision making. You can ask it anything you want and it will do + its best to give you accurate and relevant information. +greeting: '' +turn_template: '' +custom_stopping_strings: '' +stop_at_newline: false +add_bos_token: true +ban_eos_token: false +skip_special_tokens: true +truncation_length: 2048 +truncation_length_min: 0 +truncation_length_max: 8192 +mode: chat +chat_style: cai-chat +instruction_template: None +chat-instruct_command: 'Continue the chat dialogue below. Write a single reply for + the character "<|character|>". + + + <|prompt|>' +chat_prompt_size: 2048 +chat_prompt_size_min: 0 +chat_prompt_size_max: 2048 +chat_generation_attempts: 1 +chat_generation_attempts_min: 1 +chat_generation_attempts_max: 10 +default_extensions: [] +chat_default_extensions: +- gallery +preset: LLaMA-Precise +prompt: QA