pub struct ResponseClassifier;Expand description
Stateless classifier for LLM responses.
Implementations§
Source§impl ResponseClassifier
impl ResponseClassifier
Sourcepub fn classify(&self, response: &str, prompt: &str) -> ClassificationResult
pub fn classify(&self, response: &str, prompt: &str) -> ClassificationResult
Classify a single response given the original prompt.
Sourcepub fn detect_category(text: &str) -> (ResponseCategory, f64)
pub fn detect_category(text: &str) -> (ResponseCategory, f64)
Detect the response category using keyword/pattern matching.
Returns (category, confidence).
Sourcepub fn detect_refusal(text: &str) -> bool
pub fn detect_refusal(text: &str) -> bool
Detect if the response is a refusal.
Sourcepub fn detect_citations(text: &str) -> bool
pub fn detect_citations(text: &str) -> bool
Detect whether the response contains citations or references.
Sourcepub fn score_coherence(text: &str) -> f64
pub fn score_coherence(text: &str) -> f64
Score sentence-level coherence (0-1).
Heuristic: rewards smooth sentence beginnings, penalises abrupt stops.
Sourcepub fn score_completeness(response: &str, prompt: &str) -> f64
pub fn score_completeness(response: &str, prompt: &str) -> f64
Score how completely the response addresses the prompt (0-1).
Sourcepub fn score_conciseness(text: &str) -> f64
pub fn score_conciseness(text: &str) -> f64
Score conciseness (0-1). Higher = more concise.
Sourcepub fn score_formatting(text: &str) -> f64
pub fn score_formatting(text: &str) -> f64
Score formatting quality (0-1).
Sourcepub fn flesch_kincaid_grade(text: &str) -> f64
pub fn flesch_kincaid_grade(text: &str) -> f64
Compute the Flesch-Kincaid Grade Level.
FK Grade = 0.39 * (words/sentences) + 11.8 * (syllables/words) - 15.59
Sourcepub fn batch_classify(
&self,
responses: &[(String, String)],
) -> Vec<ClassificationResult>
pub fn batch_classify( &self, responses: &[(String, String)], ) -> Vec<ClassificationResult>
Classify a batch of (response, prompt) pairs.
Trait Implementations§
Source§impl Debug for ResponseClassifier
impl Debug for ResponseClassifier
Source§impl Default for ResponseClassifier
impl Default for ResponseClassifier
Source§fn default() -> ResponseClassifier
fn default() -> ResponseClassifier
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for ResponseClassifier
impl RefUnwindSafe for ResponseClassifier
impl Send for ResponseClassifier
impl Sync for ResponseClassifier
impl Unpin for ResponseClassifier
impl UnsafeUnpin for ResponseClassifier
impl UnwindSafe for ResponseClassifier
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