llama-cpp-python #6627
-
|
Hello Flet team! I am building a local AI agent app for Android/iOS using Flet. I rely on Because Package Details:
Could we get Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
|
We already have it working, and it will be shipped soon: flet-dev/mobile-forge#91 |
Beta Was this translation helpful? Give feedback.
-
|
This is really exciting news for the community! It’s great to see that the request is being addressed so quickly by the contributors. |
Beta Was this translation helpful? Give feedback.
-
|
Hi @ndonkoHenri! Thank you so much for putting this recipe together. Having 5 out of the 6 platform matrices green (especially Android 3.12–3.14 and iOS 3.13–3.14) is amazing progress! I noticed that the iOS build for Python 3.12 is currently the only compilation failing on the CI, along with the Since I'm targeting Android first for my app, is there any way I can download and test the compiled Android Python 3.12 wheels locally in my project? Also, let me know if there's anything I can help with to help get the Python 3.12 iOS build resolved or tested! |
Beta Was this translation helpful? Give feedback.
-
|
It's a CPU-only build (all GPU backends — Metal/CUDA/Vulkan/OpenCL — and OpenMP are disabled, since none are portable across mobile), which is plenty for the quantized models that realistically fit on a phone. Everything runs offline; the only network you need is a one-time model download. InstallAdd it to your deps: # pyproject.toml
dependencies = [
"flet",
"llama-cpp-python",
]
[tool.flet.android]
target_arch = ["arm64-v8a", "x86_64", "armeabi-v7a"] # if on Flet < 0.86Storage & the model file (the important bit)GGUF weights are large — a 1–3B import os, urllib.request
data_dir = os.getenv("FLET_APP_STORAGE_DATA")
model_path = os.path.join(data_dir, "model.gguf")
if not os.path.exists(model_path):
urllib.request.urlretrieve("https://<your-host>/model.gguf", model_path)
Minimal usageimport os
from llama_cpp import Llama
model_path = os.path.join(os.getenv("FLET_APP_STORAGE_DATA"), "model.gguf")
llm = Llama(
model_path=model_path,
n_ctx=2048, # keep modest on mobile RAM
n_threads=4,
n_gpu_layers=0, # CPU only
verbose=False,
)
out = llm("The capital of France is", max_tokens=32, stop=["\n"])
print(out["choices"][0]["text"])Run it off the UI threadModel load and generation are CPU-bound and take a while — do them in What actually runs well
Let me know if you face any issues! |
Beta Was this translation helpful? Give feedback.
llama-cpp-python0.3.32.1 is now supported on Android and iOS: https://pypi.flet.dev/llama-cpp-pythonIt's a CPU-only build (all GPU backends — Metal/CUDA/Vulkan/OpenCL — and OpenMP are disabled, since none are portable across mobile), which is plenty for the quantized models that realistically fit on a phone. Everything runs offline; the only network you need is a one-time model download.
Install
Add it to your deps:
Storage & the model file (the important bit)
GGUF weights are large — a 1–3B
Q4model is ~0.7–2 GB — so don'…