pub struct ChatTemplates { /* private fields */ }Expand description
The chat templates a model ships, ready to apply.
Wraps common_chat_templates, which owns parsed Jinja programs — building
it is not free, so hold one per model rather than one per request.
Implementations§
Source§impl ChatTemplates
impl ChatTemplates
Sourcepub fn from_model(
model: &LlamaModel,
template_override: Option<&str>,
) -> Result<Self, ChatError>
pub fn from_model( model: &LlamaModel, template_override: Option<&str>, ) -> Result<Self, ChatError>
Build the template set for model.
Pass None for template_override to use whatever the model ships, or
Jinja source to override it. Overriding is what lets you reach a
model’s tool_use variant — fetch it with
LlamaModel::chat_template and hand it back here.
§Errors
Returns ChatError::Init if the model has no usable template
or the override does not parse.
Sourcepub fn source(&self, variant: Option<&str>) -> Result<String, ChatError>
pub fn source(&self, variant: Option<&str>) -> Result<String, ChatError>
Where the active template came from, e.g. "model" or a builtin name.
§Errors
Returns ChatError::Failed if llama.cpp could not report a source.
Sourcepub fn was_explicit(&self) -> bool
pub fn was_explicit(&self) -> bool
Whether the caller supplied the template rather than the model.
Sourcepub fn supports_enable_thinking(&self) -> bool
pub fn supports_enable_thinking(&self) -> bool
Whether this template understands enable_thinking.
Sourcepub fn caps_json(&self) -> Result<String, ChatError>
pub fn caps_json(&self) -> Result<String, ChatError>
Template capabilities as a JSON object of name -> bool.
This is what upstream’s server reports on /props; it tells you whether
the template can handle tools, parallel calls, a system role, and so on
before you send a request it cannot render.
§Errors
Returns ChatError::Failed if llama.cpp could not report caps.
Sourcepub fn apply(&self, params: &ChatApplyParams) -> Result<ChatParams, ChatError>
pub fn apply(&self, params: &ChatApplyParams) -> Result<ChatParams, ChatError>
Render messages and tools into a prompt plus its sampling constraints.
§Errors
Returns ChatError::BadJson for malformed messages/tools JSON, or
ChatError::Failed if the template cannot render the request.