feat(llamaswap): add llama-swap provider + canonical imagegen interface
CI / Tidy (pull_request) Successful in 9m25s
CI / Build & Test (pull_request) Successful in 10m15s

Add provider/llamaswap, a tailored provider for llama-swap (the model-swapping
proxy over llama.cpp / stable-diffusion.cpp). Its chat path delegates to
provider/openai at {base}/v1 — no duplicated wire client (ADR-0007) — with
legacy max_tokens, a Bearer no-key placeholder for keyless local instances, and
a timeout-free client so cold model swaps rely on context deadlines. The
"tailored" surface is concrete management methods (ListModels / Running /
Unload) that don't belong on the canonical llm.Provider interface. The
llama-swap:// DSN scheme builds an http base URL (local-first); a no-URL
built-in errors clearly on use, mirroring foreman.

Add imagegen, a new canonical text-to-image interface separate from llm
(Request/Result/Model/Provider; Image = llm.ImagePart so generated images feed
straight back into chat). First backend is llama-swap via OpenAI
/v1/images/generations (b64_json, bytes-only). Re-exported from the root. v1 is
txt2img only.

Hermetic httptest coverage for chat delegation, management endpoints, image
decode, and scheme wiring. ADR-0015 + ADR-0016, README support matrix +
image-gen section, CLAUDE.md package map, and progress.md updated in the same
commit.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-27 15:01:54 -04:00
parent 1fd7109a42
commit 96c612e707
14 changed files with 994 additions and 7 deletions
+23
View File
@@ -6,6 +6,7 @@ import (
"gitea.stevedudenhoeffer.com/steve/majordomo/llm"
"gitea.stevedudenhoeffer.com/steve/majordomo/provider/anthropic"
"gitea.stevedudenhoeffer.com/steve/majordomo/provider/google"
"gitea.stevedudenhoeffer.com/steve/majordomo/provider/llamaswap"
"gitea.stevedudenhoeffer.com/steve/majordomo/provider/ollama"
"gitea.stevedudenhoeffer.com/steve/majordomo/provider/openai"
)
@@ -18,6 +19,7 @@ const (
ProviderOllama = "ollama"
ProviderOllamaCloud = "ollama-cloud"
ProviderForeman = "foreman"
ProviderLlamaSwap = "llama-swap"
)
// registerBuiltins installs the built-in providers and env-DSN scheme
@@ -66,6 +68,27 @@ func registerBuiltins(r *Registry, httpClient *http.Client) {
)...), nil
}
// llama-swap: OpenAI-compatible chat + image generation + management
// endpoints over a model-swapping proxy. Chat reuses the openai client
// (provider/llamaswap delegates); the DSN builds an http:// base URL
// because llama-swap is local-first (TLS-fronted instances can use the
// openai:// scheme for chat). The no-DSN built-in errors on use with a
// clear message, mirroring foreman.
llamaSwapOpts := func(extra ...llamaswap.Option) []llamaswap.Option {
if httpClient != nil {
extra = append(extra, llamaswap.WithHTTPClient(httpClient))
}
return extra
}
r.providers[ProviderLlamaSwap] = llamaswap.New(llamaSwapOpts(llamaswap.WithName(ProviderLlamaSwap))...)
r.schemes[ProviderLlamaSwap] = func(name string, dsn DSN) (llm.Provider, error) {
return llamaswap.New(llamaSwapOpts(
llamaswap.WithName(name),
llamaswap.WithBaseURL("http://"+dsn.Host),
llamaswap.WithToken(dsn.Token),
)...), nil
}
// Anthropic and Anthropic-compatible endpoints.
anthropicOpts := func(extra ...anthropic.Option) []anthropic.Option {
if httpClient != nil {