module

Fm

Constants

DEFAULT_CONTEXT_TOKENS = 4096

Default context window size for Apple's on-device Foundation Models.

TRANSCRIPT_SKIP_KEYS = {"role", "content", "text", "prompt", "response", "instructions"}
TRANSCRIPT_TEXT_KEYS = {"content", "text", "prompt", "response", "instructions"}
VERSION = "0.1.0"

Class methods

compact_session_if_needed(model : SystemLanguageModel, session : Session, limit : ContextLimit, config : CompactionConfig = CompactionConfig.new, base_instructions : String | Nil = nil) : CompactedSession | Nil

Compacts a session if context usage exceeds the limit. Returns nil if still within budget.

Source
compact_transcript(model : SystemLanguageModel, transcript_json : String, config : CompactionConfig = CompactionConfig.new) : String

Compacts a transcript into a summary using the on-device model.

Source
compacted_instructions(base_instructions : String | Nil, summary : String) : String | Nil

Builds instructions text for a compacted session.

Source
context_usage_from_transcript(transcript_json : String, limit : ContextLimit) : ContextUsage

Estimates token usage from transcript JSON and a context limit.

Source
estimate_tokens(text : String, chars_per_token : Int32) : Int32

Estimates tokens based on a characters-per-token heuristic.

Source
session_from_summary(model : SystemLanguageModel, base_instructions : String | Nil, summary : String) : Session

Creates a new session from base instructions and a summary.

Source
transcript_to_text(transcript_json : String) : String

Extracts readable text from transcript JSON.

Source

Nested types