feat: add optional Ollama backend for local LLM commit messages - #4
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A second
Generatorimplementation that calls a local Ollama serverinstead 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
generator.Generatorinterface as heuristic —main.godidn'tneed structural changes, just a
--backendflag and a selectionfunction.
IsAvailable()checks the server before use.models fast.
httptest, so the suite passeswith zero setup — no Ollama required to run
go test.Testing
server, empty response, availability checks)
on a real staged diff — produced a working commit message with zero
cloud dependency