Gaivoronsky commited on
Commit
d3d4e31
1 Parent(s): 3eb2551

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +47 -1
README.md CHANGED
@@ -28,10 +28,56 @@ import openai
28
  openai.api_base = "http://localhost:8000/v1"
29
  openai.api_key = "none"
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  response = openai.ChatCompletion.create(
32
  model="Gaivoronsky/Mistral-7B-Saiga",
33
- messages=[{"role": "user", "content": 'Сколько весит жираф?'}],
34
  max_tokens=512,
 
35
  )
36
  response['choices'][0]['message']['content']
37
  ```
 
28
  openai.api_base = "http://localhost:8000/v1"
29
  openai.api_key = "none"
30
 
31
+ DEFAULT_MESSAGE_TEMPLATE = "<s>{role}\n{content}</s>"
32
+ DEFAULT_RESPONSE_TEMPLATE = "<s>bot\n"
33
+ DEFAULT_SYSTEM_PROMPT = "Ты — Сайга, русскоязычный автоматический ассистент. Ты разговариваешь с людьми и помогаешь им."
34
+
35
+
36
+ class Conversation:
37
+ def __init__(
38
+ self,
39
+ message_template=DEFAULT_MESSAGE_TEMPLATE,
40
+ system_prompt=DEFAULT_SYSTEM_PROMPT,
41
+ response_template=DEFAULT_RESPONSE_TEMPLATE
42
+ ):
43
+ self.message_template = message_template
44
+ self.response_template = response_template
45
+ self.messages = [{
46
+ "role": "system",
47
+ "content": system_prompt
48
+ }]
49
+
50
+ def add_user_message(self, message):
51
+ self.messages.append({
52
+ "role": "user",
53
+ "content": message
54
+ })
55
+
56
+ def add_bot_message(self, message):
57
+ self.messages.append({
58
+ "role": "bot",
59
+ "content": message
60
+ })
61
+
62
+ def get_prompt(self):
63
+ final_text = ""
64
+ for message in self.messages:
65
+ message_text = self.message_template.format(**message)
66
+ final_text += message_text
67
+ final_text += DEFAULT_RESPONSE_TEMPLATE
68
+ return final_text.strip()
69
+
70
+
71
+ query = "Сколько весит жираф?"
72
+ conversation = Conversation()
73
+ conversation.add_user_message(query)
74
+ prompt = conversation.get_prompt()
75
+
76
  response = openai.ChatCompletion.create(
77
  model="Gaivoronsky/Mistral-7B-Saiga",
78
+ messages=[{"role": "user", "content": prompt}],
79
  max_tokens=512,
80
+ stop=['</s>']
81
  )
82
  response['choices'][0]['message']['content']
83
  ```