template.py 1.35 KB
Newer Older
1
2
from difflib import SequenceMatcher

3
4
5
6
7
8
9
model_prompts = {
    "alpaca": "Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\n{prompt}\n\n### Response:\n\n",
    "gpt4": "### Instruction:\n{prompt}\n\n### Response:\n",
    "hermes": "### Instruction:\n{prompt}\n\n### Response:\n",
    "oasst": "{prompt}",
    "orca": "### System:\nYou are an AI assistant that follows instruction extremely well. Help as much as you can.\n\n### User:\n{prompt}\n\n### Response:",
    "qlora": "### Human: {prompt}\n### Assistant:",
Bruce MacDonald's avatar
Bruce MacDonald committed
10
    "tulu": "\n{prompt}\n\n",
11
12
13
    "vicuna": "A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.\n\nUSER: {prompt}\nASSISTANT:",
    "wizardlm": "{prompt}\n\n### Response:",
}
14
15
16
17
18
19
20
21
22
23
24
25
26


def template(model, prompt):
    max_ratio = 0
    closest_key = ""
    model_name = model.lower()
    # Find the specialized prompt with the closest name match
    for key in model_prompts.keys():
        ratio = SequenceMatcher(None, model_name, key).ratio()
        if ratio > max_ratio:
            max_ratio = ratio
            closest_key = key
    # Return the value of the closest match
Bruce MacDonald's avatar
Bruce MacDonald committed
27
    p = model_prompts.get(closest_key)  # TODO: provide a better default template
28
    return p.format(prompt=prompt)