Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions common/chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@ bool common_chat_templates_support_enable_thinking(const common_chat_templates *
return params.supports_thinking;
}

bool common_chat_templates_support_preserve_thinking(const common_chat_templates * chat_templates) {
std::string src = common_chat_templates_source(chat_templates);
return src.find("preserve_thinking") != std::string::npos;
}

std::vector<common_chat_msg> common_chat_msgs_parse_oaicompat(const json & messages) {
std::vector<common_chat_msg> msgs;

Expand Down
1 change: 1 addition & 0 deletions common/chat.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ common_reasoning_format common_reasoning_format_from_name(const std::string & fo
common_chat_tool_choice common_chat_tool_choice_parse_oaicompat(const std::string & tool_choice);

bool common_chat_templates_support_enable_thinking(const common_chat_templates * chat_templates);
bool common_chat_templates_support_preserve_thinking(const common_chat_templates * chat_templates);

// Parses a JSON array of messages in OpenAI's chat completion API format.
std::vector<common_chat_msg> common_chat_msgs_parse_oaicompat(const nlohmann::ordered_json & messages);
Expand Down
8 changes: 8 additions & 0 deletions tools/server/server-context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1520,6 +1520,14 @@ struct server_context_impl {
const bool enable_thinking = params_base.enable_reasoning != 0 && template_supports_thinking;
SRV_TRC("%s: chat template, thinking = %d\n", __func__, enable_thinking);

// hint: suggest preserve_thinking if the template supports it but user hasn't set it
if (params_base.use_jinja && common_chat_templates_support_preserve_thinking(chat_templates.get())) {
auto it = params_base.default_template_kwargs.find("preserve_thinking");
if (it == params_base.default_template_kwargs.end()) {
SRV_WRN("%s\n", "chat template supports 'preserve_thinking' - consider using --chat-template-kwargs \"{\\\"preserve_thinking\\\": true}\" (ref: https://docs.z.ai/guides/capabilities/thinking-mode#preserved-thinking)");
}
}

// IMPORTANT: chat_params is reused across sleeping / resuming states,
// never store llama_context/llama_model pointers in chat_params,
// as they may be invalidated after sleeping
Expand Down