Commit 50e0ca2

mo khan <mo@mokhan.ca>
2026-08-30 06:00:18
fix: set reasoning_format on templates_apply, not just parse
reasoning_format on common_chat_parser_params only controls parse-time behavior for formats the template-apply step already flagged as extract_reasoning; it must also be set on common_chat_templates_inputs before common_chat_templates_apply, or thinking-tag models (verified against GLM-4.7-Flash's <think>...</think>) leave reasoning text inline in content instead of routing it to reasoning_content. gpt-oss's harmony channels were unaffected since that path already had its own handling, but this is required for correctness generally.
Changed files (1)
ext
elelem_llama
ext/elelem_llama/elelem_llama.cpp
@@ -136,6 +136,12 @@ static const char *el_generate_impl(void *handle, const char *messages_json, con
     if (tools_json && *tools_json) inputs.tools = build_tools(json::parse(tools_json));
     inputs.add_generation_prompt = true;
     inputs.use_jinja = true;
+    // Must be set before templates_apply -- it bakes extract_reasoning into the
+    // parser grammar templates_apply builds (see common_chat_parser_params below,
+    // which only controls parse-time behavior for formats that already support
+    // it). Without this, thinking-tag models (e.g. GLM's <think>...</think>)
+    // leave reasoning text inline in content instead of reasoning_content.
+    inputs.reasoning_format = COMMON_REASONING_FORMAT_AUTO;
     common_chat_params cparams = common_chat_templates_apply(h->tmpls.get(), inputs);
 
     json result;