class Llama::Session

Overview

Stateful text facade. The canonical transcript is rebuilt before each turn; this conservative strategy keeps stop-truncated text and native KV state in agreement until incremental token reconciliation is introduced.

Included Modules

Defined in:

llama/session.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(model : Model, context_options : ContextOptions = ContextOptions.new) #

[View source]

Instance Method Detail

def close : Nil #

[View source]
def closed? : Bool #

[View source]
def finalize #

[View source]
def free : Nil #

[View source]
def generate(prompt : String, options : GenerationOptions = GenerationOptions.new, &block : GenerationChunk -> ) : Generation #

[View source]
def generate(prompt : String, options : GenerationOptions = GenerationOptions.new) : Generation #

[View source]
def load(path : String) : Nil #

[View source]
def reset : Nil #

[View source]
def restore(value : SessionSnapshot) : Nil #

Restores canonical text only after every compatibility check succeeds. The next generation rebuilds native KV state through checked decode.


[View source]
def save(path : String) : Nil #

[View source]
def snapshot : SessionSnapshot #

[View source]
def to_unsafe #

[View source]
def transcript_token_count(add_special : Bool = true, parse_special : Bool = true) : Int32 #

Returns logical transcript tokens. An empty transcript is always zero; callers can explicitly choose tokenizer special-token behavior.


[View source]
def used_tokens : Int32 #

Returns the historical tokenization count, including the vocabulary's default special-token behavior. This is not native KV-cache occupancy.


[View source]