|
5 | 5 | "log" |
6 | 6 | "strings" |
7 | 7 | "sync" |
| 8 | + "time" |
8 | 9 |
|
9 | 10 | candle_binding "github.com/vllm-project/semantic-router/candle-binding" |
10 | 11 | "github.com/vllm-project/semantic-router/semantic-router/pkg/config" |
@@ -115,13 +116,15 @@ func (c *Classifier) CheckForJailbreak(text string) (bool, string, float32, erro |
115 | 116 | var result candle_binding.ClassResult |
116 | 117 | var err error |
117 | 118 |
|
| 119 | + start := time.Now() |
118 | 120 | if c.Config.PromptGuard.UseModernBERT { |
119 | 121 | // Use ModernBERT jailbreak classifier |
120 | 122 | result, err = candle_binding.ClassifyModernBertJailbreakText(text) |
121 | 123 | } else { |
122 | 124 | // Use linear jailbreak classifier |
123 | 125 | result, err = candle_binding.ClassifyJailbreakText(text) |
124 | 126 | } |
| 127 | + metrics.RecordClassifierLatency("jailbreak", time.Since(start).Seconds()) |
125 | 128 |
|
126 | 129 | if err != nil { |
127 | 130 | return false, "", 0.0, fmt.Errorf("jailbreak classification failed: %w", err) |
@@ -196,13 +199,15 @@ func (c *Classifier) ClassifyCategory(text string) (string, float64, error) { |
196 | 199 | var result candle_binding.ClassResult |
197 | 200 | var err error |
198 | 201 |
|
| 202 | + start := time.Now() |
199 | 203 | if c.Config.Classifier.CategoryModel.UseModernBERT { |
200 | 204 | // Use ModernBERT classifier |
201 | 205 | result, err = candle_binding.ClassifyModernBertText(text) |
202 | 206 | } else { |
203 | 207 | // Use linear classifier |
204 | 208 | result, err = candle_binding.ClassifyText(text) |
205 | 209 | } |
| 210 | + metrics.RecordClassifierLatency("category", time.Since(start).Seconds()) |
206 | 211 |
|
207 | 212 | if err != nil { |
208 | 213 | return "", 0.0, fmt.Errorf("classification error: %w", err) |
@@ -243,7 +248,9 @@ func (c *Classifier) ClassifyPII(text string) ([]string, error) { |
243 | 248 |
|
244 | 249 | // Use ModernBERT PII token classifier for entity detection |
245 | 250 | configPath := fmt.Sprintf("%s/config.json", c.Config.Classifier.PIIModel.ModelID) |
| 251 | + start := time.Now() |
246 | 252 | tokenResult, err := candle_binding.ClassifyModernBertPIITokens(text, configPath) |
| 253 | + metrics.RecordClassifierLatency("pii", time.Since(start).Seconds()) |
247 | 254 | if err != nil { |
248 | 255 | return nil, fmt.Errorf("PII token classification error: %w", err) |
249 | 256 | } |
@@ -323,7 +330,9 @@ func (c *Classifier) AnalyzeContentForPII(contentList []string) (bool, []PIIAnal |
323 | 330 |
|
324 | 331 | // Use ModernBERT PII token classifier for detailed analysis |
325 | 332 | configPath := fmt.Sprintf("%s/config.json", c.Config.Classifier.PIIModel.ModelID) |
| 333 | + start := time.Now() |
326 | 334 | tokenResult, err := candle_binding.ClassifyModernBertPIITokens(content, configPath) |
| 335 | + metrics.RecordClassifierLatency("pii", time.Since(start).Seconds()) |
327 | 336 | if err != nil { |
328 | 337 | log.Printf("Error analyzing content %d: %v", i, err) |
329 | 338 | continue |
|
0 commit comments