Skip to content

Commit 2af6880

Browse files
authored
llama-chat : reset glmedge chat template (ggml-org#13253)
* reset glmedge chat template * fix glmedge chat template
1 parent e84773a commit 2af6880

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

src/llama-chat.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ int32_t llm_chat_apply_template(
447447
if (add_ass) {
448448
ss << "<|assistant|>";
449449
}
450-
} else if (tmpl == LLM_CHAT_TEMPLATE_CHATGLM_4 || tmpl == LLM_CHAT_TEMPLATE_GLMEDGE) {
450+
} else if (tmpl == LLM_CHAT_TEMPLATE_CHATGLM_4) {
451451
ss << "[gMASK]" << "<sop>";
452452
for (auto message : chat) {
453453
std::string role(message->role);
@@ -456,6 +456,14 @@ int32_t llm_chat_apply_template(
456456
if (add_ass) {
457457
ss << "<|assistant|>\n";
458458
}
459+
} else if (tmpl == LLM_CHAT_TEMPLATE_GLMEDGE) {
460+
for (auto message : chat) {
461+
std::string role(message->role);
462+
ss << "<|" << role << "|>" << "\n" << message->content;
463+
}
464+
if (add_ass) {
465+
ss << "<|assistant|>";
466+
}
459467
} else if (tmpl == LLM_CHAT_TEMPLATE_MINICPM) {
460468
// MiniCPM-3B-OpenHermes-2.5-v2-GGUF
461469
for (auto message : chat) {

tests/test-chat-template.cpp

+8-9
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,14 @@ int main(void) {
187187
/* .bos_token= */ "",
188188
/* .eos_token= */ "",
189189
},
190-
// TODO @ngxson : GLMEdge produces poor result without `[gMASK]<sop>`, so we're temporarily using GLM4 template for it. We should fix this in the future.
191-
// {
192-
// /* .name= */ "GLMEdge",
193-
// /* .template_str= */ "{% for item in messages %}{% if item['role'] == 'system' %}<|system|>\n{{ item['content'] }}{% elif item['role'] == 'user' %}<|user|>\n{{ item['content'] }}{% elif item['role'] == 'assistant' %}<|assistant|>\n{{ item['content'] }}{% endif %}{% endfor %}<|assistant|>",
194-
// /* .expected_output= */ "<|system|>\nYou are a helpful assistant<|user|>\nHello<|assistant|>\nHi there<|user|>\nWho are you<|assistant|>\n I am an assistant <|user|>\nAnother question<|assistant|>",
195-
// /* .expected_output_jinja= */ "<|system|>\nYou are a helpful assistant<|user|>\nHello<|assistant|>\nHi there<|user|>\nWho are you<|assistant|>\n I am an assistant <|user|>\nAnother question<|assistant|>",
196-
// /* .bos_token= */ "",
197-
// /* .eos_token= */ "",
198-
// },
190+
{
191+
/* .name= */ "GLMEdge",
192+
/* .template_str= */ "{% for item in messages %}{% if item['role'] == 'system' %}<|system|>\n{{ item['content'] }}{% elif item['role'] == 'user' %}<|user|>\n{{ item['content'] }}{% elif item['role'] == 'assistant' %}<|assistant|>\n{{ item['content'] }}{% endif %}{% endfor %}<|assistant|>",
193+
/* .expected_output= */ "<|system|>\nYou are a helpful assistant<|user|>\nHello<|assistant|>\nHi there<|user|>\nWho are you<|assistant|>\n I am an assistant <|user|>\nAnother question<|assistant|>",
194+
/* .expected_output_jinja= */ "<|system|>\nYou are a helpful assistant<|user|>\nHello<|assistant|>\nHi there<|user|>\nWho are you<|assistant|>\n I am an assistant <|user|>\nAnother question<|assistant|>",
195+
/* .bos_token= */ "",
196+
/* .eos_token= */ "",
197+
},
199198
{
200199
/* .name= */ "MiniCPM-3B-OpenHermes-2.5-v2-GGUF",
201200
/* .template_str= */ U8C("{% for message in messages %}{% if message['role'] == 'user' %}{{'<用户>' + message['content'].strip() + '<AI>'}}{% else %}{{message['content'].strip()}}{% endif %}{% endfor %}"),

0 commit comments

Comments
 (0)