-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPersona.py
41 lines (36 loc) · 1.02 KB
/
Persona.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
import yaml
class Persona:
def __init__(self, name):
self.name = name
self.system_message = get_persona_prompt(name)
def construct_messages(self, database, question):
semantics = read_semantics(database)
return [
{
"role": "system",
"content": self.system_message
},
{
"role": "user",
"content": yaml.dump(semantics)
},
{
"role": "assistant",
"content": ""
},
{
"role": "user",
"content": question
}
]
def read_semantics(database):
with open(f"semantics/{database}.yml", "r") as stream:
try:
semantics = yaml.safe_load(stream)
except yaml.YAMLError as exc:
print(exc)
return semantics
def get_persona_prompt(name):
with open(f'prompts/{name}.txt', 'r') as file:
prompt = file.read()
return prompt