Private blog-post descriptions and tags from a local Gemma model in Node.js
- Hardware
- MacBook Pro with M4 Pro and 48 GB of unified memory
- Models & engines
- Ollama 0.40.14 and Node.js 22, no npm dependencies
Models tested: gemma3:1b (Q4_K_M, Q8_0, FP16), gemma3:4b and gemma4:26b - Key gotcha
- Putting maxLength in the schema just cut the description off mid-sentence at 160 characters.
What they built
Flavio's blog has 2,261 posts, each with a hand-written description and tag. He wanted a model to suggest them, but the posts that need help are drafts he would rather not send to an API, so he built the feature on a model running on his Mac with Ollama.
The script reads a post, asks the model for a JSON object with a description and one of 19 allowed tags, checks the answer against rules in code, and prints a suggestion. If Ollama isn't running, the model isn't installed, the request takes longer than 20 seconds, or the answer breaks a rule, it prints a suggestion built from the post itself instead.
The frontmatter he writes stays the source of truth: the script only suggests, and a source field says whether a suggestion came from the model or the fallback.
Setup
- MacBook Pro with M4 Pro and 48 GB of unified memory
- Ollama 0.40.14 and Node.js 22, no npm dependencies
- Models tested: gemma3:1b (Q4_K_M, Q8_0, FP16), gemma3:4b and gemma4:26b
- num_ctx 4096, temperature 0, fixed seed, num_predict 150, posts cut at 6,000 characters
How it works
- Ollama's format field takes a JSON Schema with the tag as an enum, so the output always has the right shape.
- Length and content rules live in a validate() function, not the schema: 50 to 160 characters, a full sentence, no em dash, no filler opening, and every number must appear in the post.
- A rejected answer is sent back once with the list of problems; after that the script falls back.
- Timeouts and Ctrl+C cancellation are combined with AbortSignal.any(); expected failures become a ProviderError with a kind such as timeout, unreachable or rejected.
- A second provider talks to any OpenAI-compatible endpoint, and the model is pinned by its digest so a changed tag can't silently swap the weights.
Results & numbers
- On a 24-post evaluation set, gemma4:26b passed 23 of 24, gemma3:4b passed 14 of 24, and all three gemma3:1b quantizations passed 2 of 24; the no-model fallback passed 13 of 24.
- gemma3:4b took about 3 seconds per post warm; gemma4:26b had a median of about 3 seconds while holding 17.7 GiB of memory.
- Prompt wording alone took gemma3:4b from 0 to 14 passing cases; asking for 'at most 18 words' worked better than a character count.
Gotchas
- Putting maxLength in the schema just cut the description off mid-sentence at 160 characters.
- ollama ps reported far less memory than the llama-server process actually held (1.4 to 1.6 GB versus 17.7 GiB for gemma4:26b); trust the process.
- Quantization didn't change the 1B result for this task; parameter count mattered more than precision.
- Automatic checks verify shape, not whether a sentence summarizes the post, so he still reads every suggestion.
“For this feature I picked local because drafts stay on my laptop and the script works on a plane, not to save money.”— Flavio Copes
Do it yourself
- Install Ollama and run ollama pull gemma3:4b.
- Write down the contract first: inputs, the exact output fields, and the rules a good answer must pass.
- Call http://127.0.0.1:11434/api/chat with stream false, a JSON schema in format, temperature 0 and a seed.
- Validate every answer in code and retry once with the validator's errors.
- Add a timeout and a deterministic fallback so the script still produces something when the model fails.
- Build a small evaluation set from your own real data and rerun it whenever you change the model or prompt.
Similar setups
A read-only Gemma 4 agent on Ollama that explains what fills a Mac's disk
A sysadmin's one-file Python agent lets Gemma 4 on Ollama dig through his home folder and write a Markdown report on disk usage, while code and a four-line macOS sandbox-exec profile make sure it can only look.
Getting OpenCode to work with a local Ollama model by fixing the 4,096-token context
OpenCode on a local Ollama model ignored files, invented tasks or looped, because each ~23k-token request was silently cut to fit Ollama's default 4,096-token context on a 16 GB GPU.
PatchPal TinyAgent: a coding agent on a 4B model and a 6GB laptop GPU
WiseProbe adapted its PatchPal coding agent to run Gemma 4 E4B or Qwen3.5 4B through Ollama on a 6GB RTX A1000, using handoff-note compaction and capped file reads to work inside a 16K or 32K window.
Ghost in the Machine: a fake 1998 terminal where a local Gemma 3 whispers back at every command
A Hacktoberfest entry in a single HTML file: you type into a simulated old shell and a presence called the tenant answers each command with one eerie line, streamed from Gemma 3 4B on Ollama.