-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconversation.py
40 lines (35 loc) · 1.45 KB
/
conversation.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
MODEL_NAME = "Saiga Mistal 7B GPTQ"
DEFAULT_MESSAGE_TEMPLATE = "<s>{role}\n{content}</s>"
DEFAULT_RESPONSE_TEMPLATE = "<s>bot\n"
DEFAULT_SYSTEM_PROMPT = "Ты — Ассистент по договору о долевом участии, отвечай строго по инструкции, если вопрос " \
"задается не о договоре о долевом участии, проси задавать вопросы только по теме."
class Conversation:
def __init__(
self,
message_template=DEFAULT_MESSAGE_TEMPLATE,
system_prompt=DEFAULT_SYSTEM_PROMPT,
response_template=DEFAULT_RESPONSE_TEMPLATE
):
self.message_template = message_template
self.response_template = response_template
self.messages = [{
"role": "system",
"content": system_prompt
}]
def add_user_message(self, message):
self.messages.append({
"role": "user",
"content": message
})
def add_bot_message(self, message):
self.messages.append({
"role": "bot",
"content": message
})
def get_prompt(self):
final_text = ""
for message in self.messages:
message_text = self.message_template.format(**message)
final_text += message_text
final_text += DEFAULT_RESPONSE_TEMPLATE
return final_text.strip()