diff --git a/common/chat.cpp b/common/chat.cpp index 34e6152164..78ceecd02b 100644 --- a/common/chat.cpp +++ b/common/chat.cpp @@ -1314,8 +1314,15 @@ static common_chat_params common_chat_params_init_deepseek_r1(const common_chat_ } static common_chat_params common_chat_params_init_deepseek_v3_1(const common_chat_template & tmpl, const struct templates_params & inputs) { - // For now, use the same implementation as R1 - return common_chat_params_init_deepseek_r1(tmpl, inputs); + common_chat_params data; + auto prompt = apply(tmpl, inputs); + data.prompt = prompt; + data.format = COMMON_CHAT_FORMAT_DEEPSEEK_V3_1; + + // For V3.1, we need to handle thinking mode differently + // The template should handle the thinking mode logic + + return data; } static void common_chat_parse_deepseek_r1(common_chat_msg_parser & builder) { diff --git a/tests/test-chat-parser.cpp b/tests/test-chat-parser.cpp index 59e44e07d2..a81761f321 100644 --- a/tests/test-chat-parser.cpp +++ b/tests/test-chat-parser.cpp @@ -152,6 +152,32 @@ static void test_regex() { } } +static void test_deepseek_v3_1() { + // Test DeepSeek V3.1 parsing - reasoning content followed by "" and then regular content + { + common_chat_syntax syntax = { + /* .format = */ COMMON_CHAT_FORMAT_DEEPSEEK_V3_1, + /* .reasoning_format = */ COMMON_REASONING_FORMAT_DEEPSEEK, + /* .reasoning_in_content = */ false, + /* .thinking_forced_open = */ false, + /* .parse_tool_calls = */ true, + }; + common_chat_msg_parser builder("REASONING\nok +static void test_deepseek_v3_1() { + // Test DeepSeek V3.1 parsing - reasoning content followed by "" and then regular content + { + common_chat_syntax syntax = { + /* .format = */ COMMON_CHAT_FORMAT_DEEPSEEK_V3_1, + /* .reasoning_format = */ COMMON_REASONING_FORMAT_DEEPSEEK, + /* .reasoning_in_content = */ false, + /* .thinking_forced_open = */ false, + /* .parse_tool_calls = */ true, + }; + common_chat_msg_parser builder("REASONING\nok +static void test_deepseek_v3_1() { + // Test DeepSeek V3.1 parsing - reasoning content followed by "" and then regular content + { + common_chat_msg_parser builder("REASONING\nok const std::vector barely_healable_jsons = { "{", "{\"", diff --git a/tools/server/server.cpp b/tools/server/server.cpp index 35b060674b..19e5d4d484 100644 --- a/tools/server/server.cpp +++ b/tools/server/server.cpp @@ -774,6 +774,9 @@ struct server_task_result_cmpl_final : server_task_result { if (!stream && !probs_output.empty()) { res["completion_probabilities"] = completion_token_output::probs_vector_to_json(probs_output, post_sampling_probs); } + if (!oaicompat_msg.reasoning_content.empty()) { + res["reasoning_content"] = oaicompat_msg.reasoning_content; + } return response_fields.empty() ? res : json_get_nested_values(response_fields, res); }