MCPcopy
hub / github.com/mudler/LocalAI / ResolvePIIPolicy

Method ResolvePIIPolicy

core/application/application.go:343–361  ·  view source on GitHub ↗

ResolvePIIPolicy resolves the effective request-side PII policy for a consuming model, layering the instance-wide default detector (PIIDefaultDetectors, set via POST /api/settings) on top of the per-model config. It is the single decision point shared by the chat middleware (via WithPolicyResolver)

(cfg *config.ModelConfig)

Source from the content-addressed store, hash-verified

341// appConfig is read live, so changes via the settings API take effect on the
342// next request without a restart.
343func (a *Application) ResolvePIIPolicy(cfg *config.ModelConfig) (enabled bool, detectors []string) {
344 if cfg == nil {
345 return false, nil
346 }
347 appCfg := a.ApplicationConfig()
348
349 // PIIIsEnabled already encodes "explicit pii.enabled wins, else backend
350 // default (cloud-proxy)" — the single source of that rule.
351 enabled = cfg.PIIIsEnabled()
352 if !enabled {
353 return false, nil
354 }
355
356 detectors = cfg.PIIDetectors()
357 if len(detectors) == 0 {
358 detectors = append([]string(nil), appCfg.PIIDefaultDetectors...)
359 }
360 return true, detectors // enabled is necessarily true past the !enabled guard
361}
362
363// PIIPolicyResolver adapts ResolvePIIPolicy to pii.PolicyResolver for
364// pii.WithPolicyResolver. The middleware carries the resolved model config as

Callers 4

PIIPolicyResolverMethod · 0.95
buildPIIStatusFunction · 0.80
startMITMLockedFunction · 0.80
pii_policy_test.goFile · 0.80

Calls 3

ApplicationConfigMethod · 0.95
PIIIsEnabledMethod · 0.65
PIIDetectorsMethod · 0.65

Tested by

no test coverage detected