Skip to content

Commit 9e897d7

Browse files
Log chat template fallback failures
Emit a warning when apply_chat_template fails and ltengine falls back to the hardcoded Gemma prompt format.
1 parent d1052b5 commit 9e897d7

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

ltengine/src/llm.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,17 @@ impl LLM {
175175
// Use the model's embedded chat template when llama.cpp can detect it.
176176
// Falls back to hardcoded Gemma format when detection fails (e.g. Gemma 4
177177
// until llama-cpp-sys picks up the upstream Gemma 4 template detection fix).
178-
let llm_input = self.model
178+
let llm_input = match self.model
179179
.chat_template(None)
180180
.ok()
181181
.and_then(|tmpl| self.model.apply_chat_template(&tmpl, &messages, true).ok())
182-
.unwrap_or_else(|| format!(
183-
"<start_of_turn>user\n{system}\n\n{user}<end_of_turn>\n<start_of_turn>model\n"
184-
));
182+
{
183+
Some(s) => s,
184+
None => {
185+
eprintln!("ltengine: apply_chat_template failed: using hardcoded Gemma format");
186+
format!("<start_of_turn>user\n{system}\n\n{user}<end_of_turn>\n<start_of_turn>model\n")
187+
}
188+
};
185189

186190
// BOS is not added by apply_chat_template — str_to_token handles it.
187191
let tokens_list = self.model

0 commit comments

Comments
 (0)