diff --git a/common/chat.cpp b/common/chat.cpp
index 3c6eeda5a..77cae245b 100644
--- a/common/chat.cpp
+++ b/common/chat.cpp
@@ -623,13 +623,13 @@ static common_chat_params common_chat_params_init_deepseek_r1(const common_chat_
static common_chat_msg common_chat_parse_deepseek_r1(const std::string & input) {
static std::regex function_regex("<|tool▁call▁begin|>function<|tool▁sep|>([^\n]+)\n```json\n");
static std::regex close_regex("```[\\s\\r\\n]*<|tool▁call▁end|>");
- static std::regex thoughts_regex("(?:([\\s\\S\\r\\n]*?))?([\\s\\S\\r\\n]*)");
+ static std::regex reasoning_content_regex("(?:([\\s\\S\\r\\n]*?))?([\\s\\S\\r\\n]*)");
static std::regex tool_calls_regex("[\\s\\r\\n]*(?:<|tool▁calls▁begin|>|<|tool_calls_begin|>|<|tool calls begin|>|<|tool\\\\_calls\\\\_begin|>)([\\s\\S\\r\\n]*?)<|tool▁calls▁end|>");
common_chat_msg msg;
msg.role = "assistant";
std::smatch match;
- if (std::regex_match(input, match, thoughts_regex)) {
- msg.thoughts = string_trim(match[1].str());
+ if (std::regex_match(input, match, reasoning_content_regex)) {
+ msg.reasoning_content = string_trim(match[1].str());
auto rest = match[2].str();
if (std::regex_search(rest, match, tool_calls_regex)) {
diff --git a/common/common.h b/common/common.h
index 858d2807e..0d1cb98ce 100644
--- a/common/common.h
+++ b/common/common.h
@@ -623,7 +623,7 @@ struct common_chat_msg {
std::string role;
std::string content;
std::vector tool_calls;
- std::string thoughts = "";
+ std::string reasoning_content = "";
std::string tool_plan = "";
};
diff --git a/examples/server/server.cpp b/examples/server/server.cpp
index 5e440eb0c..8f098fef0 100644
--- a/examples/server/server.cpp
+++ b/examples/server/server.cpp
@@ -745,8 +745,8 @@ struct server_task_result_cmpl_final : server_task_result {
{"tool_calls", tool_calls},
{"role", "assistant"},
};
- if (!msg.thoughts.empty()) {
- message["thoughts"] = msg.thoughts;
+ if (!msg.reasoning_content.empty()) {
+ message["reasoning_content"] = msg.reasoning_content;
}
if (!msg.tool_plan.empty()) {
message["tool_plan"] = msg.tool_plan;
diff --git a/examples/server/tests/unit/test_tool_call.py b/examples/server/tests/unit/test_tool_call.py
index 70288dbf3..87a4a27e0 100644
--- a/examples/server/tests/unit/test_tool_call.py
+++ b/examples/server/tests/unit/test_tool_call.py
@@ -436,12 +436,12 @@ def test_calc_result(result_override: str | None, n_predict: int, hf_repo: str,
@pytest.mark.slow
-@pytest.mark.parametrize("n_predict,expect_content,expect_thoughts,hf_repo,template_override", [
+@pytest.mark.parametrize("n_predict,expect_content,expect_reasoning_content,hf_repo,template_override", [
(128, "^The sum of 102 and 7 is 109.*", None, "bartowski/Phi-3.5-mini-instruct-GGUF:Q4_K_M", None),
(1024, "To find the sum of.*", "I need to calculate the sum of 102 and 7.*", "bartowski/DeepSeek-R1-Distill-Qwen-7B-GGUF:Q4_K_M", None),
(1024, "To find the sum of.*", "First, I need to add the tens place.*", "bartowski/DeepSeek-R1-Distill-Qwen-7B-GGUF:Q4_K_M", ("llama-cpp-deepseek-r1", None)),
])
-def test_thoughts(n_predict: int, expect_content: str | None, expect_thoughts: str | None, hf_repo: str, template_override: str | Tuple[str, str | None] | None):
+def test_reasoning_content(n_predict: int, expect_content: str | None, expect_reasoning_content: str | None, hf_repo: str, template_override: str | Tuple[str, str | None] | None):
global server
server.n_slots = 1
server.jinja = True
@@ -470,9 +470,9 @@ def test_thoughts(n_predict: int, expect_content: str | None, expect_thoughts: s
if expect_content is not None:
assert re.match(expect_content, content), f'Expected {expect_content}, got {content}'
- thoughts = choice["message"].get("thoughts")
- if expect_thoughts is not None:
- assert re.match(expect_thoughts, thoughts), f'Expected {expect_thoughts}, got {thoughts}'
+ reasoning_content = choice["message"].get("reasoning_content")
+ if expect_reasoning_content is not None:
+ assert re.match(expect_reasoning_content, reasoning_content), f'Expected {expect_reasoning_content}, got {reasoning_content}'
@pytest.mark.slow
diff --git a/tests/test-chat.cpp b/tests/test-chat.cpp
index c40a77ca2..7827ad0e4 100644
--- a/tests/test-chat.cpp
+++ b/tests/test-chat.cpp
@@ -26,8 +26,8 @@ static common_chat_msg msg_from_json(const json & message) {
if (message.contains("tool_plan")) {
ret.tool_plan = message.at("tool_plan");
}
- if (message.contains("thoughts")) {
- ret.thoughts = message.at("thoughts");
+ if (message.contains("reasoning_content")) {
+ ret.reasoning_content = message.at("reasoning_content");
}
auto has_tool_calls = message.contains("tool_calls");
if (has_tool_calls) {
@@ -108,7 +108,7 @@ static std::string dump(const json & j) {
static void assert_msg_equals(const common_chat_msg & expected, const common_chat_msg & actual) {
assert_equals(expected.role, actual.role);
assert_equals(expected.content, actual.content);
- assert_equals(expected.thoughts, actual.thoughts);
+ assert_equals(expected.reasoning_content, actual.reasoning_content);
assert_equals(expected.tool_plan, actual.tool_plan);
assert_equals(expected.tool_calls.size(), actual.tool_calls.size());
for (size_t i = 0; i < expected.tool_calls.size(); i++) {
@@ -293,10 +293,10 @@ static void test_template_output_parsers() {
{ "role", "assistant" },
{ "content", "Hello, world!" },
};
- json text_thoughts_message {
+ json text_reasoning_message {
{ "role", "assistant" },
{ "content", "Hello, world!" },
- { "thoughts", "I'm thinking" },
+ { "reasoning_content", "I'm thinking" },
};
json tool_calls = json::array({{
{ "type", "function" },
@@ -316,10 +316,10 @@ static void test_template_output_parsers() {
},
}},
};
- json tool_call_thoughts_message = {
+ json tool_call_reasoning_message = {
{ "role", "assistant" },
{ "content", nullptr },
- { "thoughts", "I'm\nthinking" },
+ { "reasoning_content", "I'm\nthinking" },
{ "tool_calls", {
{
{ "type", "function" },
@@ -589,8 +589,8 @@ static void test_template_output_parsers() {
assert_equals(COMMON_CHAT_FORMAT_DEEPSEEK_R1, common_chat_params_init(tmpl, inputs_tools).format);
test_template(tmpl, end_tokens, text_message, tools, "Hello, world!", /* expect_grammar_triggered= */ false);
- test_template(tmpl, end_tokens, text_thoughts_message, tools, "Hello, world!", /* expect_grammar_triggered= */ false);
- assert_msg_equals(msg_from_json(text_thoughts_message), common_chat_parse("I'm thinkingHello, world!", COMMON_CHAT_FORMAT_DEEPSEEK_R1));
+ test_template(tmpl, end_tokens, text_reasoning_message, tools, "Hello, world!", /* expect_grammar_triggered= */ false);
+ assert_msg_equals(msg_from_json(text_reasoning_message), common_chat_parse("I'm thinkingHello, world!", COMMON_CHAT_FORMAT_DEEPSEEK_R1));
// test_template(tmpl, end_tokens, tool_call_message, tools,
// "<|tool▁calls▁begin|><|tool▁call▁begin|>function<|tool▁sep|>special_function\n"
// "```json\n"
@@ -609,10 +609,10 @@ static void test_template_output_parsers() {
assert_equals(COMMON_CHAT_FORMAT_DEEPSEEK_R1, common_chat_params_init(tmpl, inputs_tools).format);
test_template(tmpl, end_tokens, text_message, tools, "Hello, world!", /* expect_grammar_triggered= */ false);
- test_template(tmpl, end_tokens, text_thoughts_message, tools, "Hello, world!", /* expect_grammar_triggered= */ false);
- assert_msg_equals(msg_from_json(text_thoughts_message), common_chat_parse("I'm thinkingHello, world!", COMMON_CHAT_FORMAT_DEEPSEEK_R1));
+ test_template(tmpl, end_tokens, text_reasoning_message, tools, "Hello, world!", /* expect_grammar_triggered= */ false);
+ assert_msg_equals(msg_from_json(text_reasoning_message), common_chat_parse("I'm thinkingHello, world!", COMMON_CHAT_FORMAT_DEEPSEEK_R1));
- assert_msg_equals(msg_from_json(tool_call_thoughts_message),
+ assert_msg_equals(msg_from_json(tool_call_reasoning_message),
common_chat_parse(
"I'm\nthinking\n\n"
"<|tool▁calls▁begin|><|tool▁call▁begin|>function<|tool▁sep|>special_function\n"