MCPcopy Create free account
hub / github.com/abetlen/llama-cpp-python / llama_chat_apply_template

Function llama_chat_apply_template

llama_cpp/llama_cpp.py:4132–4154  ·  view source on GitHub ↗

Apply chat template. Args: tmpl: Template to use. If None, uses model's default chat: Array of chat messages n_msg: Number of messages add_ass: Whether to end prompt with assistant token buf: Output buffer length: Buffer length Returns:

(
    tmpl: bytes,
    chat: CtypesArray[llama_chat_message],
    n_msg: int,
    add_ass: bool,  # Added parameter
    buf: bytes,
    length: int,
    /,
)

Source from the content-addressed store, hash-verified

4130 ctypes.c_int32,
4131)
4132def llama_chat_apply_template(
4133 tmpl: bytes,
4134 chat: CtypesArray[llama_chat_message],
4135 n_msg: int,
4136 add_ass: bool, # Added parameter
4137 buf: bytes,
4138 length: int,
4139 /,
4140) -> int:
4141 """Apply chat template.
4142
4143 Args:
4144 tmpl: Template to use. If None, uses model's default
4145 chat: Array of chat messages
4146 n_msg: Number of messages
4147 add_ass: Whether to end prompt with assistant token
4148 buf: Output buffer
4149 length: Buffer length
4150
4151 Returns:
4152 Number of bytes written, or needed if buffer too small
4153 """
4154 ...
4155
4156
4157# // Get list of built-in chat templates

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…