ML::LLM::Generator
High-level text generation interface
Constants
GPT_OSS_STOPS = ["<|end|>", "<|im_end|>"]
Default stop strings for gpt-oss models
Constructors
Instance methods
ask(question : String, system : String | Nil = nil, max_tokens : Int32 = 256, temperature : Float32 = 0.7_f32) : String
Ask a question and get response (formats prompt automatically)
ask_stream(question : String, system : String | Nil = nil, max_tokens : Int32 = 256, temperature : Float32 = 0.7_f32, &block : String -> ) : Int32
Stream response to a question (filtered - only final answer for gpt-oss)
ask_stream_raw(question : String, system : String | Nil = nil, max_tokens : Int32 = 256, temperature : Float32 = 0.7_f32, &block : String -> ) : Int32
Stream raw response (no filtering)
Calculate tokens per second from wall clock time
context
Sourcefinalize
SourceFormat prompt based on current mode
free
Sourcegenerate(prompt : String, max_tokens : Int32 = 256, stop_on_eos : Bool = true, stop_strings : Array(String) | Nil = nil, temperature : Float32 = 0.8_f32, top_k : Int32 = 40, top_p : Float32 = 0.95_f32) : String
Generate text completion
mean_logprob
Sourcemin_logprob
Sourcemodel
Sourceprompt_mode
Sourceprompt_mode=(prompt_mode : PromptMode)
Sourcestream(prompt : String, max_tokens : Int32 = 256, stop_on_eos : Bool = true, stop_strings : Array(String) | Nil = nil, &block : String -> ) : Int32
Stream generation with callback
token_logprobs
Per-token log-probabilities from last generation (log-softmax of sampled token)
tokens_per_second
Get tokens per second from last generation Note: llama.cpp perf stats may not populate correctly, use wall clock time instead