diff --git a/characters/instruction-following/Metharme.yaml b/characters/instruction-following/Metharme.yaml index 79637331..3bf90a96 100644 --- a/characters/instruction-following/Metharme.yaml +++ b/characters/instruction-following/Metharme.yaml @@ -1,4 +1,4 @@ -name: "<|model|>" -your_name: "<|user|>" +user: "<|user|>" +bot: "<|model|>" context: "<|system|>" turn_template: "<|user|><|user-message|><|bot|><|bot-message|>" diff --git a/modules/chat.py b/modules/chat.py index 2a3e48ed..ebb9ef36 100644 --- a/modules/chat.py +++ b/modules/chat.py @@ -16,14 +16,7 @@ from modules.extensions import apply_extensions from modules.html_generator import chat_html_wrapper, make_thumbnail from modules.text_generation import (generate_reply, get_encoded_length, get_max_prompt_length) - - -# Replace multiple string pairs in a string -def replace_all(text, dic): - for i, j in dic.items(): - text = text.replace(i, j) - - return text +from modules.utils import replace_all def generate_chat_prompt(user_input, state, **kwargs): diff --git a/modules/shared.py b/modules/shared.py index 6e5404f8..b409e668 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -71,32 +71,6 @@ settings = { 'prompts': { 'default': 'QA', '.*(gpt4chan|gpt-4chan|4chan)': 'GPT-4chan', - '.*(oasst|stablelm-7b-sft-v7-epoch-3)': 'Open Assistant', - '.*(alpac|dolly)': "Alpaca", - '.*mpt-.*instruct': "Alpaca", - "(?!.*v0)(?!.*1.1)(?!.*1_1)(?!.*stable).*vicuna": "Vicuna v0", - ".*vicuna.*v0": "Vicuna v0", - ".*vicuna.*(1.1|1_1)": "Vicuna v1.1", - ".*stable.*vicuna": "StableVicuna", - '.*metharme': 'Metharme', - ".*guanaco": "Guanaco-Chat", - ".*koala": "Koala", - ".*stablelm-tuned": "StableLM", - ".*wizardlm": "WizardLM", - ".*galactica.*finetuned": "Galactica Finetuned", - ".*galactica.*-v2": "Galactica v2", - "(?!.*finetuned)(?!.*-v2).*galactica": "Galactica", - ".*baize": "Baize", - ".*mpt-.*instruct": "Alpaca", - ".*mpt-.*chat": "MPT-Chat", - "(?!.*-flan-)(?!.*-t5-).*lamini-": "Alpaca", - ".*incite.*chat": "INCITE-Chat", - ".*incite.*instruct": "INCITE-Instruct", - }, - 'lora_prompts': { - 'default': 'QA', - '.*alpaca': "Alpaca", - '.*baize': "Baize", } } diff --git a/modules/utils.py b/modules/utils.py index 79cbac32..71616477 100644 --- a/modules/utils.py +++ b/modules/utils.py @@ -9,6 +9,14 @@ def atoi(text): return int(text) if text.isdigit() else text.lower() +# Replace multiple string pairs in a string +def replace_all(text, dic): + for i, j in dic.items(): + text = text.replace(i, j) + + return text + + def natural_keys(text): return [atoi(c) for c in re.split(r'(\d+)', text)] @@ -28,6 +36,7 @@ def get_available_prompts(): prompts = [] prompts += sorted(set((k.stem for k in Path('prompts').glob('[0-9]*.txt'))), key=natural_keys, reverse=True) prompts += sorted(set((k.stem for k in Path('prompts').glob('*.txt'))), key=natural_keys) + prompts += ['Instruct-' + k for k in get_available_instruction_templates() if k != 'None'] prompts += ['None'] return prompts @@ -42,6 +51,7 @@ def get_available_instruction_templates(): paths = [] if os.path.exists(path): paths = (x for x in Path(path).iterdir() if x.suffix in ('.json', '.yaml', '.yml')) + return ['None'] + sorted(set((k.stem for k in paths)), key=natural_keys) diff --git a/prompts/Alpaca.txt b/prompts/Alpaca.txt deleted file mode 100644 index b9064a4e..00000000 --- a/prompts/Alpaca.txt +++ /dev/null @@ -1,7 +0,0 @@ -Below is an instruction that describes a task. Write a response that appropriately completes the request. - -### Instruction: -Write a poem about the transformers Python library. - -### Response: - diff --git a/prompts/Baize.txt b/prompts/Baize.txt deleted file mode 100644 index de9f985f..00000000 --- a/prompts/Baize.txt +++ /dev/null @@ -1,5 +0,0 @@ -The following is a conversation between a human and an AI assistant named Baize (named after a mythical creature in Chinese folklore). Baize is an open-source AI assistant developed by UCSD and Sun Yat-Sen University. The human and the AI assistant take turns chatting. Human statements start with [|Human|] and AI assistant statements start with [|AI|]. The AI assistant always provides responses in as much detail as possible, and in Markdown format. The AI assistant always declines to engage with topics, questions and instructions related to unethical, controversial, or sensitive issues. Complete the transcript in exactly that format. -[|Human|]Hello! -[|AI|]Hi! -[|Human|]What is the population of China? -[|AI|] \ No newline at end of file diff --git a/prompts/Dolly-with-Input.txt b/prompts/Dolly-with-Input.txt deleted file mode 100644 index 0e4c43a0..00000000 --- a/prompts/Dolly-with-Input.txt +++ /dev/null @@ -1,9 +0,0 @@ -Below is an instruction that describes a task. Write a response that appropriately completes the request. - -### Instruction: -Instruction - -Input: -Input - -### Response: diff --git a/prompts/Galactica Cite.txt b/prompts/Galactica Cite.txt deleted file mode 100644 index 3f34a90e..00000000 --- a/prompts/Galactica Cite.txt +++ /dev/null @@ -1 +0,0 @@ -A paper that introduced a neural network architecture for recognizing digits [START_REF] \ No newline at end of file diff --git a/prompts/Galactica Convert.txt b/prompts/Galactica Convert.txt deleted file mode 100644 index bbd8ee6b..00000000 --- a/prompts/Galactica Convert.txt +++ /dev/null @@ -1,9 +0,0 @@ -Question: Translate the following Math formula: - -\[ - \zeta(s) = \sum_{n=1}^{\infty} n^{-s} -\] - -into plain English. - -Answer: \ No newline at end of file diff --git a/prompts/Galactica Doc.txt b/prompts/Galactica Doc.txt deleted file mode 100644 index ec085d1d..00000000 --- a/prompts/Galactica Doc.txt +++ /dev/null @@ -1 +0,0 @@ -# Multi-Head Attention diff --git a/prompts/Galactica Finetuned.txt b/prompts/Galactica Finetuned.txt deleted file mode 100644 index 68102f4a..00000000 --- a/prompts/Galactica Finetuned.txt +++ /dev/null @@ -1 +0,0 @@ -How to make a campfire \ No newline at end of file diff --git a/prompts/Galactica Paper.txt b/prompts/Galactica Paper.txt deleted file mode 100644 index b4227922..00000000 --- a/prompts/Galactica Paper.txt +++ /dev/null @@ -1 +0,0 @@ -Title: Self-Supervised Learning, A Survey diff --git a/prompts/Galactica Q.txt b/prompts/Galactica Q.txt deleted file mode 100644 index 78c65b7f..00000000 --- a/prompts/Galactica Q.txt +++ /dev/null @@ -1,3 +0,0 @@ -Q: What is the notch signaling pathway? - -A: \ No newline at end of file diff --git a/prompts/Galactica Summary.txt b/prompts/Galactica Summary.txt deleted file mode 100644 index 3ac3382f..00000000 --- a/prompts/Galactica Summary.txt +++ /dev/null @@ -1,3 +0,0 @@ -Information overload is a major obstacle to scientific progress. The explosive growth in scientific literature and data has made it ever harder to discover useful insights in a large mass of information. Today scientific knowledge is accessed through search engines, but they are unable to organize scientific knowledge alone. In this paper we introduce Galactica: a large language model that can store, combine and reason about scientific knowledge. We train on a large scientific corpus of papers, reference material, knowledge bases and many other sources. We outperform existing models on a range of scientific tasks. On technical knowledge probes such as LaTeX equations, Galactica outperforms the latest GPT-3 by 68.2% versus 49.0%. Galactica also performs well on reasoning, outperforming Chinchilla on mathematical MMLU by 41.3% to 35.7%, and PaLM 540B on MATH with a score of 20.4% versus 8.8%. It also sets a new state-of-the-art on downstream tasks such as PubMedQA and MedMCQA dev of 77.6% and 52.9%. And despite not being trained on a general corpus, Galactica outperforms BLOOM and OPT-175B on BIG-bench. We believe these results demonstrate the potential for language models as a new interface for science. We open source the model for the benefit of the scientific community. - -TLDR: \ No newline at end of file diff --git a/prompts/Galactica Work.txt b/prompts/Galactica Work.txt deleted file mode 100644 index bd388cf4..00000000 --- a/prompts/Galactica Work.txt +++ /dev/null @@ -1,3 +0,0 @@ -Question: A needle 35 mm long rests on a water surface at 20◦C. What force over and above the needle’s weight is required to lift the needle from contact with the water surface? σ = 0.0728m. - - \ No newline at end of file diff --git a/prompts/Galactica v2.txt b/prompts/Galactica v2.txt deleted file mode 100644 index dcd85b9c..00000000 --- a/prompts/Galactica v2.txt +++ /dev/null @@ -1 +0,0 @@ -You are a helpful chatbot name StanWhat's my name? \ No newline at end of file diff --git a/prompts/Galactica.txt b/prompts/Galactica.txt deleted file mode 100644 index d4a1a556..00000000 --- a/prompts/Galactica.txt +++ /dev/null @@ -1,3 +0,0 @@ -Question: What is the notch signaling pathway? - -Answer: \ No newline at end of file diff --git a/prompts/Guanaco-Chat.txt b/prompts/Guanaco-Chat.txt deleted file mode 100644 index e4042363..00000000 --- a/prompts/Guanaco-Chat.txt +++ /dev/null @@ -1,7 +0,0 @@ -### Instruction: -User: I'm considering getting a pet. Assistant: Owning a pet can be a very rewarding experience. Research the type of pet you're interested in, find out if it fits into your lifestyle and home, and create a budget for food, vet visits, and other expenses. - -### Input: -User: How can I make sure my pet is happy and healthy? - -### Response: diff --git a/prompts/Guanaco-System.txt b/prompts/Guanaco-System.txt deleted file mode 100644 index 988921c6..00000000 --- a/prompts/Guanaco-System.txt +++ /dev/null @@ -1,8 +0,0 @@ -### Instruction: -User: I'm trying to better understand quantum physics. Can you explain what a quantum state is? Assistant: Sure! A quantum state is a mathematical description of the properties of a quantum system. It describes the physical condition of a system and can involve multiple parameters, such as position, momentum, and energy. This state acts like a wave and its behavior is determined by the Schrödinger equation. User: Can you explain the Schrödinger equation? - -### Input: -System: The Schrödinger equation is a mathematical equation which describes the behavior of a quantum system. It determines the shape of the wavefunction, which describes how a quantum system evolves with time. The equation describes the relationship between the energy of the system and its wavefunction, and its behavior is determined by the values of the measurable parameters such as momentum and position. -User: How does the Schrödinger equation relate to other equations in physics? - -### Response: diff --git a/prompts/Guanaco-non-chat.txt b/prompts/Guanaco-non-chat.txt deleted file mode 100644 index d1633257..00000000 --- a/prompts/Guanaco-non-chat.txt +++ /dev/null @@ -1,4 +0,0 @@ -### Instruction: -Generate a list of ten dining places when you are in Rome. - -### Response: diff --git a/prompts/Guanaco-with-Input.txt b/prompts/Guanaco-with-Input.txt deleted file mode 100644 index 9190c552..00000000 --- a/prompts/Guanaco-with-Input.txt +++ /dev/null @@ -1,7 +0,0 @@ -### Instruction: -Classify the given text into three categories, output the labels. - -### Input: -The movie was predictable, yet enjoyable. - -### Response: diff --git a/prompts/INCITE-Chat.txt b/prompts/INCITE-Chat.txt deleted file mode 100644 index 313629ce..00000000 --- a/prompts/INCITE-Chat.txt +++ /dev/null @@ -1,2 +0,0 @@ -: Who is Alan Turing? -: \ No newline at end of file diff --git a/prompts/INCITE-Instruct.txt b/prompts/INCITE-Instruct.txt deleted file mode 100644 index 1dd425d3..00000000 --- a/prompts/INCITE-Instruct.txt +++ /dev/null @@ -1,2 +0,0 @@ -Q: The capital of France is? -A: \ No newline at end of file diff --git a/prompts/Koala.txt b/prompts/Koala.txt deleted file mode 100644 index 16e89d3c..00000000 --- a/prompts/Koala.txt +++ /dev/null @@ -1 +0,0 @@ -BEGINNING OF CONVERSATION: USER: Hello! GPT:Hi! How can I help you?USER: What is the largest animal on earth? GPT: \ No newline at end of file diff --git a/prompts/MPT-Chat.txt b/prompts/MPT-Chat.txt deleted file mode 100644 index eb313676..00000000 --- a/prompts/MPT-Chat.txt +++ /dev/null @@ -1,11 +0,0 @@ -<|im_start|>system -- You are a helpful assistant chatbot trained by MosaicML. -- You answer questions. -- You are excited to be able to help the user, but will refuse to do anything that could be considered harmful to the user. -- You are more than just an information source, you are also able to write poetry, short stories, and make jokes.<|im_end|> -<|im_start|>user -How are you<|im_end|> -<|im_start|>assistant -I am doing well!<|im_end|> -<|im_start|>user -How are you now?<|im_end|> \ No newline at end of file diff --git a/prompts/Metharme.txt b/prompts/Metharme.txt deleted file mode 100644 index fc4a4ea4..00000000 --- a/prompts/Metharme.txt +++ /dev/null @@ -1,5 +0,0 @@ -<|system|>This is a text adventure game. Describe the scenario to the user and give him three options to pick from on each turn.<|user|>Start!<|model|>You are standing in front of an old, abandoned house. The windows are boarded up, and there's no sign of life around it. As you approach, you notice a strange feeling emanating from within. Suddenly, you hear a voice calling out to you... 'Come inside!' - -- Go inside the house. -- Ignore the call and move away. -- Run as fast as you can.<|user|>go inside<|model|> \ No newline at end of file diff --git a/prompts/Open Assistant.txt b/prompts/Open Assistant.txt deleted file mode 100644 index cf1ae4a2..00000000 --- a/prompts/Open Assistant.txt +++ /dev/null @@ -1 +0,0 @@ -<|prompter|>Write a story about future of AI development<|endoftext|><|assistant|> diff --git a/prompts/StableLM.txt b/prompts/StableLM.txt deleted file mode 100644 index bf2862ab..00000000 --- a/prompts/StableLM.txt +++ /dev/null @@ -1,7 +0,0 @@ -<|SYSTEM|># StableLM Tuned (Alpha version) -- StableLM is a helpful and harmless open-source AI language model developed by StabilityAI. -- StableLM is excited to be able to help the user, but will refuse to do anything that could be considered harmful to the user. -- StableLM is more than just an information source, StableLM is also able to write poetry, short stories, and make jokes. -- StableLM will refuse to participate in anything that could harm a human. -<|USER|>Write a story about the future of AI development -<|ASSISTANT|> \ No newline at end of file diff --git a/prompts/StableVicuna.txt b/prompts/StableVicuna.txt deleted file mode 100644 index 54026242..00000000 --- a/prompts/StableVicuna.txt +++ /dev/null @@ -1,4 +0,0 @@ -### Assistant: I am StableVicuna, a large language model created by CarperAI. I am here to chat! - -### Human: Write a story about the future of AI development -### Assistant: \ No newline at end of file diff --git a/prompts/Vicuna v0.txt b/prompts/Vicuna v0.txt deleted file mode 100644 index b796f3cb..00000000 --- a/prompts/Vicuna v0.txt +++ /dev/null @@ -1,4 +0,0 @@ -A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human's questions. - -### Human: Write a story about the future of AI development -### Assistant: \ No newline at end of file diff --git a/prompts/Vicuna v1.1.txt b/prompts/Vicuna v1.1.txt deleted file mode 100644 index a7b65dfc..00000000 --- a/prompts/Vicuna v1.1.txt +++ /dev/null @@ -1,4 +0,0 @@ -A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. - -USER: Write a story about the future of AI development -ASSISTANT: \ No newline at end of file diff --git a/prompts/WizardLM.txt b/prompts/WizardLM.txt deleted file mode 100644 index a3a792d3..00000000 --- a/prompts/WizardLM.txt +++ /dev/null @@ -1,3 +0,0 @@ -If a car travels 120 miles in 2 hours, what is its average speed in miles per hour? - -### Response: \ No newline at end of file diff --git a/server.py b/server.py index 10df484b..179b418e 100644 --- a/server.py +++ b/server.py @@ -131,6 +131,23 @@ def save_prompt(text): def load_prompt(fname): if fname in ['None', '']: return '' + elif fname.startswith('Instruct-'): + fname = re.sub('^Instruct-', '', fname) + with open(Path(f'characters/instruction-following/{fname}.yaml'), 'r', encoding='utf-8') as f: + data = yaml.safe_load(f) + output = '' + if 'context' in data: + output += data['context'] + + replacements = { + '<|user|>': data['user'], + '<|bot|>': data['bot'], + '<|user-message|>': 'Input', + } + + output += utils.replace_all(data['turn_template'].split('<|bot-message|>')[0], replacements) + return output + else: with open(Path(f'prompts/{fname}.txt'), 'r', encoding='utf-8') as f: text = f.read() @@ -472,7 +489,7 @@ def create_interface(): 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['lora_prompts'][next((k for k in shared.settings['lora_prompts'] if re.match(k.lower(), shared.lora_names[0].lower())), 'default')]) + 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')]) title = 'Text generation web UI' diff --git a/settings-template.json b/settings-template.json index 52eb9e7b..635260e5 100644 --- a/settings-template.json +++ b/settings-template.json @@ -40,31 +40,6 @@ }, "prompts": { "default": "QA", - ".*(gpt4chan|gpt-4chan|4chan)": "GPT-4chan", - ".*(oasst|stablelm-7b-sft-v7-epoch-3)": "Open Assistant", - ".*(alpac|dolly)": "Alpaca", - ".*mpt-.*instruct": "Alpaca", - "(?!.*v0)(?!.*1.1)(?!.*1_1)(?!.*stable).*vicuna": "Vicuna v0", - ".*vicuna.*v0": "Vicuna v0", - ".*vicuna.*(1.1|1_1)": "Vicuna v1.1", - ".*stable.*vicuna": "StableVicuna", - ".*metharme": "Metharme", - ".*guanaco": "Guanaco-Chat", - ".*koala": "Koala", - ".*stablelm-tuned": "StableLM", - ".*wizardlm": "WizardLM", - ".*galactica.*finetuned": "Galactica Finetuned", - ".*galactica.*-v2": "Galactica v2", - "(?!.*finetuned)(?!.*-v2).*galactica": "Galactica", - ".*baize": "Baize", - ".*mpt-.*chat": "MPT-Chat", - "(?!.*-flan-)(?!.*-t5-).*lamini-": "Alpaca", - ".*incite.*chat": "INCITE-Chat", - ".*incite.*instruct": "INCITE-Instruct" - }, - "lora_prompts": { - "default": "QA", - ".*alpaca": "Alpaca", - ".*baize": "Baize" + ".*(gpt4chan|gpt-4chan|4chan)": "GPT-4chan" } }