R6 class for managing local Small Language Model inference.
Provides a unified interface for loading model weights, running inference,
and managing model lifecycle.
Public fields
model_path
Path to the model weights file.
model_name
Human-readable model name.
backend
The inference backend ("onnx", "torch", "gguf").
config
Model configuration parameters.
loaded
Whether the model is currently loaded in memory.
Methods
Method new()
Create a new SLM Engine instance.
Arguments
model_path
Path to the model weights file (GGUF, ONNX, or PT format).
backend
Inference backend to use: "gguf" (default), "onnx", or "torch".
config
Optional list of configuration parameters.
Returns
A new SlmEngine object.
Load the model into memory.
Returns
Self (invisibly).
Method unload()
Unload the model from memory.
Returns
Self (invisibly).
Method generate()
Generate text completion from a prompt.
Usage
SlmEngine$generate(
prompt,
max_tokens = 256,
temperature = 0.7,
top_p = 0.9,
stop = NULL
)
Arguments
prompt
The input prompt text.
max_tokens
Maximum number of tokens to generate.
temperature
Sampling temperature (0.0 to 2.0).
top_p
Nucleus sampling parameter.
stop
Optional stop sequences.
Returns
A list with generated text and metadata.
Method stream()
Stream text generation with a callback function.
Usage
SlmEngine$stream(
prompt,
callback,
max_tokens = 256,
temperature = 0.7,
top_p = 0.9,
stop = NULL
)
Arguments
prompt
The input prompt text.
callback
Function called with each generated token.
max_tokens
Maximum number of tokens to generate.
temperature
Sampling temperature.
top_p
Nucleus sampling parameter.
stop
Optional stop sequences.
Returns
A list with the complete generated text and metadata.
Method info()
Get model information and statistics.
Returns
A list with model metadata.
Print method for SlmEngine.
Method clone()
The objects of this class are cloneable with this method.
Usage
SlmEngine$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.