Ailia LLM
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.
Functions
Gets the context size of the model.
Gets the generated text (delta).
Detail of the last native error; valid until the next native operation.
Gets the multimodal capabilities of the loaded model.
Gets the prompt token count.
Gets buffered assistant JSON. Deltas need not be accumulated by the caller.
Gets the token count for a text.
Opens a model file.
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.
Opens a multimodal projector file for vision/audio support. Must be called after openModelFile() to enable multimodal capabilities.
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.
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.
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.
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.
Sets sampling parameters.
Enable or disable thinking (reasoning output). Controls whether thinking models (e.g. Gemma4) output their reasoning process. Must be called before setPrompt.
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().