Skip to content

Commit 7795594

Browse files
committed
DeepSeek V3.1 fix reasoning_format none
1 parent befa31c commit 7795594

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

common/chat.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,6 +1458,11 @@ static void common_chat_parse_deepseek_v3_1(common_chat_msg_parser & builder) {
14581458
// </think><|tool▁calls▁begin|><|tool▁call▁begin|>function<|tool▁sep|>NAME\n```json\nJSON\n```<|tool▁call▁end|><|tool▁calls▁end|>
14591459
common_chat_parse_deepseek_v3_1_content(builder);
14601460
} else {
1461+
if (builder.syntax().reasoning_format == COMMON_REASONING_FORMAT_NONE) {
1462+
LOG_DBG("%s: reasoning_format none, adding content\n", __func__);
1463+
common_chat_parse_deepseek_v3_1_content(builder);
1464+
return;
1465+
}
14611466
// If no reasoning tags found, check if we should treat everything as reasoning
14621467
if (builder.syntax().thinking_forced_open) {
14631468
// If thinking is forced open but no tags found, treat everything as reasoning

tests/test-chat-parser.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,26 @@ static void test_reasoning() {
114114
/* .thinking_forced_open = */ true,
115115
/* .parse_tool_calls = */ true,
116116
};
117+
const std::string variant("deepseek_v3_1_reasoning_format_deepseek");
117118
common_chat_msg_parser builder("REASONING</think>ok", /* is_partial= */ false, syntax);
118-
assert_equals(true, builder.try_parse_reasoning("<think>", "</think>"));
119-
assert_equals(std::string("REASONING"), builder.result().reasoning_content);
120-
assert_equals(std::string("ok"), builder.consume_rest());
119+
assert_equals(variant, true, builder.try_parse_reasoning("<think>", "</think>"));
120+
assert_equals(variant, std::string("REASONING"), builder.result().reasoning_content);
121+
assert_equals(variant, std::string("ok"), builder.consume_rest());
122+
}
123+
// Test DeepSeek V3.1 parsing - reasoning_format none - reasoning content followed by "</think>" and then regular content
124+
{
125+
common_chat_syntax syntax = {
126+
/* .format = */ COMMON_CHAT_FORMAT_DEEPSEEK_V3_1,
127+
/* .reasoning_format = */ COMMON_REASONING_FORMAT_NONE,
128+
/* .reasoning_in_content = */ false,
129+
/* .thinking_forced_open = */ true,
130+
/* .parse_tool_calls = */ true,
131+
};
132+
const std::string variant("deepseek_v3_1_reasoning_format_none");
133+
const std::string input = "REASONING</think>ok";
134+
auto msg = common_chat_parse(input, false, syntax);
135+
assert_equals(variant, std::string("REASONING</think>ok"), msg.content);
136+
assert_equals(variant, std::string(""), msg.reasoning_content);
121137
}
122138
}
123139

tests/test-chat.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,6 +1778,19 @@ static void test_template_output_parsers() {
17781778
/* .reasoning_in_content = */ false,
17791779
/* .thinking_forced_open = */ true,
17801780
}));
1781+
// variant: thinking forced open, reasoning_format none
1782+
assert_msg_equals(
1783+
simple_assist_msg("REASONING</think>ok", ""),
1784+
common_chat_parse(
1785+
"REASONING</think>ok",
1786+
/* is_partial= */ false,
1787+
{
1788+
COMMON_CHAT_FORMAT_DEEPSEEK_V3_1,
1789+
/* .reasoning_format = */ COMMON_REASONING_FORMAT_NONE,
1790+
/* .reasoning_in_content = */ false,
1791+
/* .thinking_forced_open = */ true,
1792+
/* .parse_tool_calls = */ true,
1793+
}));
17811794
// variant: happy path for when it works as the model card says it should
17821795
assert_msg_equals(
17831796
simple_assist_msg("", "", "get_time", "{\"city\":\"Tokyo\"}"),

0 commit comments

Comments
 (0)