Skip to content

feat: add optional Ollama backend for local LLM commit messages - #4

Merged
zorhehs merged 1 commit into
mainfrom
feature-ollama-backend
Aug 22, 2026
Merged

feat: add optional Ollama backend for local LLM commit messages#4
zorhehs merged 1 commit into
mainfrom
feature-ollama-backend

Conversation

@zorhehs

@zorhehs zorhehs commented Aug 22, 2026

Copy link
Copy Markdown
Owner

What

A second Generator implementation that calls a local Ollama server
instead of using heuristics — fully offline, no API key, no cloud.

Usage

commitcraft --backend ollama # uses default model (llama3.2:1b)
commitcraft --backend ollama --model phi3 # pick a different pulled model

If Ollama isn't running, commitcraft prints a warning and falls back to
the heuristic backend automatically rather than failing.

Design

  • Same generator.Generator interface as heuristic — main.go didn't
    need structural changes, just a --backend flag and a selection
    function.
  • IsAvailable() checks the server before use.
  • Diff is truncated to 6000 chars in the prompt to keep small local
    models fast.
  • Tests fake the Ollama HTTP API with httptest, so the suite passes
    with zero setup — no Ollama required to run go test.

Testing

  • 8 new unit tests (response parsing, server errors, unreachable
    server, empty response, availability checks)
  • All 21 tests across the project pass
  • Verified end-to-end against a real local Ollama server (llama3.2:1b)
    on a real staged diff — produced a working commit message with zero
    cloud dependency

Implements the same Generator interface as heuristic, calling a local
Ollama server (default http://localhost:11434) instead of using rules.
Fully offline — no API key, no network egress, runs on the user's own
hardware.

- --backend ollama opts in; --model picks the model (default llama3.2:1b)
- IsAvailable() pings the server before use; if unreachable, main.go
  prints a warning and falls back to the heuristic backend rather than
  failing outright
- Diff is truncated to 6000 chars before prompting, to keep small local
  models fast
- Tests use httptest to fake the Ollama API, so they pass without
  Ollama installed

Verified end-to-end against a real local Ollama server (llama3.2:1b)
on a real staged diff (ai-research-summarizer/src/app.py) — produced
a working commit message with zero cloud dependency.
@zorhehs
zorhehs merged commit b2b941f into main Aug 22, 2026
1 check passed
@zorhehs
zorhehs deleted the feature-ollama-backend branch August 22, 2026 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant