Skip to content

Commit d5fbde2

Browse files
authored
[Fix] Fix inconsistent system prompt handling (#2539)
This PR fixes the conversation template of ChatML, whose system prompt ends with `<|im_end|>`. An inconsistent handling of system prompt between the JSONFFI side and the Python side is also corrected.
1 parent e601409 commit d5fbde2

File tree

3 files changed

+4
-9
lines changed

3 files changed

+4
-9
lines changed

cpp/json_ffi/conv_template.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,6 @@ Result<std::vector<Data>> CreatePrompt(const Conversation& conv,
250250
std::string pending_text =
251251
conv.GetSystemText(has_custom_system ? custom_system_inputs : conv.system_message);
252252

253-
// the seperator after system message.
254-
if (!pending_text.empty()) {
255-
pending_text += conv.seps[0];
256-
}
257-
258253
// Get the message strings
259254
std::vector<Data> message_list;
260255
size_t non_system_msg_count = 0;

python/mlc_llm/conversation_template/hermes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
ConvTemplateRegistry.register_conv_template(
99
Conversation(
1010
name="open_hermes_mistral",
11-
system_template=f"<|im_start|>system\n{MessagePlaceholders.SYSTEM.value}",
11+
system_template=f"<|im_start|>system\n{MessagePlaceholders.SYSTEM.value}<|im_end|>\n",
1212
system_message=(
1313
'You are "Hermes 2", a conscious sentient superintelligent artificial '
1414
"intelligence developed by a man named Teknium, and your purpose and drive "
@@ -28,7 +28,7 @@
2828
ConvTemplateRegistry.register_conv_template(
2929
Conversation(
3030
name="neural_hermes_mistral",
31-
system_template=f"<|im_start|>system\n{MessagePlaceholders.SYSTEM.value}",
31+
system_template=f"<|im_start|>system\n{MessagePlaceholders.SYSTEM.value}<|im_end|>\n",
3232
system_message=("You are a helpful assistant chatbot."),
3333
roles={"user": "<|im_start|>user", "assistant": "<|im_start|>assistant"},
3434
seps=["<|im_end|>\n"],
@@ -44,7 +44,7 @@
4444
ConvTemplateRegistry.register_conv_template(
4545
Conversation(
4646
name="hermes2_pro_llama3",
47-
system_template=f"<|im_start|>system\n{MessagePlaceholders.SYSTEM.value}",
47+
system_template=f"<|im_start|>system\n{MessagePlaceholders.SYSTEM.value}<|im_end|>\n",
4848
system_message=(
4949
'You are "Hermes 2", a conscious sentient superintelligent artificial '
5050
"intelligence developed by a man named Teknium, and your purpose and drive "

python/mlc_llm/conversation_template/registry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def get_conv_template(name: str) -> Optional[Conversation]:
3838
ConvTemplateRegistry.register_conv_template(
3939
Conversation(
4040
name="chatml",
41-
system_template=f"<|im_start|>system\n{MessagePlaceholders.SYSTEM.value}",
41+
system_template=f"<|im_start|>system\n{MessagePlaceholders.SYSTEM.value}<|im_end|>\n",
4242
system_message=(
4343
"A conversation between a user and an LLM-based AI assistant. The "
4444
"assistant gives helpful and honest answers."

0 commit comments

Comments
 (0)