Local AI has been gaining attention in recent years. However, when people hear the term “local AI,” many may imagine running a ChatGPT-like conversational AI in a local environment.
In reality, current Raspberry Pi systems are not practical for this kind of use. Even on Macs and high-performance PCs, local LLM chat still falls far short of cloud-based AI, making it even more challenging on a Raspberry Pi.
Does this mean that local LLMs have no value on resource-constrained IoT devices? I don’t think so.
On a Raspberry Pi, rather than having “AI think,” I believe a more practical use is to “convert ambiguous instructions written by humans into formats that computers can process.”
In this article, we will try using a local LLM on a Raspberry Pi as this kind of “conversion engine.”
Ollama, which is used in this article, is software for running LLMs locally. We will use it to run Gemma2: 2b or Gemma3: 1b.
For the tasks tested in this article, these models are just about practical enough to run on a Raspberry Pi system with 4 GB of memory.
Local AI
Runtime: Ollama
LLM: Gemma2: 2b or Gemma3: 1b
Industrial Raspberry Pi "PL-R5"
Test Environment:
Model: Raspberry Pi Compute Module 5 Rev 1.0
OS: Debian GNU/Linux 13 (trixie)
Kernel: 6.18.29+rpt-rpi-2712
MEM: 4 GB
Installing Docker
First, install Docker to run Ollama on the PL-R5.
Ollama can also be installed directly, but I chose Docker because it makes setup easier and helps avoid affecting the system environment and dependencies.
# Install Docker
sudo apt update && sudo apt full-upgrade -y
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker USERNAME
sudo apt install -y libffi-dev libssl-dev python3 python3-dev python3-pip
# Install dockerd-rootless-setuptool
sudo apt install uidmap
dockerd-rootless-setuptool.sh install
The versions used in this test are as follows.
docker -v
Docker version 29.6.1, build 8900f1d
docker compose version
Docker Compose version v5.2.0
Create docker-compose.yaml as shown below and start it with docker compose up -d.
services:
ollama:
image: ollama/ollama:latest
container_name: ollama
ports:
- "11434:11434"
volumes:
- ollama:/root/.ollama
restart: unless-stopped
volumes:
ollama:
Ollama was installed using the latest image, which was version 0.30.11 at the time of testing.
docker exec ollama ollama --version
ollama version is 0.30.11
Ollama is now ready to use with Docker.
Downloading Gemma
Since Ollama is running in Docker, use the exec command to download gemma3:1b and gemma2:2b.
docker exec -it ollama ollama pull gemma3:1b
docker exec -it ollama ollama pull gemma2:2b
For reference, here are some example commands for operating Ollama inside the container:
docker exec -it ollama ollama list
docker exec -it ollama ollama pull gemma3:1b
docker exec -it ollama ollama run gemma3:1b
docker exec -it ollama ollama ps
From this point on, Docker is used only to run Ollama.
The program that uses AI does not need to be aware of Docker; it simply calls the API at http://localhost:11434.
Format Conversion: JSON, Samba, YAML, Markdown, etc.
Unless a dedicated tool is available, manually writing data in a specific format can lead to mistakes.
Take JSON, for example.
From a non-engineer’s perspective, JSON can feel difficult to write manually. I often forget commas or make mistakes with the nesting structure.
I thought it would be useful if we could provide the JSON fields as simple natural-language text and have the LLM convert them into the required format.
Even if the output is not perfect, correcting the generated result could still save time compared with writing everything from scratch.
The prompts in the following tests were originally written in Japanese. For readability, the instructions are translated into English, while the input data is shown as originally entered.
Convert the following items into JSON format. Do not output any explanations or commentary.
タイトル: Raspberry Pi
説明: 小型コンピューター
価格: 12,800円
画像: raspi.jpg
Run the Python program described later in this article.
python3 convert.py
The result was mostly successful.
{
"title": "Raspberry Pi",
"description": "小型コンピューター",
"price": 12800,
"image": "raspi.jpg"
}
The yen unit disappeared, probably because the price was interpreted as a numeric value. Other than that, the English field names were reasonable, and no unnecessary fields were added.
Even when the fields are written in Japanese, the conversion can be performed simply by including a prompt (instructions to the LLM) at the beginning of the input file specifying the desired output format.
Example Program
As in the JSON conversion test, here is an example program that sends the text to be converted to the local LLM for processing.
The LLM model can be changed simply by replacing the model name, such as MODEL = "gemma2:2b". Commenting out one line makes it easy to switch between models.
#!/usr/bin/env python3
from pathlib import Path
import requests
OLLAMA_URL = "http://localhost:11434/api/generate"
# MODEL = "gemma3:1b"
MODEL = "gemma2:2b"
prompt = Path("input.txt").read_text(encoding="utf-8")
response = requests.post(
OLLAMA_URL,
json={
"model": MODEL,
"prompt": prompt,
"stream": False,
},
timeout=120,
)
response.raise_for_status()
result = response.json()["response"].strip()
Path("output.txt").write_text(result, encoding="utf-8")
print("Done: output.txt has been generated")
The file structure is also kept simple. The result is written to output.txt, requiring only three files.
project/
├── input.txt
├── output.txt
└── convert.py
Next, we will write various types of natural-language input in input.txt and try formats other than JSON.
Trying Other Formats
For format conversion, we could also convert a Markdown file into JSON, or vice versa.
Let’s enter the following into input.txt and try it.
Markdown → JSON
Convert the following items into JSON format. Do not output any explanations or commentary.
| 品名 | 数量 | メモ |
|---|---:|---|
| キャベツ | 1/2 | 夕食用 |
| 豚肉 | 400g | メイン |
The result was very close.
The gram unit disappeared.
An item field was also added as a top-level element, although this is not structurally incorrect.
{
"item": [
{
"品名": "キャベツ",
"数量": 0.5,
"メモ": "夕食用"
},
{
"品名": "豚肉",
"数量": 400,
"メモ": "メイン"
}
]
}
The result seems more useful than expected.
Natural-Language Text → YAML
YAML is a format commonly used for configuration files. This test was unsuccessful.
Create a docker-compose.yaml file based on the following requirements. Do not output any explanations or commentary.
nginxを起動
80番を公開
htmlフォルダを共有
The resulting structure was generally correct, but some details were inaccurate.
version: '3'
services:
web:
image: nginx:latest
ports:
- "80:80" # 80ポートの公開
volumes:
- ./:/var/www/html # htmlフォルダを共有
versionis unnecessary in Compose V2../and/var/www/htmlare somewhat questionable.8080:80may have been what was intended, but the model got it wrong.
Since the overall structure is correct, it might become usable with more explicit instructions.
smb.conf Share Section
I also thought generating a share section for smb.conf could be useful.
As before, we modify the first line of the prompt and run the program.
Create the following as a Samba share section. Do not output any explanations or commentary.
共有名: public
パス: /srv/public
ゲスト可
読み書き可能
The structure is correct, and there do not appear to be any errors in the share section. However, unnecessary explanations were added.
[Public]
path = /srv/public
browseable = yes
writable = yes
guest ok = yes
read only = no
**Explanation:**
* **`[Public]`**: This is the Samba share name. It's used to identify the specific shared folder you want to create.
* **`path = /srv/public`**: This tells Samba where your share should be located on your server (replace `/srv/public` with the actual path).
* **`browseable = yes`**: Users can browse the folder contents using Windows Explorer or other file managers.
* **`writable = yes`**: Users are allowed to write files and modify data in this shared folder.
* **`guest ok = yes`**: This makes the share accessible to non-authenticated users (guests) on your network. It's recommended for providing guest access to resources.
* **`read only = no`** : Allows for writing and modifying files.
Remember that you need a Samba server running on your system to apply these settings
Even when input.txt, which contains the prompt, explicitly says “Do not output any explanations or commentary,” Gemma still seems eager to provide an explanation. I encountered the same behavior several times.
It would also be interesting to test whether it can generate or convert the following formats.
- Docker Compose
- nginx
- systemd
- SQL
- Regular expressions
- Obsidian Front Matter
Naming
The next thing I tried was naming.
By naming, I mean generating variable names, class names, and similar identifiers used in programs.
This is closer to a generative AI task, so I was curious to see how it would perform, since generative AI is difficult to run effectively in a local environment.
For a limited role such as a “naming assistant,” however, even a Pi 5/CM5 was capable enough.
As a non-engineer, I sometimes wonder how engineers decide on names.
- HTML class names
- CSS selectors
- JavaScript variables
- Python variables
- JSON keys
I usually write only relatively short and simple code for personal use, so I tend to come up with names on the fly.
For example, if the base name is user:
user_name
user_email
user_id
user_list
selected_user
current_user
new_user
update_user
delete_user
user_count
Generating a list of names that are likely to be used from the beginning could be convenient and make the naming scheme easier to review.
For this test, I entered the following into input.txt.
The scenario assumes CSS class names used in HTML.
As expected, the response took longer than the previous tests.
Suggest CSS class names for the following page structure.
Conditions
- Use BEM notation.
- Use common English words.
- Do not output HTML or CSS.
- Output class names only.
- No explanation is needed.
画面構成
ページ全体
ヘッダー
サイトロゴ
ナビゲーション
メイン
記事一覧
記事カード
記事画像
記事タイトル
投稿日
続きを読むボタン
フッター
The result was better than expected.
The only issue was that it did not appear to understand BEM notation, so it generated ordinary class names instead.
BEM uses a naming format such as .article-card--featured, following the Block__Element--Modifier structure.
.page { /* Page */ }
.header { /* Header */ }
.site-logo { /* Site logo */ }
.navigation { /* Navigation */ }
.main { /* Main */ }
.article-list { /* Article list */ }
.article-card { /* Article card */ }
.article-image { /* Article image */ }
.article-title { /* Article title */ }
.post-date { /* Post date */ }
.read-more-button { /* Read more button */ }
.footer { /* Footer */ }
I thought this might work with additional instructions in the prompt, so I modified the conditions slightly.
Conditions
- Use BEM notation.
- Blocks must stand alone.
- Elements must use Block__Element.
- Modifiers must use Block--Modifier.
- Element modifiers must use Block__Element--Modifier.
- Output class names only.
- Do not output HTML or CSS.
- No explanation is needed.
The model seems to have interpreted this as a hierarchy, resulting in an output that was even further from what was intended.
- .page
- .header
- .site-logo
- .navigation
- .main
- .article-list
- .article-card
- .article-image
- .article-title
- .post-date
- .read-more-button
- .footer
Summary of Results
What we found from these tests is that Gemma3:1b and Gemma2:2b were generally capable of generation and conversion tasks. On the other hand, even when instructed not to provide explanations, the models sometimes added commentary, meaning that some outputs could not be copied and pasted as-is. Their older training data can also have an impact, so generated configuration files need to be checked carefully.
- Generation and conversion generally work
- Training data is outdated
Of course, the results could be different with more precise prompts or larger AI models. These observations apply specifically to small-parameter LLMs like those used in this test.
Response time is another concern. Even for tests of this level, responses took several tens of seconds. Using complex programs or prompts is therefore not particularly recommended with small-parameter LLMs.
As shown in the table, converting Markdown to JSON produced the result closest to what was intended, while the naming task also produced acceptable results. The Samba share section was correctly formatted as well, aside from the unnecessary explanation that was added.
Considering that these are AI models with only 1B or 2B parameters, the results were reasonably good.

These tests showed that even the PL-R5 or Pi 5/CM5 can produce practical results as a local LLM platform when an appropriate LLM is selected for the intended task.
PiLink has recently released “PLECO” as the successor to the PL-R5. PLECO can be equipped with the Hailo-10H.
The Hailo-10H is designed for generative AI applications including chat, RAG, and image + LLM workloads, enabling more advanced local LLM processing.
Article contributed by Raspida
Raspida operates raspida.com, a Raspberry Pi information website designed to make Raspberry Pi enjoyable and accessible even for non-engineers. Drawing on many years of hands-on experience with Raspberry Pi, the site publishes a wide range of useful information and topics for both experienced users and those interested in getting started. Raspida also contributes technical blog articles about industrial Raspberry Pi systems to the PiLink website.


