Skip to content

Commit

Permalink
🚧 Filtering based on threshold
Browse files Browse the repository at this point in the history
Signed-off-by: Evaline Ju <69598118+evaline-ju@users.noreply.github.com>
  • Loading branch information
evaline-ju committed May 28, 2024
1 parent 513b25d commit 31bbdbd
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/orchestrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ async fn handle_detection_task(
// NOTE: The detector request is expected to change and not actually
// take parameters. However, any parameters will be ignored for now
// ref. https://github.com/foundation-model-stack/fms-guardrails-orchestrator/issues/37
let request = DetectorRequest::new(chunk.text.clone(), detector_params);
let request = DetectorRequest::new(chunk.text.clone(), detector_params.clone());
debug!(
%detector_id,
?request,
Expand All @@ -357,11 +357,20 @@ async fn handle_detection_task(
let results = response
.detections
.into_iter()
.map(|detection| {
.filter_map(|detection| {
let mut result: TokenClassificationResult = detection.into();
result.start += chunk.offset as u32;
result.end += chunk.offset as u32;
result
if let Some(threshold_value) = detector_params.get("threshold") {
if let Some(threshold) = threshold_value.as_f64() {
if result.score >= threshold {
return Some(result);
}
}
} else {
return Some(result);
}
None
})
.collect::<Vec<_>>();
Ok::<Vec<TokenClassificationResult>, Error>(results)
Expand Down

0 comments on commit 31bbdbd

Please sign in to comment.