diff --git a/common/chat.cpp b/common/chat.cpp index 4350a9ec6be..7f6428dddf1 100644 --- a/common/chat.cpp +++ b/common/chat.cpp @@ -2720,20 +2720,20 @@ static common_chat_params common_chat_params_init_laguna(const common_chat_templ // "\n" followed by the opening (thinking enabled) or // (disabled). Consume it, then capture reasoning. The model's // output therefore starts with the reasoning text (no leading ). - const std::string GEN_PROMPT = "\n"; + auto gen_prompt = p.literal("") + p.optional(p.space()); auto head = p.eps(); if (extract_reasoning && inputs.enable_thinking) { // The model normally closes reasoning with before a tool // call, but sometimes emits directly without it. // Terminate reasoning on whichever marker comes first so the call is // not swallowed into reasoning_content; consume if present. - head = p.literal(GEN_PROMPT + THINK_START) + + head = gen_prompt + p.literal(THINK_START) + p.reasoning(p.until_one_of({ THINK_END, CALL_START })) + p.optional(p.literal(THINK_END)); } else if (extract_reasoning) { - head = p.literal(GEN_PROMPT + THINK_END); + head = gen_prompt + p.literal(THINK_END); } else { - head = p.literal(GEN_PROMPT) + + head = gen_prompt + p.optional(p.literal(THINK_START)) + p.optional(p.literal(THINK_END)); }