feat: OpenAI-compatible inference backend alongside Ollama - #7
Merged
Merged
Conversation
…Studio) Adds PW_INFERENCE_BACKEND=ollama|openai + PW_INFERENCE_API_BASE to council/ollama.py, the single shared HTTP client used by worker, researcher, judge, batch, and rerank. On the default (ollama) backend behavior is unchanged. On openai, base()/generate()/smallest_chat_model() speak the OpenAI-compatible /v1/chat/completions + /v1/models shape that llama.cpp-server and LM Studio expose, giving every council/ollama.py caller a new backend option with zero changes to those callers. Other direct-to-Ollama call sites (council/local.py, council/library.py, council/doctor.py, council/net/agent.py, council/net/baseline.py, council/operator.py) are intentionally out of scope and remain Ollama-only, per the task boundary. Adds tests/test_ollama.py (module had zero dedicated tests) covering base() resolution on both backends, generate()'s request shape on both backends, resolve_timeout() precedence, and KNOWN registry entries. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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
Adds
PW_INFERENCE_BACKEND=ollama|openai+PW_INFERENCE_API_BASEtocouncil/ollama.py, the single shared HTTP client used byworker,researcher,judge,batch, andrerank. Since every one of those callers already goes through this one module'sbase()/generate()/smallest_chat_model(), this gives all five a new backend option with zero changes to those callers.ollama, or unset): behavior unchanged —/api/generate+/api/tags,PW_OLLAMA_BASE.PW_INFERENCE_BACKEND=openai: speaks the OpenAI-compatible/v1/chat/completions+/v1/modelsshape that both llama.cpp-server and LM Studio expose out of the box (2026), resolving the endpoint fromPW_INFERENCE_API_BASE(no hardcoded default — there's no sane guess for an arbitrary local port the waylocalhost:11434is for Ollama).generate()'s public signature and return shape (tuple[str, int]of (text, tokens)) are unchanged; internally it now dispatches to_generate_ollama/_generate_openai. The openai path mirrors the existing Ollama path's error-tolerance contract exactly (0 tokens / empty text on a missing field, never a crash).Out of scope (intentional)
Other call sites that talk to Ollama directly (
council/local.py,council/library.py,council/doctor.py,council/net/agent.py,council/net/baseline.py,council/operator.py) are not routed through this dispatch and remain Ollama-only — documented as a known limitation in the module's docstring, not an oversight. D1 (no token), D4 (no proxied traffic), and D18 (no browser automation) are unaffected — this is purely a local-inference-runtime choice.Config
Registered
PW_INFERENCE_BACKENDandPW_INFERENCE_API_BASEincouncil/config.py'sKNOWNregistry so they're discoverable viapw config list.Tests
New
tests/test_ollama.py(module had zero dedicated tests before this PR):base()resolution on both backends,generate()'s request shape on both backends (mockedrequests.post, asserted on URL/body),resolve_timeout()precedence, and the two newKNOWNkeys.Verification
python -m py_compile council/ollama.py council/config.py tests/test_ollama.py— cleanruff check .— all checks passedpytest tests/ -q— 521 passed, 1 skipped, 0 failed (full suite, including everything touchingcouncil/ollama.py/council.config.KNOWN)osand the already-corerequestspackage, so thecore-install-no-extrasCI smoke job is unaffected.🤖 Generated with Claude Code