mirror of
https://github.com/mudler/LocalAI.git
synced 2026-06-14 19:58:44 -04:00
Add a routing middleware stack and a cloud-proxy backend. * cloud-proxy: a Go gRPC backend that forwards OpenAI- and Anthropic-shaped chat requests to upstream providers, with an optional translate mode (OpenAI request -> Anthropic /v1/messages -> OpenAI response) and full tool-calling support. * routing: admission control, content-aware model routing (embedding cache + classifier + rerank + Arch-Router score), PII detection/redaction (regex + NER) with streaming filter and OpenAI/Anthropic adapters, and a per-user/per-key billing recorder backed by GORM or in-memory storage. * middleware: UsageMiddleware records usage via the billing recorder, plus admission, route-model, usage-stamp and trace middlewares. * observability: BackendTrace ring buffer stores full request bodies (capped), MITM proxy emits structured trace events, and router classifier decisions surface at /api/router/decide. * gallery: Arch-Router-1.5B (Q4_K_M and Q8_0). * UI: cloud-proxy model-editor fields, classifier system-prompt and score-normalization config, and a Traces page rendering request bodies. Assisted-by: claude-code:claude-opus-4-7 [Read] [Edit] [Bash] Signed-off-by: Richard Palethorpe <io@richiejp.com>
64 lines
2.1 KiB
Go
64 lines
2.1 KiB
Go
package httpapi
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
)
|
|
|
|
// Route paths for the LocalAI admin REST surface that this client targets.
|
|
// Static paths are constants; dynamic paths are builders that handle
|
|
// url.PathEscape on segment values. Keep these aligned with the server-side
|
|
// registrations in core/http/routes/localai.go — the Tool↔REST drift detector
|
|
// in coverage_test.go documents the mapping.
|
|
const (
|
|
routeWelcome = "/"
|
|
routeModelsApply = "/models/apply"
|
|
routeModelsAvail = "/models/available"
|
|
routeModelsGall = "/models/galleries"
|
|
routeModelsImport = "/models/import-uri"
|
|
routeModelsReload = "/models/reload"
|
|
routeBackends = "/backends"
|
|
routeBackendsKnown = "/backends/known"
|
|
routeBackendsApply = "/backends/apply"
|
|
routeNodes = "/api/nodes"
|
|
routeVRAMEstimate = "/api/models/vram-estimate"
|
|
routeBranding = "/api/branding"
|
|
routeSettings = "/api/settings"
|
|
routeUsage = "/api/usage"
|
|
routeUsageAll = "/api/usage/all"
|
|
routePIIPatterns = "/api/pii/patterns"
|
|
routePIIPatternsPersist = "/api/pii/patterns/persist"
|
|
routePIIEvents = "/api/pii/events"
|
|
routePIITest = "/api/pii/test"
|
|
routeMiddleware = "/api/middleware/status"
|
|
routeRouterDecisions = "/api/router/decisions"
|
|
)
|
|
|
|
func routePIIPatternByID(id string) string {
|
|
return "/api/pii/patterns/" + url.PathEscape(id)
|
|
}
|
|
|
|
func routeJobStatus(jobID string) string {
|
|
return "/models/jobs/" + url.PathEscape(jobID)
|
|
}
|
|
|
|
func routeModelDelete(name string) string {
|
|
return "/models/delete/" + url.PathEscape(name)
|
|
}
|
|
|
|
func routeModelConfigJSON(name string) string {
|
|
return "/api/models/config-json/" + url.PathEscape(name)
|
|
}
|
|
|
|
func routeBackendUpgrade(name string) string {
|
|
return "/backends/upgrade/" + url.PathEscape(name)
|
|
}
|
|
|
|
func routeToggleModelState(name, action string) string {
|
|
return fmt.Sprintf("/models/toggle-state/%s/%s", url.PathEscape(name), url.PathEscape(action))
|
|
}
|
|
|
|
func routeToggleModelPinned(name, action string) string {
|
|
return fmt.Sprintf("/models/toggle-pinned/%s/%s", url.PathEscape(name), url.PathEscape(action))
|
|
}
|