Skip to content

🥅🏷️ Use more defined struct for threshold #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions TODOs.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
# TODOs
- [ ] Design detector map config and implement loading this config file
- [ ] Add TLS support for orchestrator server
- [ ] Implement Health probes
- [ ] Add request models (objects for request and response)
- [ ] Add unit tests
- [ ] Add request validation for classification with text generation endpoint
- [ ] Add request validation for streaming classification with text generation endpoint
- [ ] Host API in swagger pages in the repo
- [ ] Tokenization REST API and client will need to be updated for bidirectional streaming if/when available for REST use
- [ ] There is currently NO WAY for us to know the prefix ID required by TGIS for inferencing on tuned prompts
- [ ] Add configurable request timeouts for all clients
- [ ] [OSS public] Copyright headers
- [ ] [OSS public] CI - github actions
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub struct DetectorConfig {
/// ID of chunker that this detector will use
pub chunker_id: String,
/// Default threshold with which to filter detector results by score
pub default_threshold: f32,
pub default_threshold: f64,
}

/// Overall orchestrator server configuration
Expand Down
11 changes: 6 additions & 5 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
use crate::pb;
use std::collections::HashMap;

// TODO: When detector API is updated, consider if fields
// like 'threshold' can be named options instead of the
// use a generic HashMap with Values here
// ref. https://github.com/foundation-model-stack/fms-guardrails-orchestrator/issues/37
pub type DetectorParams = HashMap<String, serde_json::Value>;
/// Parameters relevant to each detector
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct DetectorParams {
/// Threshold with which to filter detector results by score
pub threshold: Option<f64>,
}

/// User request to orchestrator
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
Expand Down
7 changes: 2 additions & 5 deletions src/orchestrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,12 @@ async fn handle_chunk_task(
async fn handle_detection_task(
ctx: Arc<Context>,
detector_id: String,
default_threshold: f32,
default_threshold: f64,
detector_params: DetectorParams,
chunks: Vec<Chunk>,
) -> Result<Vec<TokenClassificationResult>, Error> {
let detector_id = detector_id.clone();
let threshold = detector_params
.get("threshold")
.and_then(|v| v.as_f64())
.unwrap_or(default_threshold as f64);
let threshold = detector_params.threshold.unwrap_or(default_threshold);
let contents = chunks.iter().map(|chunk| chunk.text.clone()).collect();
let request = ContentAnalysisRequest::new(contents);
debug!(
Expand Down