Skip to main content

ailia LLM Python API

!! CAUTION !! “ailia” IS NOT OPEN SOURCE SOFTWARE (OSS). As long as user complies with the conditions stated in License Document, user may use the Software for free of charge, but the Software is basically paid software.

About ailia LLM

ailia LLM is a library for running LLMs on edge devices. It provides bindings for C++ and Unity.

Install from pip

You can install the ailia LLM free evaluation package with the following command.

pip3 install ailia_llm

Install from package

You can install the ailia LLM from Package with the following command.

python3 bootstrap.py
pip3 install ./

Usage

import ailia_llm

import os
import urllib.request

model_file_path = "gemma-2-2b-it-Q4_K_M.gguf"
if not os.path.exists(model_file_path):
	urllib.request.urlretrieve(
		"https://storage.googleapis.com/ailia-models/gemma/gemma-2-2b-it-Q4_K_M.gguf",
		model_file_path
	)

model = ailia_llm.AiliaLLM()
cpu_backend = next(backend for backend in model.get_backend_list()
                   if backend["backend_name"] == "CPU")
model.set_backend(cpu_backend["idx"])  # Optional; call before open().
model.open(model_file_path, n_ctx=8192)

messages = []
messages.append({"role": "system", "content": "語尾に「わん」をつけてください。"})
messages.append({"role": "user", "content": "あなたの名前は何ですか?"})

stream = model.generate(messages)

text = ""
for delta_text in stream:
	text = text + delta_text
print(text)

if model.context_full():
	raise Exception("Context full")

messages.append({"role": "assistant", "content": text})

Tool Use (JSON API)

Use a model that supports tool calling, such as Gemma 4. Define tools with set_tools(), generate with generate_json(), and read the complete assistant message with get_response_json(). Append the response and tool results to the history, then generate again for the final answer.

import json
import ailia_llm

model = ailia_llm.AiliaLLM()
model.open("gemma-4-E2B-it-Q4_K_M.gguf", n_ctx=8192)
model.set_tools([{"type":"function","function":{
    "name":"get_weather", "description":"Get the current weather.",
    "parameters":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}
}}])
messages = [{"role":"user","content":"What is the weather in Tokyo?"}]
try:
    for _ in range(8):
        for _ in model.generate_json(messages):
            pass  # Consume generation; collecting text deltas is optional.
        if model.context_full():
            raise RuntimeError("Context full; shorten the history.")
        response = model.get_response_json()
        messages.append(response)
        if not response.get("tool_calls"):
            print(response["content"])
            break
        for call in response["tool_calls"]:
            args = json.loads(call["function"]["arguments"])
            # Validate the requested tool and arguments, then execute it here.
            result = {"city": args["city"], "weather": "sunny"}  # Mock result
            messages.append({"role":"tool", "tool_call_id":call["id"],
                             "content":json.dumps(result)})
finally:
    model.set_tools(None)

While tools are enabled, use generate_json() from the first turn instead of generate(). Read the response before clearing tools. Invalid input or incomplete output raises AiliaLLMError; only append successfully parsed responses and execute their complete tool calls.

Images and audio

Load a compatible projector with open_multimodal_projector() and pass media as content parts to generate_json():

model.open_multimodal_projector("mmproj.gguf")
messages = [{"role": "user", "content": [
    {"type": "text", "text": "Describe this image."},
    {"type": "image", "file_path": "/path/to/image.jpg"},
]}]
for delta in model.generate_json(messages):
    print(delta, end="", flush=True)

For audio, use "type": "audio" with a supported file such as WAV, MP3 or FLAC. Use separate prompts for images and audio. Each media part accepts either file_path or data (standard Base64-encoded file bytes). Media works with or without tools, and matching media and conversation prefixes can reuse cached encoder outputs and KV cache.

API specification

https://github.com/ailia-ai/ailia-sdk

Metadata

Release files for ailia-llm 1.5.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ailia-llm 1.5.3
File Size Uploaded Provenance Actions
ailia_llm-1.5.3.tar.gz 44.7 MB Without provenance Details for ailia_llm-1.5.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ailia-llm 1.5.3
File Interpreter ABI Platform Actions
ailia_llm-1.5.3-py3-none-any.whl Python 3 none any Details for ailia_llm-1.5.3-py3-none-any.whl

Total release size: 89.9 MB

Release files / ailia_llm-1.5.3.tar.gz

Download URL ailia_llm-1.5.3.tar.gz
Size 44.7 MB
Tags Source
SHA-256 checksum
How to use checksums
9e0c1f3ef624c1acee1e62377a78b37c5691094d50baf2d8b75b3ec46ec7b517
BLAKE2b-256 checksum
How to use checksums
ccabfedcc7e560a6db11f226555069307b97cf4efbd1e1f81d646f5bb8e6f196
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.13

Release files / ailia_llm-1.5.3-py3-none-any.whl

Download URL ailia_llm-1.5.3-py3-none-any.whl
Size 45.1 MB
Tags Python 3
SHA-256 checksum
How to use checksums
35f0e4fa0a90053cd93eab4bf252e4de7ac91d7ba7fe92e5a06a25463bc8ef8d
BLAKE2b-256 checksum
How to use checksums
0aa88c792ec578f3775b909654e0d769bd7a3d699c6c045f46152554dfad1286
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.13

Security for ailia-llm 1.5.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page