@@ -463,6 +463,9 @@ def test_preprocess_chat_request_with_extra_chat_template_kwargs(
463463 }
464464
465465
466+ #### Helper function request->chat_completion_request tests
467+
468+
466469def test_request_to_chat_completion_request_prompt_analysis (granite_guardian_detection ):
467470 granite_guardian_detection_instance = asyncio .run (granite_guardian_detection )
468471 context_request = ContextAnalysisRequest (
@@ -499,7 +502,7 @@ def test_request_to_chat_completion_request_prompt_analysis(granite_guardian_det
499502 )
500503
501504
502- def test_request_to_chat_completion_request_reponse_analysis (
505+ def test_request_to_chat_completion_request_response_analysis (
503506 granite_guardian_detection ,
504507):
505508 granite_guardian_detection_instance = asyncio .run (granite_guardian_detection )
@@ -569,6 +572,29 @@ def test_request_to_chat_completion_request_empty_guardian_config(
569572 assert "No risk_name for context analysis" in chat_request .message
570573
571574
575+ def test_request_to_chat_completion_request_missing_risk_name (
576+ granite_guardian_detection ,
577+ ):
578+ granite_guardian_detection_instance = asyncio .run (granite_guardian_detection )
579+ context_request = ContextAnalysisRequest (
580+ content = CONTENT ,
581+ context_type = "docs" ,
582+ context = [CONTEXT_DOC ],
583+ detector_params = {
584+ "n" : 3 ,
585+ "chat_template_kwargs" : {"guardian_config" : {"risk_definition" : "hi" }},
586+ },
587+ )
588+ chat_request = (
589+ granite_guardian_detection_instance ._request_to_chat_completion_request (
590+ context_request , MODEL_NAME , fn_type = DetectorType .TEXT_CONTEXT_DOC
591+ )
592+ )
593+ assert type (chat_request ) == ErrorResponse
594+ assert chat_request .code == HTTPStatus .BAD_REQUEST
595+ assert "No risk_name for context analysis" in chat_request .message
596+
597+
572598def test_request_to_chat_completion_request_unsupported_risk_name (
573599 granite_guardian_detection ,
574600):
@@ -594,6 +620,9 @@ def test_request_to_chat_completion_request_unsupported_risk_name(
594620 )
595621
596622
623+ #### Helper function preprocess content tests
624+
625+
597626def test_preprocess_content_request_with_detector_params (granite_guardian_detection ):
598627 granite_guardian_detection_instance = asyncio .run (granite_guardian_detection )
599628 # Make sure with addition of allowed params like risk_name and risk_definition,
0 commit comments