Hansimov commited on
Commit
dc3b7a9
1 Parent(s): 4a9e46f

:boom: [Fix] Revert chat templates with mannual version as nous-mixtral-8x7b behaves weirdly

Browse files
Files changed (1) hide show
  1. messagers/message_composer.py +34 -0
messagers/message_composer.py CHANGED
@@ -91,6 +91,40 @@ class MessageComposer:
91
  self.cached_str = f"[INST] {content} [/INST]"
92
  if self.cached_str:
93
  self.merged_str += f"{self.cached_str}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  # https://huggingface.co/google/gemma-7b-it#chat-template
95
  elif self.model in ["gemma-7b"]:
96
  self.messages = self.concat_messages_by_role(messages)
 
91
  self.cached_str = f"[INST] {content} [/INST]"
92
  if self.cached_str:
93
  self.merged_str += f"{self.cached_str}"
94
+ # https://huggingface.co/NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO#prompt-format
95
+ elif self.model in ["nous-mixtral-8x7b"]:
96
+ self.merged_str_list = []
97
+ for message in self.messages:
98
+ role = message["role"]
99
+ content = message["content"]
100
+ if role not in ["system", "user", "assistant"]:
101
+ role = self.default_role
102
+ message_line = f"<|im_start|>{role}\n{content}<|im_end|>"
103
+ self.merged_str_list.append(message_line)
104
+ self.merged_str_list.append("<|im_start|>assistant")
105
+ self.merged_str = "\n".join(self.merged_str_list)
106
+ # https://huggingface.co/openchat/openchat-3.5-0106
107
+ elif self.model in ["openchat-3.5"]:
108
+ self.messages = self.concat_messages_by_role(messages)
109
+ self.merged_str_list = []
110
+ self.end_of_turn = "<|end_of_turn|>"
111
+ for message in self.messages:
112
+ role = message["role"]
113
+ content = message["content"]
114
+ if role in self.inst_roles:
115
+ self.merged_str_list.append(
116
+ f"GPT4 Correct User:\n{content}{self.end_of_turn}"
117
+ )
118
+ elif role in self.answer_roles:
119
+ self.merged_str_list.append(
120
+ f"GPT4 Correct Assistant:\n{content}{self.end_of_turn}"
121
+ )
122
+ else:
123
+ self.merged_str_list.append(
124
+ f"GPT4 Correct User: {content}{self.end_of_turn}"
125
+ )
126
+ self.merged_str_list.append(f"GPT4 Correct Assistant:\n")
127
+ self.merged_str = "\n".join(self.merged_str_list)
128
  # https://huggingface.co/google/gemma-7b-it#chat-template
129
  elif self.model in ["gemma-7b"]:
130
  self.messages = self.concat_messages_by_role(messages)