-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.py
83 lines (71 loc) · 2.77 KB
/
template.py
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
def parse_example(example: dict[str, str]) -> tuple[str, str, str, str]:
question = example['question'].replace('\n\n', '\n').strip()
choices_prompt = ''
for i in range(6):
choice = chr(i + ord('A'))
if example[choice] is not None:
choices_prompt += f'({choice}) {example[choice]}\n'
else:
break
answer = example['answer'].strip()
choices_prompt = choices_prompt.strip()
cot = example['explanation'].strip()
return question, choices_prompt, answer, cot
def hf_template(example: dict[str, str], use_cot: bool = False, include_ans: bool = False) -> str:
question, choices_prompt, answer, cot = parse_example(example)
full_prompt = f'問題:{question}\n{choices_prompt}'
if include_ans:
if use_cot:
full_prompt += f'\n讓我們一步一步思考。\n{cot}\n正確答案:({answer})'
else:
full_prompt += f'\n正確答案:({answer})'
else:
if use_cot:
full_prompt += ''
return full_prompt
def openai_template(
example: dict[str, str], use_cot: bool = False, include_ans: bool = False
) -> str:
question, choices_prompt, answer, cot = parse_example(example)
full_prompt = f'問題:{question}\n{choices_prompt}'
if include_ans:
if use_cot:
full_prompt += f'\n讓我們一步一步思考。\n{cot}\n正確答案:({answer})'
else:
full_prompt += f'\n正確答案:({answer})'
else:
if use_cot:
full_prompt += '\n讓我們一步一步思考。\n'
else:
full_prompt += '\n正確答案:('
return full_prompt
def anthropic_template(
example: dict[str, str], use_cot: bool = False, include_ans: bool = False
) -> str:
question, choices_prompt, answer, cot = parse_example(example)
full_prompt = f'問題:{question}\n{choices_prompt}'
if include_ans:
if use_cot:
full_prompt += f'\n讓我們一步一步思考。\n{cot}\n正確答案:({answer})'
else:
full_prompt += f'\n正確答案:({answer})'
else:
if use_cot:
full_prompt += ''
return full_prompt
def google_template(
example: dict[str, str], use_cot: bool = False, include_ans: bool = False
) -> str:
question, choices_prompt, answer, cot = parse_example(example)
full_prompt = f'問題:{question}\n{choices_prompt}'
if include_ans:
if use_cot:
full_prompt += f'\n讓我們一步一步思考。\n{cot}\n正確答案:({answer})'
else:
full_prompt += f'\n正確答案:({answer})'
else:
if use_cot:
full_prompt += '\n讓我們一步一步思考。\n'
else:
full_prompt += '\n正確答案:('
return full_prompt