return thoughts in reasoning_content field

This commit is contained in:
Olivier Chafik 2025-02-04 11:37:09 +00:00
parent d1b66910c5
commit 39c1d8163b
5 changed files with 23 additions and 23 deletions

View file

@ -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("(?:<think>([\\s\\S\\r\\n]*?)</think>)?([\\s\\S\\r\\n]*)");
static std::regex reasoning_content_regex("(?:<think>([\\s\\S\\r\\n]*?)</think>)?([\\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)) {