Skip to content

Commit 0702c69

Browse files
committed
Add test for standalone detection
modified: tests/model_explainability/guardrails/test_guardrails.py modified: tests/model_explainability/guardrails/test_guardrails.py
1 parent 66a1327 commit 0702c69

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tests/model_explainability/guardrails/test_guardrails.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
CHAT_COMPLETIONS_DETECTION_ENDPOINT: str = "api/v2/chat/completions-detection"
3434
PII_ENDPOINT: str = "/pii"
35+
STANDALONE_DETECTION_ENDPOINT: str = "api/v2/text/detection/content"
3536

3637
PROMPT_INJECTION_DETECTORS: Dict[str, Dict[str, Any]] = {
3738
"input": {"prompt_injection": {}},
@@ -254,6 +255,15 @@ def test_guardrails_builtin_detectors_negative_detection(
254255
"chunker_id": "whole_doc_chunker",
255256
"default_threshold": 0.5,
256257
},
258+
"hap": {
259+
"type": "text_contents",
260+
"service": {
261+
"hostname": "hap-detector-predictor",
262+
"port": 8000,
263+
},
264+
"chunker_id": "whole_doc_chunker",
265+
"default_threshold": 0.5,
266+
},
257267
},
258268
})
259269
},
@@ -273,6 +283,8 @@ class TestGuardrailsOrchestratorWithHuggingFaceDetectors:
273283
- Deploy a prompt injection detector using the HuggingFace SR.
274284
- Check that the detector works when we have an unsuitable input.
275285
- Check that the detector works when we have a harmless input (no detection).
286+
- Check that the standalone detection endpoint forwards the
287+
query directly to the orchestrator without performing any detection.
276288
"""
277289

278290
def test_guardrails_hf_detector_unsuitable_input(
@@ -324,6 +336,35 @@ def test_guardrails_hf_detector_negative_detection(
324336

325337
verify_negative_detection_response(response=response)
326338

339+
def test_guardrails_standalone_detector_endpoint(
340+
self, current_client_token, openshift_ca_bundle_file, qwen_isvc, guardrails_orchestrator_route, hap_detector_route
341+
):
342+
url = f"https://{guardrails_orchestrator_route.host}/{STANDALONE_DETECTION_ENDPOINT}"
343+
headers = get_auth_headers(token=current_client_token)
344+
payload = {
345+
"detectors": {
346+
"hap": {}
347+
},
348+
349+
"content": "You dotard, I really hate this stuff"
350+
351+
}
352+
353+
response = requests.post(
354+
url=url,
355+
headers=headers,
356+
json=payload,
357+
verify=openshift_ca_bundle_file,
358+
)
359+
360+
assert response.status_code == http.HTTPStatus.OK, (
361+
f"Unexpected status code: {response.status_code}, body: {response.text}"
362+
)
363+
data = response.json()
364+
365+
assert "detections" in data
366+
367+
327368

328369
@pytest.mark.parametrize(
329370
"model_namespace, minio_pod, minio_data_connection, orchestrator_config, guardrails_orchestrator",

0 commit comments

Comments
 (0)