Skip to content

Commit 3912fd3

Browse files
committed
Another attempt by V3.1 non-thinking
1 parent 0d96944 commit 3912fd3

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

common/chat.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,8 +1314,15 @@ static common_chat_params common_chat_params_init_deepseek_r1(const common_chat_
13141314
}
13151315

13161316
static common_chat_params common_chat_params_init_deepseek_v3_1(const common_chat_template & tmpl, const struct templates_params & inputs) {
1317-
// For now, use the same implementation as R1
1318-
return common_chat_params_init_deepseek_r1(tmpl, inputs);
1317+
common_chat_params data;
1318+
auto prompt = apply(tmpl, inputs);
1319+
data.prompt = prompt;
1320+
data.format = COMMON_CHAT_FORMAT_DEEPSEEK_V3_1;
1321+
1322+
// For V3.1, we need to handle thinking mode differently
1323+
// The template should handle the thinking mode logic
1324+
1325+
return data;
13191326
}
13201327

13211328
static void common_chat_parse_deepseek_r1(common_chat_msg_parser & builder) {

tests/test-chat-parser.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,32 @@ static void test_regex() {
152152
}
153153
}
154154

155+
static void test_deepseek_v3_1() {
156+
// Test DeepSeek V3.1 parsing - reasoning content followed by "</think>" and then regular content
157+
{
158+
common_chat_syntax syntax = {
159+
/* .format = */ COMMON_CHAT_FORMAT_DEEPSEEK_V3_1,
160+
/* .reasoning_format = */ COMMON_REASONING_FORMAT_DEEPSEEK,
161+
/* .reasoning_in_content = */ false,
162+
/* .thinking_forced_open = */ false,
163+
/* .parse_tool_calls = */ true,
164+
};
165+
common_chat_msg_parser builder("REASONING</think><function=finish>\n<parameter=message>ok
166+
static void test_deepseek_v3_1() {
167+
// Test DeepSeek V3.1 parsing - reasoning content followed by "</think>" and then regular content
168+
{
169+
common_chat_syntax syntax = {
170+
/* .format = */ COMMON_CHAT_FORMAT_DEEPSEEK_V3_1,
171+
/* .reasoning_format = */ COMMON_REASONING_FORMAT_DEEPSEEK,
172+
/* .reasoning_in_content = */ false,
173+
/* .thinking_forced_open = */ false,
174+
/* .parse_tool_calls = */ true,
175+
};
176+
common_chat_msg_parser builder("REASONING</think><function=finish>\n<parameter=message>ok
177+
static void test_deepseek_v3_1() {
178+
// Test DeepSeek V3.1 parsing - reasoning content followed by "</think>" and then regular content
179+
{
180+
common_chat_msg_parser builder("REASONING</think><function=finish>\n<parameter=message>ok
155181
const std::vector<std::string> barely_healable_jsons = {
156182
"{",
157183
"{\"",

tools/server/server.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,9 @@ struct server_task_result_cmpl_final : server_task_result {
774774
if (!stream && !probs_output.empty()) {
775775
res["completion_probabilities"] = completion_token_output::probs_vector_to_json(probs_output, post_sampling_probs);
776776
}
777+
if (!oaicompat_msg.reasoning_content.empty()) {
778+
res["reasoning_content"] = oaicompat_msg.reasoning_content;
779+
}
777780
return response_fields.empty() ? res : json_get_nested_values(response_fields, res);
778781
}
779782

0 commit comments

Comments
 (0)