AiliaLLM

Kotlin binding for ailia LLM library. Provides Large Language Model inference capabilities.

Calls JNI directly from Kotlin without going through Java wrappers.

When using QNN, call destroy or close on the same thread that constructed this instance. For QNN, release resources explicitly on that thread; do not rely on garbage collection.

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open override fun close()

Implements Closeable for use with use { } blocks. When using QNN, this method must be called on the same thread that constructed this instance, as with destroy.

Link copied to clipboard
fun destroy()

Destroys the AiliaLLM instance and releases resources.

Link copied to clipboard

Generates one token.

Link copied to clipboard

Gets the context size of the model.

Link copied to clipboard

Gets the generated text (delta).

Link copied to clipboard

Detail of the last native error; valid until the next native operation.

Link copied to clipboard

Gets the multimodal capabilities of the loaded model.

Link copied to clipboard

Gets the prompt token count.

Link copied to clipboard

Gets buffered assistant JSON. Deltas need not be accumulated by the caller.

Link copied to clipboard

Gets the token count for a text.

Link copied to clipboard
fun openModelFile(path: String, nCtx: Int)

Opens a model file.

Link copied to clipboard
fun openMtpModel(path: String, nDraft: Int)

Open an MTP assistant and enable draft/target verification decoding. Call once after openModelFile and before setting a prompt. Supports text generation with CPU/GPU Gemma 4 GGUF and QNN models.

Link copied to clipboard

Opens a multimodal projector file for vision/audio support. Must be called after openModelFile() to enable multimodal capabilities.

Link copied to clipboard
fun setBackend(index: Int)

Selects a backend returned by getBackendCount and getBackendName. Must be called before openModelFile. HTP (QNN) accepts only .qnn; explicitly selected CPU/GPU backends reject .qnn. Without a selection, the model format determines the backend.

Link copied to clipboard
fun setNumThreads(nThreads: Int)

Sets the CPU thread count before openModelFile. The default is 0 when this method is not called. On Android, automatic selection uses performance (big/prime) cores, falling back to the existing core-count heuristic when topology is unavailable. Target decode/prefill, assistant and VLM/ALM CPU inference threads share this value.

Link copied to clipboard

Sets the prompt for generation.

Sets the prompt for generation with multimodal support. Automatically detects whether to use text-only or multimodal processing based on the presence of media data.

Link copied to clipboard
fun setPromptJson(messagesJson: String)

Sets structured history; required with tools. User content arrays accept text and image or audio parts with file_path or base64 data. Load a matching projector for media. Submit image and audio in separate prompts.

Link copied to clipboard
fun setSamplingParams(topK: Int, topP: Float, temp: Float, seed: Int)

Sets sampling parameters.

Link copied to clipboard
fun setThinking(enable: Boolean)

Enable or disable thinking (reasoning output). Controls whether thinking models (e.g. Gemma4) output their reasoning process. Must be called before setPrompt.

Link copied to clipboard
fun setTools(toolsJson: String?)

Sets the tool (function) definitions for tool use (function calling). The tools are rendered into the prompt through the chat template on the next setPromptJson call, the output is constrained to the tool call syntax, and the buffered output can be retrieved with getResponseJson().