mirror of
https://github.com/mudler/LocalAI.git
synced 2026-06-18 21:58:58 -04:00
Squashed feat/pii-ner-tier-engine rebased onto master (was 45 commits; see backup/pii-ner-tier-engine-prerebase). Net change: - privacy-filter.cpp: standalone GGML engine for the openai-privacy-filter PII/NER token classifier, wired as a LocalAI gRPC backend (CPU/CUDA/Vulkan). TokenClassify moves off the patched llama.cpp path onto this backend. - PII filter reworked to be NER-centric (encoder/NER detection tier scanning whole conversations as one document), with a recreated bounded restricted- regex secret-matching pattern detector tier alongside it (per-model pii_detection.builtins / .patterns + core/services/routing/piipattern). - Detection labelled by source (ner vs pattern); backend trace / confidence / debug observability; analyze/redact exposed as a synchronous API. - Instance-wide default detector policy + per-usecase default-on; request filtering extended to completions, embeddings, edits & Ollama. - React UI: NER-centric PII editor, detector-models table, pattern/builtins editor, middleware default-policy UI. - Gallery: privacy-filter-multilingual token-classify model + NER install filter; token_classify known_usecase; batch sized to context for NER models. privacy-filter backend registered in the backend gallery (cpu/vulkan/cuda-13 meta + image entries with a capabilities map) matching its CI matrix jobs, and an /import-model auto-detect importer (PrivacyFilterImporter, narrow privacy-filter GGUF detection) replacing the prior pref-only registration. Reconciled against master's independent evolution: - Dropped master's PIIPatternOverrides feature (global-pattern runtime overrides + /api/pii/patterns API + runtime_settings.json persistence). The per-model NER + pattern-detector design supersedes it; it was built on the global redactor pattern set this branch replaced. - Reverted the llama.cpp Score carry-patch (0006-server-task-type-score): removed the patch and restored master's grpc-server.cpp Score RPC (direct llama_decode, slot-loop bypass) and LLAMA_VERSION pin, plus master's model_config validation forbidding score + chat/completion/embeddings on llama-cpp. token_classify is unaffected (it runs on the privacy-filter backend, not llama-cpp). Assisted-by: Claude:claude-opus-4-8 [Claude Code] Signed-off-by: Richard Palethorpe <io@richiejp.com>
52 lines
1.9 KiB
Go
52 lines
1.9 KiB
Go
package application
|
|
|
|
import (
|
|
"github.com/mudler/LocalAI/core/config"
|
|
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("ResolvePIIPolicy", func() {
|
|
chat := config.FLAG_CHAT
|
|
bp := func(b bool) *bool { return &b }
|
|
mk := func(c *config.ApplicationConfig) *Application {
|
|
return &Application{applicationConfig: c}
|
|
}
|
|
|
|
It("lets an explicit pii.enabled=false win over the global default detector", func() {
|
|
app := mk(&config.ApplicationConfig{PIIDefaultDetectors: []string{"pf"}})
|
|
cfg := &config.ModelConfig{Backend: "cloud-proxy", KnownUsecases: &chat}
|
|
cfg.PII.Enabled = bp(false)
|
|
enabled, dets := app.ResolvePIIPolicy(cfg)
|
|
Expect(enabled).To(BeFalse())
|
|
Expect(dets).To(BeNil())
|
|
})
|
|
|
|
It("enables a cloud-proxy model with the global default detector (closes the no-op gap)", func() {
|
|
// cloud-proxy defaults PIIIsEnabled()==true but lists no detectors, so
|
|
// without a global default it scans with nothing.
|
|
app := mk(&config.ApplicationConfig{PIIDefaultDetectors: []string{"pf"}})
|
|
cfg := &config.ModelConfig{Backend: "cloud-proxy"}
|
|
enabled, dets := app.ResolvePIIPolicy(cfg)
|
|
Expect(enabled).To(BeTrue())
|
|
Expect(dets).To(Equal([]string{"pf"}))
|
|
})
|
|
|
|
It("leaves a non-cloud model off by default (no instance usecase default-on)", func() {
|
|
app := mk(&config.ApplicationConfig{PIIDefaultDetectors: []string{"pf"}})
|
|
cfg := &config.ModelConfig{Backend: "llama-cpp", KnownUsecases: &chat}
|
|
enabled, _ := app.ResolvePIIPolicy(cfg)
|
|
Expect(enabled).To(BeFalse())
|
|
})
|
|
|
|
It("prefers the model's own detectors over the global default", func() {
|
|
app := mk(&config.ApplicationConfig{PIIDefaultDetectors: []string{"global-pf"}})
|
|
cfg := &config.ModelConfig{Backend: "cloud-proxy"}
|
|
cfg.PII.Detectors = []string{"own-pf"}
|
|
enabled, dets := app.ResolvePIIPolicy(cfg)
|
|
Expect(enabled).To(BeTrue())
|
|
Expect(dets).To(Equal([]string{"own-pf"}))
|
|
})
|
|
})
|