pkg/miner: pluggable inference-engine backend interface (closes 3 TODOs)#2
Merged
Merged
Conversation
Close three `// TODO: Integrate with actual ...` stubs in pkg/miner/miner.go (runInference, runChat, runEmbedding) by introducing a small pluggable backend interface. The miner now dispatches through backend.InferenceBackend rather than inlining placeholder output. Two reference backends ship in-tree: - pkg/miner/backend/noop — deterministic mock, byte-for-byte identical to the pre-refactor inline stubs. Default. Zero config, zero deps. - pkg/miner/backend/openai — OpenAI-compatible HTTP adapter built on net/http. Covers llama.cpp, vllm, ollama, LocalAI, and api.openai.com via OPENAI_API_BASE. No new go.mod dependencies. Config gains Backend / OpenAIBase / OpenAIAPIKey / OpenAIModel / OpenAIEmbeddingModel fields. Unknown backend values fall back to noop so operator typos don't crash-loop the miner. Existing miner_test.go passes unchanged; DefaultConfig() behaviour is preserved. Also wire a GPUStatsProvider hook on Miner so GetStats can surface best-effort GPU telemetry (GPUUtilization, MemoryUsed) without pulling NVML/MLX bindings into the main binary. Default is nil = no-op, matching current behaviour; a follow-up PR will wire a real provider. Closes luxfi#1. Contributed by kcolbchain (https://kcolbchain.com) · https://abhishekkrishna.com
hanzo-dev
pushed a commit
that referenced
this pull request
May 13, 2026
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.
Closes #1.
Summary
Replaces three
// TODO: Integrate with actual ...stubs inpkg/miner/miner.gowith a small pluggable backend interface. The miner'srunInference,runChat, andrunEmbeddingnow dispatch throughbackend.InferenceBackendinstead of inlining placeholder output.Two reference backends ship in-tree:
pkg/miner/backend/noopnooppkg/miner/backend/openaiopenainet/http. Covers llama.cpp, vllm, ollama, LocalAI, and api.openai.com viaOPENAI_API_BASE.No new
go.moddependencies.Why one OpenAI-compatible adapter instead of direct bindings
llama.cpp bindings pull in ~20 MB of C source. vllm is Python-only. MLX bindings require CGo. But all of them — plus ollama and LocalAI — expose an OpenAI-compatible
/v1/chat/completions+/v1/embeddingssurface. One small Go adapter covers every engine an operator would realistically run, and the interface still lets someone add a direct-binding backend in a follow-up PR if latency-sensitive deployments need it.Config changes
miner.Configgains five optional fields:Backend string—"noop"(default) or"openai"OpenAIBase string— e.g.http://localhost:11434/v1(ollama),http://localhost:8080/v1(llama.cpp)OpenAIAPIKey string— bearer token, empty is fine for local enginesOpenAIModel string— default model nameOpenAIEmbeddingModel string— optional override for embed tasksUnknown
Backendvalues fall back tonoopso operator typos don't crash-loop the miner.Sibling change: GPUStatsProvider hook
Adds a
GPUStatsProviderhook onMiner:GetStatsmerges its output into the returnedStats. Default isnil= no-op, matching current behaviour. A follow-up PR will wire a real NVML/MLX provider; this leaves the seam in place without pulling heavy bindings into the main binary.Compatibility
miner_test.gopasses unchanged.DefaultConfig()keeps producing a noop miner — zero behaviour change for current callers.go.modchurn.Files
New:
pkg/miner/backend/backend.go— interface + request/response typespkg/miner/backend/backend_test.go— interface contract testspkg/miner/backend/noop/noop.go+noop_test.go— deterministic mockpkg/miner/backend/openai/openai.go+openai_test.go— HTTP adapter (httptest-mocked tests)pkg/miner/backend/README.md— operator-facing doc with engine pointer commandsModified:
pkg/miner/miner.go— backend wiring, Config extensions, GPU hookpkg/miner/miner_test.go— added 7 tests for new wiring; existing 10 unchangedTest output
Full-repo
go build ./...,go vet ./..., andgo test ./...all green.Contributed by kcolbchain (https://kcolbchain.com) · https://abhishekkrishna.com