Renders the chat template of a model repository, like apply_chat_template in Python transformers.
Needs the optional otera dependency, which renders Jinja templates in pure Elixir.
repo = Transmuter.Repo.load!({:hf, "HuggingFaceTB/SmolLM2-135M-Instruct"})
Transmuter.ChatTemplate.render(repo, [%{role: "user", content: "Hello"}])
#=> "<|im_start|>system\nYou are a helpful AI assistant named SmolLM...<|im_start|>assistant\n"Map keys can be atoms or strings. A plain Elixir map gives its keys to tojson in alphabetical order. To get the key order of transformers for tool definitions or messages that come from JSON, decode the JSON with Otera.JSON.decode!/1.
Summary
Functions
Renders messages, a list of maps with :role and :content, with the chat template of repo.
Functions
Renders messages, a list of maps with :role and :content, with the chat template of repo.
Options
:continue_final_message- ends the prompt inside the final message, so that the model continues it. The default isfalse.:add_generation_prompt- ends the prompt with the start of an assistant message. The default istrue, orfalsewith:continue_final_message.:tools- a list of tool definitions in JSON schema form. A repository with a template named"tool_use"renders tools with it.:template_options- other variables of the template, such asenable_thinking: falsefor Qwen3.:template- the template to render in place of that of the tokenizer, such as the:processor_chat_templateofTransmuter.Repo.