Skip to content

Commit fcc2931

Browse files
committed
server : add support for add_bos and add_eos in common_chat_templates
1 parent 943fbf5 commit fcc2931

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

common/chat.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,14 @@ common_chat_templates_ptr common_chat_templates_init(
605605
return tmpls;
606606
}
607607

608+
bool common_chat_templates_get_add_bos(const struct common_chat_templates * tmpls) {
609+
return tmpls->add_bos;
610+
}
611+
612+
bool common_chat_templates_get_add_eos(const struct common_chat_templates * tmpls) {
613+
return tmpls->add_eos;
614+
}
615+
608616
const char * common_chat_format_name(common_chat_format format) {
609617
switch (format) {
610618
case COMMON_CHAT_FORMAT_CONTENT_ONLY: return "Content-only";

common/chat.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ common_chat_templates_ptr common_chat_templates_init(
170170

171171
bool common_chat_templates_was_explicit(const struct common_chat_templates * tmpls);
172172
const char * common_chat_templates_source(const struct common_chat_templates * tmpls, const char * variant = nullptr);
173+
bool common_chat_templates_get_add_bos(const struct common_chat_templates * tmpls);
174+
bool common_chat_templates_get_add_eos(const struct common_chat_templates * tmpls);
173175

174176

175177
struct common_chat_params common_chat_templates_apply(

tools/server/utils.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,8 @@ static json oaicompat_chat_params_parse(
752752
inputs.add_generation_prompt = json_value(body, "add_generation_prompt", true);
753753
inputs.reasoning_format = opt.reasoning_format;
754754
inputs.enable_thinking = opt.enable_thinking;
755+
inputs.add_bos = common_chat_templates_get_add_bos(opt.tmpls);
756+
inputs.add_eos = common_chat_templates_get_add_eos(opt.tmpls);
755757
if (!inputs.tools.empty() && inputs.tool_choice != COMMON_CHAT_TOOL_CHOICE_NONE) {
756758
if (body.contains("grammar")) {
757759
throw std::runtime_error("Cannot use custom grammar constraints with tools.");

0 commit comments

Comments
 (0)