From 0e6d17304a9fb745c91d4f95764ce521b6b4f9bb Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Wed, 3 May 2023 22:50:39 -0300 Subject: [PATCH] Clearer syntax for instruction-following characters --- characters/instruction-following/Alpaca.yaml | 6 +++--- characters/instruction-following/ChatGLM.yaml | 6 +++--- characters/instruction-following/Koala.yaml | 6 +++--- characters/instruction-following/LLaVA.yaml | 8 ++++---- .../instruction-following/Open Assistant.yaml | 4 ++-- characters/instruction-following/RWKV-Raven.yaml | 4 ++-- characters/instruction-following/Vicuna-v0.yaml | 6 +++--- characters/instruction-following/Vicuna-v1.yaml | 6 +++--- docs/Custom-chat-characters.md | 5 +++-- modules/chat.py | 15 ++++++++++++--- 10 files changed, 38 insertions(+), 28 deletions(-) diff --git a/characters/instruction-following/Alpaca.yaml b/characters/instruction-following/Alpaca.yaml index 4379d02b..f8a7d61a 100644 --- a/characters/instruction-following/Alpaca.yaml +++ b/characters/instruction-following/Alpaca.yaml @@ -1,4 +1,4 @@ -name: "### Response:" -your_name: "### Instruction:" -context: "Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n" +user: "### Instruction:" +bot: "### Response:" turn_template: "<|user|>\n<|user-message|>\n\n<|bot|>\n<|bot-message|>\n\n" +context: "Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n" diff --git a/characters/instruction-following/ChatGLM.yaml b/characters/instruction-following/ChatGLM.yaml index aed51eb9..0e5d3f41 100644 --- a/characters/instruction-following/ChatGLM.yaml +++ b/characters/instruction-following/ChatGLM.yaml @@ -1,4 +1,4 @@ -name: "答:" -your_name: "[Round <|round|>]\n问:" -context: "" +user: "[Round <|round|>]\n问:" +bot: "答:" turn_template: "<|user|><|user-message|>\n<|bot|><|bot-message|>\n" +context: "" diff --git a/characters/instruction-following/Koala.yaml b/characters/instruction-following/Koala.yaml index c0f64098..db4ee0ef 100644 --- a/characters/instruction-following/Koala.yaml +++ b/characters/instruction-following/Koala.yaml @@ -1,4 +1,4 @@ -name: "GPT:" -your_name: "USER:" -context: "BEGINNING OF CONVERSATION: " +user: "USER:" +bot: "GPT:" turn_template: "<|user|> <|user-message|> <|bot|><|bot-message|>" +context: "BEGINNING OF CONVERSATION: " diff --git a/characters/instruction-following/LLaVA.yaml b/characters/instruction-following/LLaVA.yaml index 7a8cf1d3..ecaf0288 100644 --- a/characters/instruction-following/LLaVA.yaml +++ b/characters/instruction-following/LLaVA.yaml @@ -1,4 +1,4 @@ -name: "### Assistant" -your_name: "### Human" -context: "You are LLaVA, a large language and vision assistant trained by UW Madison WAIV Lab. You are able to understand the visual content that the user provides, and assist the user with a variety of tasks using natural language. Follow the instructions carefully and explain your answers in detail.\n### Human: \nHi!\n### Assistant: \nHi there! How can I help you today?\n" -turn_template: "<|user|>\n<|user-message|>\n<|bot|>\n<|bot-message|>\n" \ No newline at end of file +user: "### Human" +bot: "### Assistant" +turn_template: "<|user|>\n<|user-message|>\n<|bot|>\n<|bot-message|>\n" +context: "You are LLaVA, a large language and vision assistant trained by UW Madison WAIV Lab. You are able to understand the visual content that the user provides, and assist the user with a variety of tasks using natural language. Follow the instructions carefully and explain your answers in detail.\n### Human: \nHi!\n### Assistant: \nHi there! How can I help you today?\n" \ No newline at end of file diff --git a/characters/instruction-following/Open Assistant.yaml b/characters/instruction-following/Open Assistant.yaml index bf199517..edc1e819 100644 --- a/characters/instruction-following/Open Assistant.yaml +++ b/characters/instruction-following/Open Assistant.yaml @@ -1,3 +1,3 @@ -name: "<|assistant|>" -your_name: "<|prompter|>" +user: "<|prompter|>" +bot: "<|assistant|>" turn_template: "<|user|><|user-message|><|endoftext|><|bot|><|bot-message|><|endoftext|>" diff --git a/characters/instruction-following/RWKV-Raven.yaml b/characters/instruction-following/RWKV-Raven.yaml index c35bab92..6b1ce170 100644 --- a/characters/instruction-following/RWKV-Raven.yaml +++ b/characters/instruction-following/RWKV-Raven.yaml @@ -1,3 +1,3 @@ -name: "Alice:" -your_name: "Bob:" +user: "Bob:" +bot: "Alice:" turn_template: "<|user|> <|user-message|>\n\n<|bot|> <|bot-message|>\n\n" diff --git a/characters/instruction-following/Vicuna-v0.yaml b/characters/instruction-following/Vicuna-v0.yaml index 43b2a28c..a162bdaa 100644 --- a/characters/instruction-following/Vicuna-v0.yaml +++ b/characters/instruction-following/Vicuna-v0.yaml @@ -1,4 +1,4 @@ -name: "### Assistant:" -your_name: "### Human:" -context: "A chat between a human and an assistant.\n\n" +user: "### Human:" +bot: "### Assistant:" turn_template: "<|user|> <|user-message|>\n<|bot|> <|bot-message|>\n" +context: "A chat between a human and an assistant.\n\n" diff --git a/characters/instruction-following/Vicuna-v1.yaml b/characters/instruction-following/Vicuna-v1.yaml index 9b00b764..2761d874 100644 --- a/characters/instruction-following/Vicuna-v1.yaml +++ b/characters/instruction-following/Vicuna-v1.yaml @@ -1,4 +1,4 @@ -name: "ASSISTANT:" -your_name: "USER:" -context: "A chat between a user and an assistant.\n\n" +user: "USER:" +bot: "ASSISTANT:" turn_template: "<|user|> <|user-message|>\n<|bot|> <|bot-message|>\n" +context: "A chat between a user and an assistant.\n\n" diff --git a/docs/Custom-chat-characters.md b/docs/Custom-chat-characters.md index b25a2294..eeb22d1c 100644 --- a/docs/Custom-chat-characters.md +++ b/docs/Custom-chat-characters.md @@ -4,11 +4,12 @@ The following fields may be defined: | Field | Description | |-------|-------------| -| `name` | The character's name. | +| `name` or `bot` | The character's name. | +| `your_name` or `user` (optional) | Your name. This overwrites what you had previously written in the `Your name` field in the interface. | | `context` | A string that appears at the top of the prompt. It usually contains a description of the character's personality. | | `greeting` (optional) | The character's opening message when a new conversation is started. | | `example_dialogue` (optional) | A few example messages to guide the model. | -| `your_name` (optional) | Your name. This overwrites what you had previously written in the `Your name` field in the interface. | +| `turn_template` (optional) | Used to define where the spaces and new line characters should be in Instruct mode. See the characters in `characters/instruction-following` for examples. | #### Special tokens diff --git a/modules/chat.py b/modules/chat.py index c17f4545..98e171b0 100644 --- a/modules/chat.py +++ b/modules/chat.py @@ -455,9 +455,18 @@ def load_character(character, name1, name2, mode): file_contents = open(filepath, 'r', encoding='utf-8').read() data = json.loads(file_contents) if extension == "json" else yaml.safe_load(file_contents) - name2 = data['name'] if 'name' in data else data['char_name'] - if 'your_name' in data and data['your_name'] != '': - name1 = data['your_name'] + + # Finding the bot's name + for k in ['name', 'bot', '<|bot|>', 'char_name']: + if k in data and data[k] != '': + name2 = data[k] + break + + # Find the user name (if any) + for k in ['your_name', 'user', '<|user|>']: + if k in data and data[k] != '': + name1 = data[k] + break else: name1 = shared.settings['name1']