azure-ai-evaluation 0.0.0b0__py3-none-any.whl → 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. azure/ai/evaluation/__init__.py +82 -0
  2. azure/ai/evaluation/_common/__init__.py +16 -0
  3. azure/ai/evaluation/_common/_experimental.py +172 -0
  4. azure/ai/evaluation/_common/constants.py +72 -0
  5. azure/ai/evaluation/_common/math.py +89 -0
  6. azure/ai/evaluation/_common/rai_service.py +632 -0
  7. azure/ai/evaluation/_common/utils.py +445 -0
  8. azure/ai/evaluation/_constants.py +72 -0
  9. azure/ai/evaluation/_evaluate/__init__.py +3 -0
  10. azure/ai/evaluation/_evaluate/_batch_run/__init__.py +9 -0
  11. azure/ai/evaluation/_evaluate/_batch_run/code_client.py +188 -0
  12. azure/ai/evaluation/_evaluate/_batch_run/eval_run_context.py +89 -0
  13. azure/ai/evaluation/_evaluate/_batch_run/proxy_client.py +99 -0
  14. azure/ai/evaluation/_evaluate/_batch_run/target_run_context.py +46 -0
  15. azure/ai/evaluation/_evaluate/_eval_run.py +571 -0
  16. azure/ai/evaluation/_evaluate/_evaluate.py +850 -0
  17. azure/ai/evaluation/_evaluate/_telemetry/__init__.py +179 -0
  18. azure/ai/evaluation/_evaluate/_utils.py +298 -0
  19. azure/ai/evaluation/_evaluators/__init__.py +3 -0
  20. azure/ai/evaluation/_evaluators/_bleu/__init__.py +9 -0
  21. azure/ai/evaluation/_evaluators/_bleu/_bleu.py +72 -0
  22. azure/ai/evaluation/_evaluators/_coherence/__init__.py +7 -0
  23. azure/ai/evaluation/_evaluators/_coherence/_coherence.py +107 -0
  24. azure/ai/evaluation/_evaluators/_coherence/coherence.prompty +99 -0
  25. azure/ai/evaluation/_evaluators/_common/__init__.py +13 -0
  26. azure/ai/evaluation/_evaluators/_common/_base_eval.py +344 -0
  27. azure/ai/evaluation/_evaluators/_common/_base_prompty_eval.py +88 -0
  28. azure/ai/evaluation/_evaluators/_common/_base_rai_svc_eval.py +133 -0
  29. azure/ai/evaluation/_evaluators/_content_safety/__init__.py +17 -0
  30. azure/ai/evaluation/_evaluators/_content_safety/_content_safety.py +144 -0
  31. azure/ai/evaluation/_evaluators/_content_safety/_hate_unfairness.py +129 -0
  32. azure/ai/evaluation/_evaluators/_content_safety/_self_harm.py +123 -0
  33. azure/ai/evaluation/_evaluators/_content_safety/_sexual.py +125 -0
  34. azure/ai/evaluation/_evaluators/_content_safety/_violence.py +126 -0
  35. azure/ai/evaluation/_evaluators/_eci/__init__.py +0 -0
  36. azure/ai/evaluation/_evaluators/_eci/_eci.py +89 -0
  37. azure/ai/evaluation/_evaluators/_f1_score/__init__.py +9 -0
  38. azure/ai/evaluation/_evaluators/_f1_score/_f1_score.py +157 -0
  39. azure/ai/evaluation/_evaluators/_fluency/__init__.py +9 -0
  40. azure/ai/evaluation/_evaluators/_fluency/_fluency.py +104 -0
  41. azure/ai/evaluation/_evaluators/_fluency/fluency.prompty +86 -0
  42. azure/ai/evaluation/_evaluators/_gleu/__init__.py +9 -0
  43. azure/ai/evaluation/_evaluators/_gleu/_gleu.py +69 -0
  44. azure/ai/evaluation/_evaluators/_groundedness/__init__.py +9 -0
  45. azure/ai/evaluation/_evaluators/_groundedness/_groundedness.py +144 -0
  46. azure/ai/evaluation/_evaluators/_groundedness/groundedness_with_query.prompty +113 -0
  47. azure/ai/evaluation/_evaluators/_groundedness/groundedness_without_query.prompty +99 -0
  48. azure/ai/evaluation/_evaluators/_meteor/__init__.py +9 -0
  49. azure/ai/evaluation/_evaluators/_meteor/_meteor.py +90 -0
  50. azure/ai/evaluation/_evaluators/_multimodal/__init__.py +20 -0
  51. azure/ai/evaluation/_evaluators/_multimodal/_content_safety_multimodal.py +132 -0
  52. azure/ai/evaluation/_evaluators/_multimodal/_content_safety_multimodal_base.py +55 -0
  53. azure/ai/evaluation/_evaluators/_multimodal/_hate_unfairness.py +100 -0
  54. azure/ai/evaluation/_evaluators/_multimodal/_protected_material.py +124 -0
  55. azure/ai/evaluation/_evaluators/_multimodal/_self_harm.py +100 -0
  56. azure/ai/evaluation/_evaluators/_multimodal/_sexual.py +100 -0
  57. azure/ai/evaluation/_evaluators/_multimodal/_violence.py +100 -0
  58. azure/ai/evaluation/_evaluators/_protected_material/__init__.py +5 -0
  59. azure/ai/evaluation/_evaluators/_protected_material/_protected_material.py +113 -0
  60. azure/ai/evaluation/_evaluators/_qa/__init__.py +9 -0
  61. azure/ai/evaluation/_evaluators/_qa/_qa.py +93 -0
  62. azure/ai/evaluation/_evaluators/_relevance/__init__.py +9 -0
  63. azure/ai/evaluation/_evaluators/_relevance/_relevance.py +114 -0
  64. azure/ai/evaluation/_evaluators/_relevance/relevance.prompty +100 -0
  65. azure/ai/evaluation/_evaluators/_retrieval/__init__.py +9 -0
  66. azure/ai/evaluation/_evaluators/_retrieval/_retrieval.py +112 -0
  67. azure/ai/evaluation/_evaluators/_retrieval/retrieval.prompty +93 -0
  68. azure/ai/evaluation/_evaluators/_rouge/__init__.py +10 -0
  69. azure/ai/evaluation/_evaluators/_rouge/_rouge.py +98 -0
  70. azure/ai/evaluation/_evaluators/_service_groundedness/__init__.py +9 -0
  71. azure/ai/evaluation/_evaluators/_service_groundedness/_service_groundedness.py +148 -0
  72. azure/ai/evaluation/_evaluators/_similarity/__init__.py +9 -0
  73. azure/ai/evaluation/_evaluators/_similarity/_similarity.py +140 -0
  74. azure/ai/evaluation/_evaluators/_similarity/similarity.prompty +66 -0
  75. azure/ai/evaluation/_evaluators/_xpia/__init__.py +5 -0
  76. azure/ai/evaluation/_evaluators/_xpia/xpia.py +125 -0
  77. azure/ai/evaluation/_exceptions.py +128 -0
  78. azure/ai/evaluation/_http_utils.py +466 -0
  79. azure/ai/evaluation/_model_configurations.py +123 -0
  80. azure/ai/evaluation/_user_agent.py +6 -0
  81. azure/ai/evaluation/_vendor/__init__.py +3 -0
  82. azure/ai/evaluation/_vendor/rouge_score/__init__.py +14 -0
  83. azure/ai/evaluation/_vendor/rouge_score/rouge_scorer.py +328 -0
  84. azure/ai/evaluation/_vendor/rouge_score/scoring.py +63 -0
  85. azure/ai/evaluation/_vendor/rouge_score/tokenize.py +63 -0
  86. azure/ai/evaluation/_vendor/rouge_score/tokenizers.py +53 -0
  87. azure/ai/evaluation/_version.py +5 -0
  88. azure/ai/evaluation/py.typed +0 -0
  89. azure/ai/evaluation/simulator/__init__.py +16 -0
  90. azure/ai/evaluation/simulator/_adversarial_scenario.py +46 -0
  91. azure/ai/evaluation/simulator/_adversarial_simulator.py +471 -0
  92. azure/ai/evaluation/simulator/_constants.py +27 -0
  93. azure/ai/evaluation/simulator/_conversation/__init__.py +316 -0
  94. azure/ai/evaluation/simulator/_conversation/_conversation.py +178 -0
  95. azure/ai/evaluation/simulator/_conversation/constants.py +30 -0
  96. azure/ai/evaluation/simulator/_data_sources/__init__.py +3 -0
  97. azure/ai/evaluation/simulator/_data_sources/grounding.json +1150 -0
  98. azure/ai/evaluation/simulator/_direct_attack_simulator.py +218 -0
  99. azure/ai/evaluation/simulator/_helpers/__init__.py +4 -0
  100. azure/ai/evaluation/simulator/_helpers/_language_suffix_mapping.py +17 -0
  101. azure/ai/evaluation/simulator/_helpers/_simulator_data_classes.py +96 -0
  102. azure/ai/evaluation/simulator/_indirect_attack_simulator.py +220 -0
  103. azure/ai/evaluation/simulator/_model_tools/__init__.py +23 -0
  104. azure/ai/evaluation/simulator/_model_tools/_identity_manager.py +195 -0
  105. azure/ai/evaluation/simulator/_model_tools/_proxy_completion_model.py +244 -0
  106. azure/ai/evaluation/simulator/_model_tools/_rai_client.py +168 -0
  107. azure/ai/evaluation/simulator/_model_tools/_template_handler.py +201 -0
  108. azure/ai/evaluation/simulator/_model_tools/models.py +614 -0
  109. azure/ai/evaluation/simulator/_prompty/__init__.py +0 -0
  110. azure/ai/evaluation/simulator/_prompty/task_query_response.prompty +65 -0
  111. azure/ai/evaluation/simulator/_prompty/task_simulate.prompty +37 -0
  112. azure/ai/evaluation/simulator/_simulator.py +716 -0
  113. azure/ai/evaluation/simulator/_tracing.py +89 -0
  114. azure/ai/evaluation/simulator/_utils.py +132 -0
  115. azure_ai_evaluation-1.0.0.dist-info/METADATA +595 -0
  116. azure_ai_evaluation-1.0.0.dist-info/NOTICE.txt +70 -0
  117. azure_ai_evaluation-1.0.0.dist-info/RECORD +119 -0
  118. {azure_ai_evaluation-0.0.0b0.dist-info → azure_ai_evaluation-1.0.0.dist-info}/WHEEL +1 -1
  119. azure_ai_evaluation-1.0.0.dist-info/top_level.txt +1 -0
  120. azure_ai_evaluation-0.0.0b0.dist-info/METADATA +0 -7
  121. azure_ai_evaluation-0.0.0b0.dist-info/RECORD +0 -4
  122. azure_ai_evaluation-0.0.0b0.dist-info/top_level.txt +0 -1
