template.py 1.36 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from difflib import SequenceMatcher

model_prompts = {
    "alpaca": """Below is an instruction that describes a task. Write a response that appropriately completes the request.

### Instruction:
{prompt}

### Response:

""",
    "oasst": "<|prompter|>{prompt}<|endoftext|><|assistant|>",
    "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.

USER: {prompt}
ASSISTANT:""",
    "hermes": """### Instruction:
{prompt}

### Response:
""",
    "gpt4": """### Instruction:
{prompt}

### Response:
""",
    "qlora": """### Human: {prompt}
### Assistant:""",
    "tulu": """<|user|>
{prompt}
<|assistant|>
(include newline)""",
    "wizardlm-7b": """{prompt}

### Response:""",
    "wizardlm-13b": """{prompt}

### Response:""",
    "wizardlm-30b": """{prompt}

### Response:""",
}


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
    p = model_prompts.get(closest_key)  # .format(placeholder=prompt)
    return p.format(prompt=prompt)