-
Notifications
You must be signed in to change notification settings - Fork 82
add chatml template? #130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
Comments
I'm not sure about chatML specifically, but there is work on adding chat templates going on in #127 |
I implement a script to parse chat template from gguf model, and then use crate minijinja to transform messages to prompts let chat_template: String = unsafe {
// longest known template is about 1200 bytes from llama.cpp
let chat_temp = CString::new(Vec::<u8>::with_capacity(2048))?;
let chat_ptr = chat_temp.into_raw();
let chat_name = CString::new("tokenizer.chat_template")?;
llama_cpp_sys_2::llama_model_meta_val_str(
model.model.as_ptr(),
chat_name.as_ptr(),
chat_ptr,
250,
);
CString::from_raw(chat_ptr).to_str()?.to_string()
}; |
let mut env = Environment::new();
env.add_template("chat_temp", &chat_template)?;
let temp_eng = env.get_template("chat_temp")?;
let mut messages: Vec<HashMap<&str, &str>> = Vec::new();
let mut content1: HashMap<&str, &str> = HashMap::new();
content1.insert("role", "system");
content1.insert("content", "you are a helpful AI assistant");
messages.push(content1);
let mut content2: HashMap<&str, &str> = HashMap::new();
content2.insert("role", "user");
content2.insert("content", "what is your name");
messages.push(content2);
let prompt = temp_eng.render(context!(messages => messages, add_generation_prompt => true))?; transform messages to prompt |
completed in #127 and released. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hello, do you have any plan to add chatml template in this crate?
The text was updated successfully, but these errors were encountered: