azure-ai-evaluation 1.2.0__py3-none-any.whl → 1.3.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 (25) hide show
  1. azure/ai/evaluation/__init__.py +1 -15
  2. azure/ai/evaluation/_common/utils.py +8 -8
  3. azure/ai/evaluation/_constants.py +3 -0
  4. azure/ai/evaluation/_evaluate/_evaluate.py +5 -2
  5. azure/ai/evaluation/_exceptions.py +0 -1
  6. azure/ai/evaluation/_safety_evaluation/__init__.py +3 -0
  7. azure/ai/evaluation/_safety_evaluation/_safety_evaluation.py +640 -0
  8. azure/ai/evaluation/_version.py +2 -1
  9. azure/ai/evaluation/simulator/_adversarial_simulator.py +10 -3
  10. azure/ai/evaluation/simulator/_conversation/__init__.py +4 -5
  11. azure/ai/evaluation/simulator/_conversation/_conversation.py +4 -0
  12. azure/ai/evaluation/simulator/_model_tools/_proxy_completion_model.py +2 -0
  13. {azure_ai_evaluation-1.2.0.dist-info → azure_ai_evaluation-1.3.0.dist-info}/METADATA +7 -1
  14. {azure_ai_evaluation-1.2.0.dist-info → azure_ai_evaluation-1.3.0.dist-info}/RECORD +17 -23
  15. azure/ai/evaluation/_evaluators/_multimodal/__init__.py +0 -20
  16. azure/ai/evaluation/_evaluators/_multimodal/_content_safety_multimodal.py +0 -132
  17. azure/ai/evaluation/_evaluators/_multimodal/_content_safety_multimodal_base.py +0 -55
  18. azure/ai/evaluation/_evaluators/_multimodal/_hate_unfairness.py +0 -100
  19. azure/ai/evaluation/_evaluators/_multimodal/_protected_material.py +0 -124
  20. azure/ai/evaluation/_evaluators/_multimodal/_self_harm.py +0 -100
  21. azure/ai/evaluation/_evaluators/_multimodal/_sexual.py +0 -100
  22. azure/ai/evaluation/_evaluators/_multimodal/_violence.py +0 -100
  23. {azure_ai_evaluation-1.2.0.dist-info → azure_ai_evaluation-1.3.0.dist-info}/NOTICE.txt +0 -0
  24. {azure_ai_evaluation-1.2.0.dist-info → azure_ai_evaluation-1.3.0.dist-info}/WHEEL +0 -0
  25. {azure_ai_evaluation-1.2.0.dist-info → azure_ai_evaluation-1.3.0.dist-info}/top_level.txt +0 -0
@@ -1,124 +0,0 @@
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
@@ -1,100 +0,0 @@
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)
@@ -1,100 +0,0 @@
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)
@@ -1,100 +0,0 @@
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)