Skip to content

SafeLLamaGrammarHandle

Namespace: LLama.Native

A safe reference to a llama_grammar

1
public class SafeLLamaGrammarHandle : SafeLLamaHandleBase, System.IDisposable

Inheritance ObjectCriticalFinalizerObjectSafeHandleSafeLLamaHandleBaseSafeLLamaGrammarHandle
Implements IDisposable

Properties

IsInvalid

1
public bool IsInvalid { get; }

Property Value

Boolean

IsClosed

1
public bool IsClosed { get; }

Property Value

Boolean

Methods

ReleaseHandle()

1
protected bool ReleaseHandle()

Returns

Boolean

Create(IReadOnlyList<GrammarRule>, UInt64)

Create a new llama_grammar

1
public static SafeLLamaGrammarHandle Create(IReadOnlyList<GrammarRule> rules, ulong start_rule_index)

Parameters

rules IReadOnlyList<GrammarRule>
A list of list of elements, each inner list makes up one grammar rule

start_rule_index UInt64
The index (in the outer list) of the start rule

Returns

SafeLLamaGrammarHandle

Exceptions

RuntimeError

Create(LLamaGrammarElement, UInt64, UInt64)**

Create a new llama_grammar

1
public static SafeLLamaGrammarHandle Create(LLamaGrammarElement** rules, ulong nrules, ulong start_rule_index)

Parameters

rules LLamaGrammarElement**
rules list, each rule is a list of rule elements (terminated by a LLamaGrammarElementType.END element)

nrules UInt64
total number of rules

start_rule_index UInt64
index of the start rule of the grammar

Returns

SafeLLamaGrammarHandle

Exceptions

RuntimeError

Clone()

Create a copy of this grammar instance

1
public SafeLLamaGrammarHandle Clone()

Returns

SafeLLamaGrammarHandle

AcceptToken(SafeLLamaContextHandle, LLamaToken)

Accepts the sampled token into the grammar

1
public void AcceptToken(SafeLLamaContextHandle ctx, LLamaToken token)

Parameters

ctx SafeLLamaContextHandle

token LLamaToken