-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprompts.py
50 lines (40 loc) · 1.88 KB
/
prompts.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
import re
from datasets import load_dataset
dataset = load_dataset('fka/awesome-chatgpt-prompts')
def _to_command(display):
res = '_'.join(display.lower().replace('/', ' ').strip().split())
res = re.sub(r'[^A-Za-z0-9_]+', '', res)
return res
PROMPTS = {}
PROMPTS["<none>"] = dict(act="<none>", prompt="") # always reset to <none> after a prompt
PROMPTS["english_translator"] = dict(act="English translator", prompt="""
I want you to act as an English translator. \
I will speak to you in any language and you will detect the language and translate it into English. \
I want you to only reply the translation and nothing else, do not write explanations. \
If the input is already in English, simplify reply with the original text. My first sentence is "Aloha!".
""")
PROMPTS["professional_rewriter"] = dict(prompt="""
Rewrite the following in a professional, friendly and concise manner.
""")
PROMPTS["email_responser"] = dict(prompt="""
Given the following received email, generate a polite and professional response.
""")
PROMPTS["----"] = dict(act="----", prompt='')
PROMPTS.update(sorted({_to_command(prompt['act']): prompt for prompt in dataset['train']}.items()))
def split_prompt(prompt):
"""Split original prompt into pure instruction prompt and first request/sentence/command
NOTE: may not accurate for some instances due to the diverse of the prompts"""
for stop in ['My first', 'my first', 'First inquiry', 'First request']:
res = prompt.rsplit(stop, maxsplit=1)
if len(res) == 2:
return res[0].strip(), stop + res[1]
return prompt, None
def test_split_prompt():
for k, v in PROMPTS.items():
instr, first = split_prompt(v['prompt'])
print(k, first)
def test_split_prompt_no_first():
for k, v in PROMPTS.items():
instr, first = split_prompt(v['prompt'])
if first is None:
print(k, instr)