pub struct ContentModerator {
pub config: SafetyConfig,
pub hate_phrases: Vec<String>,
pub violence_phrases: Vec<String>,
pub spam_indicators: Vec<String>,
}Expand description
Content moderation engine.
Fields§
§config: SafetyConfig§hate_phrases: Vec<String>§violence_phrases: Vec<String>§spam_indicators: Vec<String>Implementations§
Source§impl ContentModerator
impl ContentModerator
Sourcepub fn new(config: SafetyConfig) -> Self
pub fn new(config: SafetyConfig) -> Self
Create a new ContentModerator with pre-populated phrase lists.
Sourcepub fn detect_toxicity(&self, text: &str) -> Vec<SafetyScore>
pub fn detect_toxicity(&self, text: &str) -> Vec<SafetyScore>
Scan text for toxic content per category. Confidence = hit_count / word_count.
Sourcepub fn detect_pii(text: &str) -> Vec<PiiMatch>
pub fn detect_pii(text: &str) -> Vec<PiiMatch>
Detect PII in the given text using pattern matching.
Sourcepub fn redact_pii(text: &str, matches: &[PiiMatch]) -> String
pub fn redact_pii(text: &str, matches: &[PiiMatch]) -> String
Replace matched PII spans with “REDACTED”.
Sourcepub fn analyze(&self, text: &str) -> SafetyResult
pub fn analyze(&self, text: &str) -> SafetyResult
Run all detectors and produce a SafetyResult.
Sourcepub fn overall_risk(scores: &[SafetyScore]) -> f64
pub fn overall_risk(scores: &[SafetyScore]) -> f64
Compute overall risk as the maximum confidence across all triggered categories.
Auto Trait Implementations§
impl Freeze for ContentModerator
impl RefUnwindSafe for ContentModerator
impl Send for ContentModerator
impl Sync for ContentModerator
impl Unpin for ContentModerator
impl UnsafeUnpin for ContentModerator
impl UnwindSafe for ContentModerator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request