Skip to content

< Back


LLamaTemplate

Namespace: LLama

Converts a sequence of messages into text according to a model template

1
public sealed class LLamaTemplate

Inheritance ObjectLLamaTemplate
Attributes NullableContextAttribute, NullableAttribute, DefaultMemberAttribute

Fields

Encoding

The encoding algorithm to use

1
public static Encoding Encoding;

Properties

Count

Number of messages added to this template

1
public int Count { get; private set; }

Property Value

Int32

Item

1
public TextMessage Item { get; }

Property Value

TextMessage

AddAssistant

Whether to end the prompt with the token(s) that indicate the start of an assistant message.

1
public bool AddAssistant { get; set; }

Property Value

Boolean

Constructors

LLamaTemplate(SafeLlamaModelHandle, String, Boolean)

Construct a new template, using the default model template

1
public LLamaTemplate(SafeLlamaModelHandle model, string name, bool strict)

Parameters

model SafeLlamaModelHandle
The native handle of the loaded model.

name String
The name of the template, in case there are many or differently named. Set to 'null' for the default behaviour of finding an appropriate match.

strict Boolean
Setting this to true will cause the call to throw if no valid templates are found.

LLamaTemplate(LLamaWeights, Boolean)

Construct a new template, using the default model template

1
public LLamaTemplate(LLamaWeights weights, bool strict)

Parameters

weights LLamaWeights
The handle of the loaded model's weights.

strict Boolean
Setting this to true will cause the call to throw if no valid templates are found.

LLamaTemplate(String)

Construct a new template, using a custom template.

1
public LLamaTemplate(string customTemplate)

Parameters

customTemplate String

Remarks:

Only support a pre-defined list of templates. See more: https://github.com/ggerganov/llama.cpp/wiki/Templates-supported-by-llama_chat_apply_template

Methods

Add(String, String)

Add a new message to the end of this template

1
public LLamaTemplate Add(string role, string content)

Parameters

role String

content String

Returns

LLamaTemplate
This template, for chaining calls.

Add(TextMessage)

Add a new message to the end of this template

1
public LLamaTemplate Add(TextMessage message)

Parameters

message TextMessage

Returns

LLamaTemplate
This template, for chaining calls.

RemoveAt(Int32)

Remove a message at the given index

1
public LLamaTemplate RemoveAt(int index)

Parameters

index Int32

Returns

LLamaTemplate
This template, for chaining calls.

Clear()

Remove all messages from the template and resets internal state to accept/generate new messages

1
public void Clear()

Apply()

Apply the template to the messages and return a span containing the results

1
public ReadOnlySpan<byte> Apply()

Returns

ReadOnlySpan<Byte>
A span over the buffer that holds the applied template


< Back