use anyhow::Result;
use rlx_cli::{ChatMessage, auto_chat_template};
use rlx_qwen35::{decode_ids_auto, encode_prompt_auto};
use std::path::Path;
pub fn encode_chat_prompt_auto(
weights: &Path,
tokenizer: Option<&Path>,
system: Option<&str>,
user: &str,
use_chat_template: bool,
) -> Result<Vec<u32>> {
let text = if use_chat_template {
match auto_chat_template(weights) {
Ok(tmpl) => {
let mut msgs = Vec::new();
if let Some(s) = system {
msgs.push(ChatMessage::system(s.to_string()));
}
msgs.push(ChatMessage::user(user.to_string()));
tmpl.render(&msgs, true)?
}
Err(_) => user.to_string(),
}
} else {
user.to_string()
};
encode_prompt_auto(weights, tokenizer, &text)
}
pub fn decode_token_auto(weights: &Path, tokenizer: Option<&Path>, tok: u32) -> Result<String> {
decode_ids_auto(weights, tokenizer, &[tok], false)
}