ion7-core / sampler.common

class

ion7.core.CSampler

_ptr cdata `ion7_csampler_t*` (auto-freed via ffi.gc).
_tw_anchor table String anchors for `trigger_words` (GC-pinning).

Functions

CSampler.new

Create a CSampler.

CSampler.new(model, opts)
modelcdata|table`llama_model*` or a `Model` instance.
optstable?Sampling parameters (see module header for
→ ion7.core.CSampler

raises — When the bridge call returns NULL (typically a malformed

CSampler:sample

Sample the next token AND auto-accept it. Drop-in compatible with `Sampler:sample` for the same chain semantics. Single FFI crossing per generated token (the bridge wraps sample + accept in one call).

CSampler:sample(ctx, idx)
ctxcdata`llama_context*`.
idxinteger?Logit position (default `-1` = last).
→ integerSampled token id.

CSampler:accept

Manually notify the sampler that `token` was accepted. Rarely needed (`sample` already auto-accepts) ; useful when you sample via another path and still want the DRY / Mirostat state updated.

CSampler:accept(token)

CSampler:reset

Reset every internal counter (DRY history, Mirostat state, grammar automaton position).

CSampler:reset()

CSampler:last

Last accepted token id, or `-1` if no token has been accepted yet on this sampler.

CSampler:last()
→ integer

CSampler:seed

Effective RNG seed used by this instance.

CSampler:seed()
→ integer

CSampler:free

Free the sampler before GC. Idempotent. Disarms the `ffi.gc` finalizer so the GC does not double-free later.

CSampler:free()