mirror of
https://github.com/mudler/LocalAI.git
synced 2026-06-19 14:19:16 -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>
191 lines
6.9 KiB
Go
191 lines
6.9 KiB
Go
package auth
|
|
|
|
// RouteFeature maps a route pattern + HTTP method to a required feature.
|
|
type RouteFeature struct {
|
|
Method string // "POST", "GET", "*" (any)
|
|
Pattern string // Echo route pattern, e.g. "/v1/chat/completions"
|
|
Feature string // Feature constant, e.g. FeatureChat
|
|
}
|
|
|
|
// RouteFeatureRegistry is the single source of truth for endpoint -> feature mappings.
|
|
// To gate a new endpoint, add an entry here -- no other file changes needed.
|
|
var RouteFeatureRegistry = []RouteFeature{
|
|
// Chat / Completions
|
|
{"POST", "/v1/chat/completions", FeatureChat},
|
|
{"POST", "/chat/completions", FeatureChat},
|
|
{"POST", "/v1/completions", FeatureChat},
|
|
{"POST", "/completions", FeatureChat},
|
|
{"POST", "/v1/engines/:model/completions", FeatureChat},
|
|
{"POST", "/v1/edits", FeatureChat},
|
|
{"POST", "/edits", FeatureChat},
|
|
|
|
// Anthropic
|
|
{"POST", "/v1/messages", FeatureChat},
|
|
{"POST", "/messages", FeatureChat},
|
|
|
|
// Open Responses
|
|
{"POST", "/v1/responses", FeatureChat},
|
|
{"POST", "/responses", FeatureChat},
|
|
{"GET", "/v1/responses", FeatureChat},
|
|
{"GET", "/responses", FeatureChat},
|
|
|
|
// Embeddings
|
|
{"POST", "/v1/embeddings", FeatureEmbeddings},
|
|
{"POST", "/embeddings", FeatureEmbeddings},
|
|
{"POST", "/v1/engines/:model/embeddings", FeatureEmbeddings},
|
|
|
|
// Images
|
|
{"POST", "/v1/images/generations", FeatureImages},
|
|
{"POST", "/images/generations", FeatureImages},
|
|
{"POST", "/v1/images/inpainting", FeatureImages},
|
|
{"POST", "/images/inpainting", FeatureImages},
|
|
|
|
// Audio transcription
|
|
{"POST", "/v1/audio/transcriptions", FeatureAudioTranscription},
|
|
{"POST", "/audio/transcriptions", FeatureAudioTranscription},
|
|
|
|
// Audio diarization (speaker turns)
|
|
{"POST", "/v1/audio/diarization", FeatureAudioDiarization},
|
|
{"POST", "/audio/diarization", FeatureAudioDiarization},
|
|
|
|
// Audio speech / TTS
|
|
{"POST", "/v1/audio/speech", FeatureAudioSpeech},
|
|
{"POST", "/audio/speech", FeatureAudioSpeech},
|
|
{"POST", "/tts", FeatureAudioSpeech},
|
|
{"POST", "/v1/text-to-speech/:voice-id", FeatureAudioSpeech},
|
|
|
|
// VAD
|
|
{"POST", "/vad", FeatureVAD},
|
|
{"POST", "/v1/vad", FeatureVAD},
|
|
|
|
// Detection
|
|
{"POST", "/v1/detection", FeatureDetection},
|
|
|
|
// Face recognition
|
|
{"POST", "/v1/face/verify", FeatureFaceRecognition},
|
|
{"POST", "/v1/face/analyze", FeatureFaceRecognition},
|
|
{"POST", "/v1/face/embed", FeatureFaceRecognition},
|
|
{"POST", "/v1/face/register", FeatureFaceRecognition},
|
|
{"POST", "/v1/face/identify", FeatureFaceRecognition},
|
|
{"POST", "/v1/face/forget", FeatureFaceRecognition},
|
|
|
|
// Voice (speaker) recognition
|
|
{"POST", "/v1/voice/verify", FeatureVoiceRecognition},
|
|
{"POST", "/v1/voice/analyze", FeatureVoiceRecognition},
|
|
{"POST", "/v1/voice/embed", FeatureVoiceRecognition},
|
|
{"POST", "/v1/voice/register", FeatureVoiceRecognition},
|
|
{"POST", "/v1/voice/identify", FeatureVoiceRecognition},
|
|
{"POST", "/v1/voice/forget", FeatureVoiceRecognition},
|
|
|
|
// Audio transform (echo cancellation, noise suppression, voice conversion, etc.)
|
|
{"POST", "/audio/transformations", FeatureAudioTransform},
|
|
{"POST", "/audio/transform", FeatureAudioTransform},
|
|
{"GET", "/audio/transformations/stream", FeatureAudioTransform},
|
|
|
|
// Video
|
|
{"POST", "/video", FeatureVideo},
|
|
|
|
// Sound generation
|
|
{"POST", "/v1/sound-generation", FeatureSound},
|
|
|
|
// Realtime
|
|
{"GET", "/v1/realtime", FeatureRealtime},
|
|
{"POST", "/v1/realtime/sessions", FeatureRealtime},
|
|
{"POST", "/v1/realtime/transcription_session", FeatureRealtime},
|
|
{"POST", "/v1/realtime/calls", FeatureRealtime},
|
|
|
|
// MCP
|
|
{"POST", "/v1/mcp/chat/completions", FeatureMCP},
|
|
{"POST", "/mcp/v1/chat/completions", FeatureMCP},
|
|
{"POST", "/mcp/chat/completions", FeatureMCP},
|
|
|
|
// Tokenize
|
|
{"POST", "/v1/tokenize", FeatureTokenize},
|
|
|
|
// Rerank
|
|
{"POST", "/v1/rerank", FeatureRerank},
|
|
|
|
// Stores
|
|
{"POST", "/stores/set", FeatureStores},
|
|
{"POST", "/stores/delete", FeatureStores},
|
|
{"POST", "/stores/get", FeatureStores},
|
|
{"POST", "/stores/find", FeatureStores},
|
|
|
|
// Fine-tuning
|
|
{"POST", "/api/fine-tuning/jobs", FeatureFineTuning},
|
|
{"GET", "/api/fine-tuning/jobs", FeatureFineTuning},
|
|
{"GET", "/api/fine-tuning/jobs/:id", FeatureFineTuning},
|
|
{"POST", "/api/fine-tuning/jobs/:id/stop", FeatureFineTuning},
|
|
{"DELETE", "/api/fine-tuning/jobs/:id", FeatureFineTuning},
|
|
{"GET", "/api/fine-tuning/jobs/:id/progress", FeatureFineTuning},
|
|
{"GET", "/api/fine-tuning/jobs/:id/checkpoints", FeatureFineTuning},
|
|
{"POST", "/api/fine-tuning/jobs/:id/export", FeatureFineTuning},
|
|
{"GET", "/api/fine-tuning/jobs/:id/download", FeatureFineTuning},
|
|
{"POST", "/api/fine-tuning/datasets", FeatureFineTuning},
|
|
|
|
// PII analyze/redact service (the events log stays admin-gated in-handler)
|
|
{"POST", "/api/pii/analyze", FeaturePIIFilter},
|
|
{"POST", "/api/pii/redact", FeaturePIIFilter},
|
|
|
|
// Quantization
|
|
{"POST", "/api/quantization/jobs", FeatureQuantization},
|
|
{"GET", "/api/quantization/jobs", FeatureQuantization},
|
|
{"GET", "/api/quantization/jobs/:id", FeatureQuantization},
|
|
{"POST", "/api/quantization/jobs/:id/stop", FeatureQuantization},
|
|
{"DELETE", "/api/quantization/jobs/:id", FeatureQuantization},
|
|
{"GET", "/api/quantization/jobs/:id/progress", FeatureQuantization},
|
|
{"POST", "/api/quantization/jobs/:id/import", FeatureQuantization},
|
|
{"GET", "/api/quantization/jobs/:id/download", FeatureQuantization},
|
|
}
|
|
|
|
// FeatureMeta describes a feature for the admin API/UI.
|
|
type FeatureMeta struct {
|
|
Key string `json:"key"`
|
|
Label string `json:"label"`
|
|
DefaultValue bool `json:"default"`
|
|
}
|
|
|
|
// AgentFeatureMetas returns metadata for agent features.
|
|
func AgentFeatureMetas() []FeatureMeta {
|
|
return []FeatureMeta{
|
|
{FeatureAgents, "Agents", false},
|
|
{FeatureSkills, "Skills", false},
|
|
{FeatureCollections, "Collections", false},
|
|
{FeatureMCPJobs, "MCP CI Jobs", false},
|
|
{FeatureLocalAIAssistant, "LocalAI Assistant", false},
|
|
}
|
|
}
|
|
|
|
// GeneralFeatureMetas returns metadata for general features.
|
|
func GeneralFeatureMetas() []FeatureMeta {
|
|
return []FeatureMeta{
|
|
{FeatureFineTuning, "Fine-Tuning", false},
|
|
{FeatureQuantization, "Quantization", false},
|
|
}
|
|
}
|
|
|
|
// APIFeatureMetas returns metadata for API endpoint features.
|
|
func APIFeatureMetas() []FeatureMeta {
|
|
return []FeatureMeta{
|
|
{FeatureChat, "Chat Completions", true},
|
|
{FeatureImages, "Image Generation", true},
|
|
{FeatureAudioSpeech, "Audio Speech / TTS", true},
|
|
{FeatureAudioTranscription, "Audio Transcription", true},
|
|
{FeatureAudioDiarization, "Audio Diarization", true},
|
|
{FeatureVAD, "Voice Activity Detection", true},
|
|
{FeatureDetection, "Detection", true},
|
|
{FeatureVideo, "Video Generation", true},
|
|
{FeatureEmbeddings, "Embeddings", true},
|
|
{FeatureSound, "Sound Generation", true},
|
|
{FeatureRealtime, "Realtime", true},
|
|
{FeatureRerank, "Rerank", true},
|
|
{FeatureTokenize, "Tokenize", true},
|
|
{FeatureMCP, "MCP", true},
|
|
{FeatureStores, "Stores", true},
|
|
{FeatureFaceRecognition, "Face Recognition", true},
|
|
{FeatureVoiceRecognition, "Voice Recognition", true},
|
|
{FeatureAudioTransform, "Audio Transform", true},
|
|
{FeaturePIIFilter, "PII Analyze / Redact", true},
|
|
}
|
|
}
|