test_chat_prompt.py 3.34 KB
Newer Older
Fazzie-Maqianli's avatar
Fazzie-Maqianli committed
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
import os

from transformers import AutoTokenizer
from utils import ChatPromptProcessor, Dialogue

CONTEXT = 'Below is an instruction that describes a task. Write a response that appropriately completes the request. Do not generate new instructions.'
tokenizer = AutoTokenizer.from_pretrained(os.environ['PRETRAINED_PATH'])

samples = [
    ([
        Dialogue(
            instruction='Who is the best player in the history of NBA?',
            response=
            'The best player in the history of the NBA is widely considered to be Michael Jordan. He is one of the most successful players in the league, having won 6 NBA championships with the Chicago Bulls and 5 more with the Washington Wizards. He is a 5-time MVP, 1'
        ),
        Dialogue(instruction='continue this talk', response=''),
    ], 128,
     'Below is an instruction that describes a task. Write a response that appropriately completes the request. Do not generate new instructions.\n\n### Instruction:\nWho is the best player in the history of NBA?\n\n### Response:\nThe best player in the history of the NBA is widely considered to be Michael Jordan. He is one of the most successful players in the league, having won 6 NBA championships with the Chicago Bulls and 5 more with the Washington Wizards. He is a 5-time MVP, 1\n\n### Instruction:\ncontinue this talk\n\n### Response:\n'
    ),
    ([
        Dialogue(
            instruction='Who is the best player in the history of NBA?',
            response=
            'The best player in the history of the NBA is widely considered to be Michael Jordan. He is one of the most successful players in the league, having won 6 NBA championships with the Chicago Bulls and 5 more with the Washington Wizards. He is a 5-time MVP, 1'
        ),
        Dialogue(instruction='continue this talk', response=''),
    ], 200,
     'Below is an instruction that describes a task. Write a response that appropriately completes the request. Do not generate new instructions.\n\n### Instruction:\ncontinue this talk\n\n### Response:\n'
    ),
    ([
        Dialogue(
            instruction='Who is the best player in the history of NBA?',
            response=
            'The best player in the history of the NBA is widely considered to be Michael Jordan. He is one of the most successful players in the league, having won 6 NBA championships with the Chicago Bulls and 5 more with the Washington Wizards. He is a 5-time MVP, 1'
        ),
        Dialogue(instruction='continue this talk', response=''),
    ], 211,
     'Below is an instruction that describes a task. Write a response that appropriately completes the request. Do not generate new instructions.\n\n### Instruction:\ncontinue this\n\n### Response:\n'
    ),
    ([
        Dialogue(instruction='Who is the best player in the history of NBA?', response=''),
    ], 128,
     'Below is an instruction that describes a task. Write a response that appropriately completes the request. Do not generate new instructions.\n\n### Instruction:\nWho is the best player in the history of NBA?\n\n### Response:\n'
    ),
]


def test_chat_prompt_processor():
    processor = ChatPromptProcessor(tokenizer, CONTEXT, 256)
    for history, max_new_tokens, result in samples:
        prompt = processor.preprocess_prompt(history, max_new_tokens)
        assert prompt == result


if __name__ == '__main__':
    test_chat_prompt_processor()