@@ -0,0 +1,100 @@
1
+ # ---------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # ---------------------------------------------------------
4
+ from promptflow._utils.async_utils import async_run_allowing_running_loop
5
+ from azure.ai.evaluation._common._experimental import experimental
6
+ from azure.ai.evaluation._common.constants import EvaluationMetrics
7
+ from ._content_safety_multimodal_base import ContentSafetyMultimodalEvaluatorBase
8
+
9
+
10
+ @experimental
11
+ class HateUnfairnessMultimodalEvaluator:
12
+ """
13
+ Initialize a hate-unfairness multimodal evaluator for hate unfairness score.
14
+
15
+ :param credential: The credential for connecting to the Azure AI project. This is required.
16
+ :type credential: ~azure.core.credentials.TokenCredential
17
+ :param azure_ai_project: The scope of the Azure AI project,
18
+ which includes subscription ID, resource group name, and project name.
19
+ :type azure_ai_project: ~azure.ai.evaluation.AzureAIProject
20
+
21
+ **Usage Example**
22
+
23
+ .. code-block:: python
24
+
25
+ azure_ai_project = {
26
+ "subscription_id": "<subscription_id>",
27
+ "resource_group_name": "<resource_group_name>",
28
+ "project_name": "<project_name>",
29
+ }
30
+ eval_fn = HateUnfairnessMultimodalEvaluator(azure_ai_project)
31
+ result = eval_fn(conversation=
32
+ {
33
+ "messages": [
34
+ {
35
+ "role": "user",
36
+ "content": [
37
+ {
38
+ "type": "text",
39
+ "text": "What's in this image?"
40
+ },
41
+ {
42
+ "type": "image_url",
43
+ "image_url": {
44
+ "url": "<image url or base64 encoded image>"
45
+ }
46
+ }
47
+ ]
48
+ },
49
+ {
50
+ "role": "assistant",
51
+ "content": "This picture shows an astronaut standing in the desert."
52
+ }
53
+ ]
54
+ }
55
+ )
56
+
57
+ **Output Format**
58
+
59
+ .. code-block:: json
60
+
61
+ {
62
+ "hate_unfairness": "High",
63
+ "hate_unfairness_score": 6.5,
64
+ "hate_unfairness_reason": "Some reason"
65
+ }
66
+
67
+ """
68
+
69
+ id = "hate_unfairness_multimodal"
70
+ """Evaluator identifier, experimental and to be used only with evaluation in cloud."""
71
+
72
+ def __init__(self, credential, azure_ai_project):
73
+ self._async_evaluator = _AsyncHateUnfairnessMultimodalEvaluator(credential, azure_ai_project)
74
+
75
+ def __call__(self, *, conversation, **kwargs):
76
+ """
77
+ Evaluates hate unfairness content.
78
+
79
+ :keyword conversation: The conversation contains list of messages to be evaluated.
80
+ Each message should have "role" and "content" keys. It supports single turn only.
81
+ :paramtype conversation: ~azure.ai.evaluation.Conversation
82
+ :return: The hate unfairness score.
83
+ :rtype: Dict[str, Union[float, str]]
84
+ """
85
+ return async_run_allowing_running_loop(self._async_evaluator, conversation=conversation, **kwargs)
86
+
87
+ def _to_async(self):
88
+ return self._async_evaluator
89
+
90
+
91
+ class _AsyncHateUnfairnessMultimodalEvaluator(ContentSafetyMultimodalEvaluatorBase):
92
+ def __init__(self, credential, azure_ai_project):
93
+ super().__init__(
94
+ metric=EvaluationMetrics.HATE_FAIRNESS,
95
+ credential=credential,
96
+ azure_ai_project=azure_ai_project,
97
+ )
98
+
99
+ async def __call__(self, *, conversation, **kwargs):
100
+ return await super().__call__(conversation=conversation, **kwargs)
@@ -0,0 +1,124 @@
1
+ # ---------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # ---------------------------------------------------------
4
+ from promptflow._utils.async_utils import async_run_allowing_running_loop
5
+ from azure.ai.evaluation._common.constants import EvaluationMetrics
6
+ from azure.ai.evaluation._common.utils import validate_conversation
7
+ from azure.ai.evaluation._common.rai_service import evaluate_with_rai_service_multimodal
8
+ from azure.ai.evaluation._common._experimental import experimental
9
+
10
+
11
+ @experimental
12
+ class ProtectedMaterialMultimodalEvaluator:
13
+ """
14
+ Initialize a protected materials evaluator to detect whether protected material
15
+ is present in multimodal messages. The evaluator outputs a Boolean label (`True` or `False`)
16
+ indicating the presence of protected material, along with AI-generated reasoning.
17
+
18
+ :param credential: The credential for connecting to the Azure AI project. This is required.
19
+ :type credential: ~azure.core.credentials.TokenCredential
20
+ :param azure_ai_project: The scope of the Azure AI project, containing the subscription ID,
21
+ resource group, and project name.
22
+ :type azure_ai_project: ~azure.ai.evaluation.AzureAIProject
23
+
24
+ :return: A dictionary containing the evaluation result label and reasoning.
25
+
26
+ **Usage Example**
27
+
28
+ .. code-block:: python
29
+
30
+ azure_ai_project = {
31
+ "subscription_id": "<subscription_id>",
32
+ "resource_group_name": "<resource_group_name>",
33
+ "project_name": "<project_name>",
34
+ }
35
+ eval_fn = ProtectedMaterialMultimodalEvaluator(azure_ai_project)
36
+ result = eval_fn(conversation=
37
+ {
38
+ "messages": [
39
+ {
40
+ "role": "user",
41
+ "content": [
42
+ {
43
+ "type": "text",
44
+ "text": "What's in this image?"
45
+ },
46
+ {
47
+ "type": "image_url",
48
+ "image_url": {
49
+ "url": "<image url or base64 encoded image>"
50
+ }
51
+ }
52
+ ]
53
+ },
54
+ {
55
+ "role": "assistant",
56
+ "content": "This picture shows an astronaut standing in the desert."
57
+ }
58
+ ]
59
+ }
60
+ )
61
+
62
+ **Output Format**
63
+
64
+ .. code-block:: json
65
+
66
+ {
67
+ "protected_material_label": "False",
68
+ "protected_material_reason": "This query does not contain any protected material."
69
+ }
70
+
71
+ """
72
+
73
+ id = "protected_material_multimodal"
74
+ """Evaluator identifier, experimental and to be used only with evaluation in cloud."""
75
+
76
+ def __init__(
77
+ self,
78
+ credential,
79
+ azure_ai_project,
80
+ ):
81
+ self._async_evaluator = _AsyncProtectedMaterialMultimodalEvaluator(credential, azure_ai_project)
82
+
83
+ def __call__(self, *, conversation, **kwargs):
84
+ """
85
+ Evaluates protected materials content.
86
+
87
+ :keyword conversation: The conversation contains list of messages to be evaluated.
88
+ Each message should have "role" and "content" keys. It supports single turn only.
89
+ :paramtype conversation: ~azure.ai.evaluation.Conversation
90
+ :return: A dictionary containing a boolean label and reasoning.
91
+ :rtype: Dict[str, str]
92
+ """
93
+ return async_run_allowing_running_loop(self._async_evaluator, conversation=conversation, **kwargs)
94
+
95
+ def _to_async(self):
96
+ return self._async_evaluator
97
+
98
+
99
+ class _AsyncProtectedMaterialMultimodalEvaluator:
100
+ def __init__(self, credential, azure_ai_project):
101
+ self._credential = credential
102
+ self._azure_ai_project = azure_ai_project
103
+
104
+ async def __call__(self, *, conversation, **kwargs):
105
+ """
106
+ Evaluates content according to this evaluator's metric.
107
+
108
+ :keyword conversation: The conversation contains list of messages to be evaluated.
109
+ Each message should have "role" and "content" keys. It supports single turn only.
110
+ :paramtype conversation: ~azure.ai.evaluation.Conversation
111
+ :return: The evaluation score computation based on the Content Safety metric (self.metric).
112
+ :rtype: Any
113
+ """
114
+ # Validate inputs
115
+ validate_conversation(conversation)
116
+ messages = conversation["messages"]
117
+ # Run score computation based on supplied metric.
118
+ result = await evaluate_with_rai_service_multimodal(
119
+ messages=messages,
120
+ metric_name=EvaluationMetrics.PROTECTED_MATERIAL,
121
+ credential=self._credential,
122
+ project_scope=self._azure_ai_project,
123
+ )
124
+ return result
@@ -0,0 +1,100 @@
1
+ # ---------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # ---------------------------------------------------------
4
+ from promptflow._utils.async_utils import async_run_allowing_running_loop
5
+ from azure.ai.evaluation._common._experimental import experimental
6
+ from azure.ai.evaluation._common.constants import EvaluationMetrics
7
+ from ._content_safety_multimodal_base import ContentSafetyMultimodalEvaluatorBase
8
+
9
+
10
+ @experimental
11
+ class SelfHarmMultimodalEvaluator:
12
+ """
13
+ Initialize a self harm multimodal evaluator for self harm score.
14
+
15
+ :param credential: The credential for connecting to the Azure AI project. This is required.
16
+ :type credential: ~azure.core.credentials.TokenCredential
17
+ :param azure_ai_project: The scope of the Azure AI project,
18
+ which includes subscription ID, resource group name, and project name.
19
+ :type azure_ai_project: ~azure.ai.evaluation.AzureAIProject
20
+
21
+ **Usage Example**
22
+
23
+ .. code-block:: python
24
+
25
+ azure_ai_project = {
26
+ "subscription_id": "<subscription_id>",
27
+ "resource_group_name": "<resource_group_name>",
28
+ "project_name": "<project_name>",
29
+ }
30
+ eval_fn = SelfHarmMultimodalEvaluator(azure_ai_project)
31
+ result = eval_fn(conversation=
32
+ {
33
+ "messages": [
34
+ {
35
+ "role": "user",
36
+ "content": [
37
+ {
38
+ "type": "text",
39
+ "text": "What's in this image?"
40
+ },
41
+ {
42
+ "type": "image_url",
43
+ "image_url": {
44
+ "url": "<image url or base64 encoded image>"
45
+ }
46
+ }
47
+ ]
48
+ },
49
+ {
50
+ "role": "assistant",
51
+ "content": "This picture shows an astronaut standing in the desert."
52
+ }
53
+ ]
54
+ }
55
+ )
56
+
57
+ **Output Format**
58
+
59
+ .. code-block:: json
60
+
61
+ {
62
+ "self_harm": "High",
63
+ "self_harm_score": 6.5,
64
+ "self_harm_reason": "Some reason"
65
+ }
66
+
67
+ """
68
+
69
+ id = "self_harm_multimodal"
70
+ """Evaluator identifier, experimental and to be used only with evaluation in cloud."""
71
+
72
+ def __init__(self, credential, azure_ai_project):
73
+ self._async_evaluator = _AsyncSelfHarmMultimodalEvaluator(credential, azure_ai_project)
74
+
75
+ def __call__(self, *, conversation, **kwargs):
76
+ """
77
+ Evaluates self harm content.
78
+
79
+ :keyword conversation: The conversation contains list of messages to be evaluated.
80
+ Each message should have "role" and "content" keys. It supports single turn only.
81
+ :paramtype conversation: ~azure.ai.evaluation.Conversation
82
+ :return: The self harm score.
83
+ :rtype: Dict[str, Union[float, str]]
84
+ """
85
+ return async_run_allowing_running_loop(self._async_evaluator, conversation=conversation, **kwargs)
86
+
87
+ def _to_async(self):
88
+ return self._async_evaluator
89
+
90
+
91
+ class _AsyncSelfHarmMultimodalEvaluator(ContentSafetyMultimodalEvaluatorBase):
92
+ def __init__(self, credential, azure_ai_project):
93
+ super().__init__(
94
+ metric=EvaluationMetrics.SELF_HARM,
95
+ credential=credential,
96
+ azure_ai_project=azure_ai_project,
97
+ )
98
+
99
+ async def __call__(self, *, conversation, **kwargs):
100
+ return await super().__call__(conversation=conversation, **kwargs)
@@ -0,0 +1,100 @@
1
+ # ---------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # ---------------------------------------------------------
4
+ from promptflow._utils.async_utils import async_run_allowing_running_loop
5
+ from azure.ai.evaluation._common.constants import EvaluationMetrics
6
+ from azure.ai.evaluation._common._experimental import experimental
7
+ from ._content_safety_multimodal_base import ContentSafetyMultimodalEvaluatorBase
8
+
9
+
10
+ @experimental
11
+ class SexualMultimodalEvaluator:
12
+ """
13
+ Initialize a sexual multimodal evaluator for sexual score.
14
+
15
+ :param credential: The credential for connecting to the Azure AI project. This is required.
16
+ :type credential: ~azure.core.credentials.TokenCredential
17
+ :param azure_ai_project: The scope of the Azure AI project,
18
+ which includes subscription ID, resource group name, and project name.
19
+ :type azure_ai_project: ~azure.ai.evaluation.AzureAIProject
20
+
21
+ **Usage Example**
22
+
23
+ .. code-block:: python
24
+
25
+ azure_ai_project = {
26
+ "subscription_id": "<subscription_id>",
27
+ "resource_group_name": "<resource_group_name>",
28
+ "project_name": "<project_name>",
29
+ }
30
+ eval_fn = SexualMultimodalEvaluator(azure_ai_project)
31
+ result = eval_fn(conversation=
32
+ {
33
+ "messages": [
34
+ {
35
+ "role": "user",
36
+ "content": [
37
+ {
38
+ "type": "text",
39
+ "text": "What's in this image?"
40
+ },
41
+ {
42
+ "type": "image_url",
43
+ "image_url": {
44
+ "url": "<image url or base64 encoded image>"
45
+ }
46
+ }
47
+ ]
48
+ },
49
+ {
50
+ "role": "assistant",
51
+ "content": "This picture shows an astronaut standing in the desert."
52
+ }
53
+ ]
54
+ }
55
+ )
56
+
57
+ **Output Format**
58
+
59
+ .. code-block:: json
60
+
61
+ {
62
+ "sexual": "High",
63
+ "sexual_score": 6.5,
64
+ "sexual_reason": "Some reason"
65
+ }
66
+
67
+ """
68
+
69
+ id = "sexual_multimodal"
70
+ """Evaluator identifier, experimental and to be used only with evaluation in cloud."""
71
+
72
+ def __init__(self, credential, azure_ai_project):
73
+ self._async_evaluator = _AsyncSexualMultimodalEvaluator(credential, azure_ai_project)
74
+
75
+ def __call__(self, *, conversation, **kwargs):
76
+ """
77
+ Evaluates sexual content.
78
+
79
+ :keyword conversation: The conversation contains list of messages to be evaluated.
80
+ Each message should have "role" and "content" keys. It supports single turn only.
81
+ :paramtype conversation: ~azure.ai.evaluation.Conversation
82
+ :return: The sexual score.
83
+ :rtype: Dict[str, Union[float, str]]
84
+ """
85
+ return async_run_allowing_running_loop(self._async_evaluator, conversation=conversation, **kwargs)
86
+
87
+ def _to_async(self):
88
+ return self._async_evaluator
89
+
90
+
91
+ class _AsyncSexualMultimodalEvaluator(ContentSafetyMultimodalEvaluatorBase):
92
+ def __init__(self, credential, azure_ai_project):
93
+ super().__init__(
94
+ metric=EvaluationMetrics.SEXUAL,
95
+ credential=credential,
96
+ azure_ai_project=azure_ai_project,
97
+ )
98
+
99
+ async def __call__(self, *, conversation, **kwargs):
100
+ return await super().__call__(conversation=conversation, **kwargs)
@@ -0,0 +1,100 @@
1
+ # ---------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # ---------------------------------------------------------
4
+ from promptflow._utils.async_utils import async_run_allowing_running_loop
5
+ from azure.ai.evaluation._common._experimental import experimental
6
+ from azure.ai.evaluation._common.constants import EvaluationMetrics
7
+ from ._content_safety_multimodal_base import ContentSafetyMultimodalEvaluatorBase
8
+
9
+
10
+ @experimental
11
+ class ViolenceMultimodalEvaluator:
12
+ """
13
+ Initialize a violence multimodal evaluator for violence score.
14
+
15
+ :param credential: The credential for connecting to the Azure AI project. This is required.
16
+ :type credential: ~azure.core.credentials.TokenCredential
17
+ :param azure_ai_project: The scope of the Azure AI project,
18
+ which includes subscription ID, resource group name, and project name.
19
+ :type azure_ai_project: ~azure.ai.evaluation.AzureAIProject
20
+
21
+ **Usage Example**
22
+
23
+ .. code-block:: python
24
+
25
+ azure_ai_project = {
26
+ "subscription_id": "<subscription_id>",
27
+ "resource_group_name": "<resource_group_name>",
28
+ "project_name": "<project_name>",
29
+ }
30
+ eval_fn = ViolenceMultimodalEvaluator(azure_ai_project)
31
+ result = eval_fn(conversation=
32
+ {
33
+ "messages": [
34
+ {
35
+ "role": "user",
36
+ "content": [
37
+ {
38
+ "type": "text",
39
+ "text": "What's in this image?"
40
+ },
41
+ {
42
+ "type": "image_url",
43
+ "image_url": {
44
+ "url": "<image url or base64 encoded image>"
45
+ }
46
+ }
47
+ ]
48
+ },
49
+ {
50
+ "role": "assistant",
51
+ "content": "This picture shows an astronaut standing in the desert."
52
+ }
53
+ ]
54
+ }
55
+ )
56
+
57
+ **Output Format**
58
+
59
+ .. code-block:: json
60
+
61
+ {
62
+ "violence": "High",
63
+ "violence_score": 6.5,
64
+ "violence_reason": "Some reason"
65
+ }
66
+
67
+ """
68
+
69
+ id = "violence_multimodal"
70
+ """Evaluator identifier, experimental and to be used only with evaluation in cloud."""
71
+
72
+ def __init__(self, credential, azure_ai_project):
73
+ self._async_evaluator = _AsyncViolenceMultimodalEvaluator(credential, azure_ai_project)
74
+
75
+ def __call__(self, *, conversation, **kwargs):
76
+ """
77
+ Evaluates violence content.
78
+
79
+ :keyword conversation: The conversation contains list of messages to be evaluated.
80
+ Each message should have "role" and "content" keys. It supports single turn only.
81
+ :paramtype conversation: ~azure.ai.evaluation.Conversation
82
+ :return: The violence score.
83
+ :rtype: Dict[str, Union[float, str]]
84
+ """
85
+ return async_run_allowing_running_loop(self._async_evaluator, conversation=conversation, **kwargs)
86
+
87
+ def _to_async(self):
88
+ return self._async_evaluator
89
+
90
+
91
+ class _AsyncViolenceMultimodalEvaluator(ContentSafetyMultimodalEvaluatorBase):
92
+ def __init__(self, credential, azure_ai_project):
93
+ super().__init__(
94
+ metric=EvaluationMetrics.VIOLENCE,
95
+ credential=credential,
96
+ azure_ai_project=azure_ai_project,
97
+ )
98
+
99
+ async def __call__(self, *, conversation, **kwargs):
100
+ return await super().__call__(conversation=conversation, **kwargs)
@@ -0,0 +1,5 @@
1
+ from ._protected_material import ProtectedMaterialEvaluator
2
+
3
+ __all__ = [
4
+ "ProtectedMaterialEvaluator",
5
+ ]
@@ -0,0 +1,113 @@
1
+ # ---------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # ---------------------------------------------------------
4
+
5
+ from typing import Dict, List, Optional, Union
6
+
7
+ from typing_extensions import overload, override
8
+
9
+ from azure.ai.evaluation._common._experimental import experimental
10
+ from azure.ai.evaluation._common.constants import EvaluationMetrics
11
+ from azure.ai.evaluation._evaluators._common import RaiServiceEvaluatorBase
12
+ from azure.ai.evaluation._model_configurations import Conversation
13
+
14
+
15
+ @experimental
16
+ class ProtectedMaterialEvaluator(RaiServiceEvaluatorBase[Union[str, bool]]):
17
+ """
18
+ Evaluates the protected material score for a given query and response or a multi-turn conversation, with reasoning.
19
+
20
+ Protected material is any text that is under copyright, including song lyrics, recipes, and articles. Protected
21
+ material evaluation leverages the Azure AI Content Safety Protected Material for Text service to perform the
22
+ classification.
23
+
24
+ The protected material score is a boolean value, where True indicates that protected material was detected.
25
+
26
+ :param credential: The credential required for connecting to the Azure AI project.
27
+ :type credential: ~azure.core.credentials.TokenCredential
28
+ :param azure_ai_project: The scope of the Azure AI project, containing the subscription ID,
29
+ resource group, and project name.
30
+ :type azure_ai_project: ~azure.ai.evaluation.AzureAIProject
31
+
32
+ .. admonition:: Example:
33
+
34
+ .. literalinclude:: ../samples/evaluation_samples_evaluate.py
35
+ :start-after: [START protected_material_evaluator]
36
+ :end-before: [END protected_material_evaluator]
37
+ :language: python
38
+ :dedent: 8
39
+ :caption: Initialize and call a ProtectedMaterialEvaluator.
40
+ """
41
+
42
+ id = "azureml://registries/azureml/models/Protected-Material-Evaluator/versions/3"
43
+ """Evaluator identifier, experimental and to be used only with evaluation in cloud."""
44
+
45
+ @override
46
+ def __init__(
47
+ self,
48
+ credential,
49
+ azure_ai_project,
50
+ ):
51
+ super().__init__(
52
+ eval_metric=EvaluationMetrics.PROTECTED_MATERIAL,
53
+ azure_ai_project=azure_ai_project,
54
+ credential=credential,
55
+ )
56
+
57
+ @overload
58
+ def __call__(
59
+ self,
60
+ *,
61
+ query: str,
62
+ response: str,
63
+ ) -> Dict[str, Union[str, bool]]:
64
+ """Evaluate a given query/response pair for protected material
65
+
66
+ :keyword query: The query to be evaluated.
67
+ :paramtype query: str
68
+ :keyword response: The response to be evaluated.
69
+ :paramtype response: str
70
+ :return: The protected material score.
71
+ :rtype: Dict[str, Union[str, bool]]
72
+ """
73
+
74
+ @overload
75
+ def __call__(
76
+ self,
77
+ *,
78
+ conversation: Conversation,
79
+ ) -> Dict[str, Union[float, Dict[str, List[Union[str, bool]]]]]:
80
+ """Evaluate a conversation for protected material
81
+
82
+ :keyword conversation: The conversation to evaluate. Expected to contain a list of conversation turns under the
83
+ key "messages", and potentially a global context under the key "context". Conversation turns are expected
84
+ to be dictionaries with keys "content", "role", and possibly "context".
85
+ :paramtype conversation: Optional[~azure.ai.evaluation.Conversation]
86
+ :return: The protected material score.
87
+ :rtype: Dict[str, Union[str, bool, Dict[str, List[Union[str, bool]]]]]
88
+ """
89
+
90
+ @override
91
+ def __call__(
92
+ self,
93
+ *,
94
+ query: Optional[str] = None,
95
+ response: Optional[str] = None,
96
+ conversation=None,
97
+ **kwargs,
98
+ ):
99
+ """
100
+ Evaluate if protected material is present in your AI system's response.
101
+
102
+ :keyword query: The query to be evaluated.
103
+ :paramtype query: Optional[str]
104
+ :keyword response: The response to be evaluated.
105
+ :paramtype response: Optional[str]
106
+ :keyword conversation: The conversation to evaluate. Expected to contain a list of conversation turns under the
107
+ key "messages". Conversation turns are expected
108
+ to be dictionaries with keys "content" and "role".
109
+ :paramtype conversation: Optional[~azure.ai.evaluation.Conversation]
110
+ :return: The fluency score.
111
+ :rtype: Union[Dict[str, Union[str, bool]], Dict[str, Union[float, Dict[str, List[Union[str, bool]]]]]]
112
+ """
113
+ return super().__call__(query=query, response=response, conversation=conversation, **kwargs)
@@ -0,0 +1,9 @@
1
+ # ---------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # ---------------------------------------------------------
4
+
5
+ from ._qa import QAEvaluator
6
+
7
+ __all__ = [
8
+ "QAEvaluator",
9
+ ]