Files
LocalAI/pkg/store/proto.go
Richard Palethorpe 6a80e23733 feat(middleware): Model routing, PII filtering, Cloud model proxies (#9802)
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>
2026-05-25 09:28:27 +02:00

47 lines
1.2 KiB
Go

package store
// pb⇄[][]float32/[][]byte translation helpers shared by the gRPC
// client (this file's package) and the local-store gRPC server in
// backend/go/local-store. Same shape on both sides of the wire so a
// schema bug only needs fixing once.
import (
"github.com/mudler/LocalAI/pkg/grpc/proto"
)
// WrapKeys wraps each plain []float32 in a *proto.StoresKey.
func WrapKeys(in [][]float32) []*proto.StoresKey {
out := make([]*proto.StoresKey, len(in))
for i, k := range in {
out[i] = &proto.StoresKey{Floats: k}
}
return out
}
// WrapValues wraps each []byte in a *proto.StoresValue.
func WrapValues(in [][]byte) []*proto.StoresValue {
out := make([]*proto.StoresValue, len(in))
for i, v := range in {
out[i] = &proto.StoresValue{Bytes: v}
}
return out
}
// UnwrapKeys extracts the inner Floats from a slice of *proto.StoresKey.
func UnwrapKeys(in []*proto.StoresKey) [][]float32 {
out := make([][]float32, len(in))
for i, k := range in {
out[i] = k.Floats
}
return out
}
// UnwrapValues extracts the inner Bytes from a slice of *proto.StoresValue.
func UnwrapValues(in []*proto.StoresValue) [][]byte {
out := make([][]byte, len(in))
for i, v := range in {
out[i] = v.Bytes
}
return out
}