Initialize the model
The runtime exposes a set of C-style functions. Use ccall to call them from JavaScript:
LogAddFilePointer()(optional; call before init)InitNLM(modelPath)to create a model instance
Note: Logging
Logs are read from the in-memory filesystem (MEMFS) under /logs. Create the directory before enabling logging:
// Create the logs directory
module.FS.mkdir('/logs');
// List log files
const logFiles = module.FS.readdir('/logs');
// Read a log file
const logData = module.FS.readFile('/logs/inference.log');
const logText = new TextDecoder('utf-8').decode(logData);
Initialize the model by calling InitNLM with the model path:
module.ccall('LogAddFilePointer', null, [], []);
const instance = module.ccall('InitNLM', 'number', ['string'], ['/model']);
InitNLM returns a pointer that represents the model instance. You must hold onto this pointer for inference and cleanup.
Other exported functions:
Delete(instancePtr)to free the model instance.Inference(instancePtr, prompt)to run the model.OutputNLM(instancePtr)to read the output buffer.LogSetSilent(...)for runtime logging control.
Databiomes