21
21
_fluency ,
22
22
_xpia ,
23
23
_coherence ,
24
+ _code_vulnerability ,
25
+ _ungrounded_attributes ,
24
26
)
25
27
from azure .ai .evaluation ._evaluators ._eci ._eci import ECIEvaluator
26
28
from azure .ai .evaluation ._evaluate import _evaluate
32
34
AdversarialScenario ,
33
35
AdversarialScenarioJailbreak ,
34
36
IndirectAttackSimulator ,
35
- DirectAttackSimulator ,
37
+ DirectAttackSimulator ,
36
38
)
37
39
from azure .ai .evaluation .simulator ._adversarial_scenario import _UnstableAdversarialScenario
38
40
from azure .ai .evaluation .simulator ._utils import JsonLineList
@@ -72,6 +74,7 @@ class _SafetyEvaluator(Enum):
72
74
"""
73
75
74
76
CONTENT_SAFETY = "content_safety"
77
+ CODE_VULNERABILITY = "code_vulnerability"
75
78
GROUNDEDNESS = "groundedness"
76
79
PROTECTED_MATERIAL = "protected_material"
77
80
RELEVANCE = "relevance"
@@ -81,6 +84,7 @@ class _SafetyEvaluator(Enum):
81
84
INDIRECT_ATTACK = "indirect_attack"
82
85
DIRECT_ATTACK = "direct_attack"
83
86
ECI = "eci"
87
+ UNGROUNDED_ATTRIBUTES = "ungrounded_attributes"
84
88
85
89
86
90
@experimental
@@ -380,6 +384,10 @@ def _get_scenario(
380
384
)
381
385
if evaluator == _SafetyEvaluator .ECI :
382
386
return _UnstableAdversarialScenario .ECI
387
+ if evaluator == _SafetyEvaluator .CODE_VULNERABILITY :
388
+ return AdversarialScenario .ADVERSARIAL_CODE_VULNERABILITY
389
+ if evaluator == _SafetyEvaluator .UNGROUNDED_ATTRIBUTES :
390
+ return AdversarialScenario .ADVERSARIAL_UNGROUNDED_ATTRIBUTES
383
391
if evaluator in [
384
392
_SafetyEvaluator .GROUNDEDNESS ,
385
393
_SafetyEvaluator .RELEVANCE ,
@@ -461,6 +469,14 @@ def _get_evaluators(
461
469
evaluators_dict ["eci" ] = ECIEvaluator (
462
470
azure_ai_project = self .azure_ai_project , credential = self .credential
463
471
)
472
+ elif evaluator == _SafetyEvaluator .CODE_VULNERABILITY :
473
+ evaluators_dict ["code_vulnerability" ] = _code_vulnerability .CodeVulnerabilityEvaluator (
474
+ azure_ai_project = self .azure_ai_project , credential = self .credential
475
+ )
476
+ elif evaluator == _SafetyEvaluator .UNGROUNDED_ATTRIBUTES :
477
+ evaluators_dict ["ungrounded_attributes" ] = _ungrounded_attributes .UngroundedAttributesEvaluator (
478
+ azure_ai_project = self .azure_ai_project , credential = self .credential
479
+ )
464
480
else :
465
481
msg = (
466
482
f"Invalid evaluator: { evaluator } . Supported evaluators are: { _SafetyEvaluator .__members__ .values ()} "
@@ -597,7 +613,28 @@ def _validate_inputs(
597
613
category = ErrorCategory .INVALID_VALUE ,
598
614
blame = ErrorBlame .USER_ERROR ,
599
615
)
600
-
616
+
617
+ if _SafetyEvaluator .CODE_VULNERABILITY in evaluators and num_turns > 1 :
618
+ self .logger .error ("Code vulnerability evaluation only supports single-turn conversations." )
619
+ msg = "Code vulnerability evaluation only supports single-turn conversations."
620
+ raise EvaluationException (
621
+ message = msg ,
622
+ internal_message = msg ,
623
+ target = ErrorTarget .UNKNOWN ,
624
+ category = ErrorCategory .INVALID_VALUE ,
625
+ blame = ErrorBlame .USER_ERROR ,
626
+ )
627
+ if _SafetyEvaluator .UNGROUNDED_ATTRIBUTES in evaluators and num_turns > 1 :
628
+ self .logger .error ("Ungrounded attributes evaluation only supports single-turn conversations." )
629
+ msg = "Ungrounded attributes evaluation only supports single-turn conversations."
630
+ raise EvaluationException (
631
+ message = msg ,
632
+ internal_message = msg ,
633
+ target = ErrorTarget .UNKNOWN ,
634
+ category = ErrorCategory .INVALID_VALUE ,
635
+ blame = ErrorBlame .USER_ERROR ,
636
+ )
637
+
601
638
if _SafetyEvaluator .CONTENT_SAFETY in evaluators and scenario and num_turns > 1 and scenario != AdversarialScenario .ADVERSARIAL_CONVERSATION :
602
639
self .logger .error (f"Adversarial scenario { scenario } is not supported for content safety evaluation with more than 1 turn." )
603
640
msg = f"Adversarial scenario { scenario } is not supported for content safety evaluation with more than 1 turn."
0 commit comments