Skip to content

Commit 4a2d17d

Browse files
committed
That's what I get for cargo culting a newline.
1 parent ab22c76 commit 4a2d17d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

common/chat.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,7 @@ static common_chat_params common_chat_params_init_deepseek_v3_1(const common_cha
14151415
additional_context);
14161416
data.prompt = prompt;
14171417
data.format = COMMON_CHAT_FORMAT_DEEPSEEK_V3_1;
1418-
if (string_ends_with(data.prompt, "<think>\n")) {
1418+
if (string_ends_with(data.prompt, "<think>")) {
14191419
if (!inputs.enable_thinking) {
14201420
data.prompt += "</think>";
14211421
} else {

tests/test-chat-parser.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,23 @@ static void test_deepseek_v3_1_tool_calls() {
282282
assert_equals(variant, std::string("REASONING<|tool▁calls▁begin|><|tool▁call▁begin|>get_time2<|tool▁sep|>{\"city\": \"Tokyo2\"}<|tool▁call▁end|><|tool▁calls▁end|>REASONING"), m.reasoning_content);
283283
}
284284

285+
// variant: thinking forced open + tool call in reasoning content + no closing think
286+
{
287+
common_chat_syntax syntax = {
288+
/* .format = */ COMMON_CHAT_FORMAT_DEEPSEEK_V3_1,
289+
/* .reasoning_format = */ COMMON_REASONING_FORMAT_DEEPSEEK,
290+
/* .reasoning_in_content = */ false,
291+
/* .thinking_forced_open = */ true,
292+
/* .parse_tool_calls = */ true,
293+
};
294+
const char* variant = "thinking_forced_open_tool_call_in_reasoning_no_closing_think";
295+
const std::string in = "REASONING<|tool▁calls▁begin|><|tool▁call▁begin|>get_time2<|tool▁sep|>{\"city\": \"Tokyo2\"}<|tool▁call▁end|><|tool▁calls▁end|>REASONING";
296+
auto m = common_chat_parse(in, false, syntax);
297+
assert_equals<std::size_t>(variant, 0, m.tool_calls.size());
298+
assert_equals(variant, std::string(""), m.content);
299+
assert_equals(variant, std::string("REASONING<|tool▁calls▁begin|><|tool▁call▁begin|>get_time2<|tool▁sep|>{\"city\": \"Tokyo2\"}<|tool▁call▁end|><|tool▁calls▁end|>REASONING"), m.reasoning_content);
300+
}
301+
285302
// variant: thinking not forced open + missing reasoning + no tool calls
286303
{
287304
common_chat_syntax syntax = {

0 commit comments

Comments
 (0)