Add Ollama backend adapter for local LLM execution #13
+1,064
−66
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.
Enables running quantcoder-cli with local Ollama models instead of requiring OpenAI API access. Default backend is now Ollama.
Architecture
Backend Adapter Pattern
OllamaAdapter: HTTP client for Ollama API at/api/generateresponse,text,output,choices[])OLLAMA_BASE_URL(default:http://localhost:11434) andOLLAMA_MODEL(default:llama2)Factory Selection
make_backend(): Returns adapter based onBACKENDenv var (default:ollama)Processor Integration
OpenAIHandlernow accepts backend parameter instead of calling OpenAI SDK directlyArticleProcessoruses factory to instantiate backendgenerate_summary,generate_qc_code,refine_code) route throughbackend.chat_complete()Usage
Error Handling
Connection failures provide clear diagnostics:
Unexpected response formats list expected fields:
Testing
21 tests with mocked HTTP calls cover:
Files
New
quantcli/backend.py(147 lines): OllamaAdapter implementationquantcli/backend_factory.py(42 lines): Backend factorytests/test_backend.py(198 lines): Adapter unit teststests/test_backend_factory.py(63 lines): Factory teststests/test_integration.py(151 lines): Integration testsModified
quantcli/processor.py: Refactored OpenAIHandler to use adapters (~50 lines changed)README.md: Added Ollama setup guide and environment variable documentationWarning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
esm.ubuntu.com/usr/lib/apt/methods/https /usr/lib/apt/methods/https(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
This pull request was created from Copilot chat.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.