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 ailiaLLMSetPromptJson from the first user message while tools are configured.
The legacy ailiaLLMSetPrompt and ailiaLLMSetMultimodalPrompt return INVALID_STATE until tools are cleared.
Define tools with ailiaLLMSetTools, set the JSON messages array, and call ailiaLLMGenerate until done.
Deltas remain available through ailiaLLMGetDeltaText for previews; retrieving or concatenating them is optional.
Retrieve assistant JSON with ailiaLLMGetResponseJsonSize / ailiaLLMGetResponseJson, append the object to history,
execute complete calls, and append tool results with matching tool_call_id. Set the next JSON prompt to continue.
The SDK accumulates generated output. Reads do not consume it; a new prompt resets it.
Structured history
[
{"role":"user","content":"Weather in Tokyo?"},
{"role":"assistant","content":"","tool_calls":[
{"id":"call_0","type":"function","function":{"name":"get_weather","arguments":"{\"city\":\"Tokyo\"}"}}
]},
{"role":"tool","tool_call_id":"call_0","content":"Snow, -3 C"}
]
Content is not reparsed as tool syntax. Supply assistant thinking in reasoning_content.
Arguments must be a string containing a JSON object. Call IDs/names must be nonempty; IDs are unique per assistant,
but may be reused in later turns. Consecutive tool results match the preceding assistant by ID, not order.
Unknown IDs, duplicate results and conflicting names are rejected. Tool content must be a string; serialize objects first.
Images and audio
Load a compatible projector with ailiaLLMOpenMultimodalProjectorFileA and use ordered user content parts:
[{"role":"user","content":[
{"type":"text","text":"Describe this image and audio."},
{"type":"image","file_path":"/path/to/image.jpg"},
{"type":"audio","file_path":"/path/to/audio.wav"}
]}]
Each image/audio part specifies exactly one of file_path or data. Data is standard padded Base64 containing
encoded file bytes (JPEG/PNG, WAV/MP3/FLAC, etc.). No URL fetching, video or raw RGB/PCM is supported.
Media works with or without tools and is re-evaluated each prompt. An unloaded/incompatible projector returns INVALID_STATE.
Query image/audio support with ailiaLLMGetMultimodalCapabilities.
Incomplete output and errors
GetResponseJson rejects unfinished calls/thinking with PARSE_ERROR. It never repairs arguments or returns executable partial results. SetPromptJson rejects incomplete arguments, invalid JSON/types/ID associations and empty arrays with INVALID_ARGUMENT. If GetResponseJson returns PARSE_ERROR, do not append the failed assistant. Append a retry user message to the existing history; no partial content/reasoning retrieval is needed. Do not invent tool results.
After clearing tools with SetTools(NULL), SetPromptJson still accepts historical tool calls and results for summaries or final answers. Retrieve response JSON before clearing tools, which invalidates the output parser. Use finally to clear tools even when an exception occurs. An unset prompt or changed tools/thinking returns INVALID_STATE; before generation an initialized prompt returns an empty assistant. File failures return ERROR_FILE_API, invalid Base64 returns INVALID_ARGUMENT, and undecodable media buffers return ERROR_BUFFER_API.
# Tool Use with SDK-buffered responses. Deltas are optional previews.
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?"}]
for turn in range(8):
for delta in model.generate_json(messages):
print(delta, end="", flush=True) # optional preview; no accumulation
response = model.get_response_json() # raises on incomplete output
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 and execute the tool in the application. Mock result here.
result = {"city": args["city"], "weather": "sunny"}
messages.append({"role":"tool", "tool_call_id":call["id"],
"content":json.dumps(result)})
model.set_tools(None)
API specification
Metadata
Release files for ailia-llm 1.5.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ailia_llm-1.5.0.0.tar.gz | 39.0 MB | Without provenance | Details for ailia_llm-1.5.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ailia_llm-1.5.0.0-py3-none-any.whl | Python 3 | none | any | Details for ailia_llm-1.5.0.0-py3-none-any.whl |
Total release size: 78.4 MB
Release files / ailia_llm-1.5.0.0.tar.gz
| Download URL | ailia_llm-1.5.0.0.tar.gz |
|---|---|
| Size | 39.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
16eac3c93a1945004ac0f95824ba0480e599c7b53a90f1705933a91cddb461bc
|
|
BLAKE2b-256 checksum How to use checksums |
e29e55d8b202daf220c8ee810b96730ad6ae344e9d54b303371bdf33394be3d2
|
| 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.0.0-py3-none-any.whl
| Download URL | ailia_llm-1.5.0.0-py3-none-any.whl |
|---|---|
| Size | 39.4 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a1b6002f778b628d147975930350a61ce0c7c96a4405056eceff33e831646c64
|
|
BLAKE2b-256 checksum How to use checksums |
6c31389bc35a47a12fb2ff526d795e0910b8c56127ba129d2228a316c9cf78a2
|
| 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.0.0
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.