From 7320f95c05543cef61274165530853791bec0d30 Mon Sep 17 00:00:00 2001 From: Xiaodong Ye Date: Mon, 12 May 2025 15:41:44 +0800 Subject: [PATCH] Support Seed-Coder chat template Signed-off-by: Xiaodong Ye --- src/llama-chat.cpp | 15 +++++++++++++++ src/llama-chat.h | 1 + 2 files changed, 16 insertions(+) diff --git a/src/llama-chat.cpp b/src/llama-chat.cpp index d12743e6b9a0c..7a64cea6290d6 100644 --- a/src/llama-chat.cpp +++ b/src/llama-chat.cpp @@ -64,6 +64,7 @@ static const std::map LLM_CHAT_TEMPLATES = { { "bailing", LLM_CHAT_TEMPLATE_BAILING }, { "llama4", LLM_CHAT_TEMPLATE_LLAMA4 }, { "smolvlm", LLM_CHAT_TEMPLATE_SMOLVLM }, + { "seed-coder", LLM_CHAT_TEMPLATE_SEED_CODER }, }; llm_chat_template llm_chat_template_from_str(const std::string & name) { @@ -183,6 +184,9 @@ llm_chat_template llm_chat_detect_template(const std::string & tmpl) { return LLM_CHAT_TEMPLATE_BAILING; } else if (tmpl_contains("<|header_start|>") && tmpl_contains("<|header_end|>")) { return LLM_CHAT_TEMPLATE_LLAMA4; + } else if (tmpl_contains("raise_exception") && tmpl_contains("System role not supported") && + tmpl_contains("Conversation roles must alternate user/assistant/user/assistant/...")) { + return LLM_CHAT_TEMPLATE_SEED_CODER; } return LLM_CHAT_TEMPLATE_UNKNOWN; } @@ -643,6 +647,17 @@ int32_t llm_chat_apply_template( if (add_ass) { ss << "Assistant:"; } + } else if (tmpl == LLM_CHAT_TEMPLATE_SEED_CODER) { + // Seed-Coder + for (auto message : chat) { + std::string role(message->role); + if (role == "user") { + ss << "<[begin▁of▁sentence]>" << role << "\n" << trim(message->content) << "<[end▁of▁sentence]>"; + } + } + if (add_ass) { + ss << "<[begin▁of▁sentence]>assistant\n"; + } } else { // template not supported return -1; diff --git a/src/llama-chat.h b/src/llama-chat.h index db24ade21e2ad..52e048216201b 100644 --- a/src/llama-chat.h +++ b/src/llama-chat.h @@ -43,6 +43,7 @@ enum llm_chat_template { LLM_CHAT_TEMPLATE_BAILING, LLM_CHAT_TEMPLATE_LLAMA4, LLM_CHAT_TEMPLATE_SMOLVLM, + LLM_CHAT_TEMPLATE_SEED_CODER, LLM_CHAT_TEMPLATE_UNKNOWN, };