azure-ai-evaluation 1.1.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 (48) hide show
  1. azure/ai/evaluation/__init__.py +1 -15
  2. azure/ai/evaluation/_azure/_clients.py +24 -8
  3. azure/ai/evaluation/_azure/_models.py +2 -2
  4. azure/ai/evaluation/_common/utils.py +8 -8
  5. azure/ai/evaluation/_constants.py +21 -0
  6. azure/ai/evaluation/_evaluate/_batch_run/__init__.py +2 -1
  7. azure/ai/evaluation/_evaluate/_eval_run.py +3 -1
  8. azure/ai/evaluation/_evaluate/_evaluate.py +74 -14
  9. azure/ai/evaluation/_evaluate/_utils.py +27 -0
  10. azure/ai/evaluation/_evaluators/_bleu/_bleu.py +46 -25
  11. azure/ai/evaluation/_evaluators/_common/__init__.py +2 -0
  12. azure/ai/evaluation/_evaluators/_common/_base_eval.py +69 -4
  13. azure/ai/evaluation/_evaluators/_common/_base_multi_eval.py +61 -0
  14. azure/ai/evaluation/_evaluators/_common/_base_rai_svc_eval.py +7 -1
  15. azure/ai/evaluation/_evaluators/_common/_conversation_aggregators.py +49 -0
  16. azure/ai/evaluation/_evaluators/_content_safety/_content_safety.py +5 -42
  17. azure/ai/evaluation/_evaluators/_content_safety/_hate_unfairness.py +2 -0
  18. azure/ai/evaluation/_evaluators/_content_safety/_self_harm.py +2 -0
  19. azure/ai/evaluation/_evaluators/_content_safety/_sexual.py +2 -0
  20. azure/ai/evaluation/_evaluators/_content_safety/_violence.py +2 -0
  21. azure/ai/evaluation/_evaluators/_f1_score/_f1_score.py +61 -68
  22. azure/ai/evaluation/_evaluators/_gleu/_gleu.py +45 -23
  23. azure/ai/evaluation/_evaluators/_meteor/_meteor.py +55 -34
  24. azure/ai/evaluation/_evaluators/_qa/_qa.py +32 -27
  25. azure/ai/evaluation/_evaluators/_rouge/_rouge.py +44 -23
  26. azure/ai/evaluation/_evaluators/_similarity/_similarity.py +41 -81
  27. azure/ai/evaluation/_exceptions.py +0 -1
  28. azure/ai/evaluation/_safety_evaluation/__init__.py +3 -0
  29. azure/ai/evaluation/_safety_evaluation/_safety_evaluation.py +640 -0
  30. azure/ai/evaluation/_version.py +2 -1
  31. azure/ai/evaluation/simulator/_adversarial_simulator.py +10 -3
  32. azure/ai/evaluation/simulator/_conversation/__init__.py +4 -5
  33. azure/ai/evaluation/simulator/_conversation/_conversation.py +4 -0
  34. azure/ai/evaluation/simulator/_model_tools/_proxy_completion_model.py +2 -0
  35. azure/ai/evaluation/simulator/_simulator.py +21 -13
  36. {azure_ai_evaluation-1.1.0.dist-info → azure_ai_evaluation-1.3.0.dist-info}/METADATA +77 -7
  37. {azure_ai_evaluation-1.1.0.dist-info → azure_ai_evaluation-1.3.0.dist-info}/RECORD +40 -44
  38. azure/ai/evaluation/_evaluators/_multimodal/__init__.py +0 -20
  39. azure/ai/evaluation/_evaluators/_multimodal/_content_safety_multimodal.py +0 -132
  40. azure/ai/evaluation/_evaluators/_multimodal/_content_safety_multimodal_base.py +0 -55
  41. azure/ai/evaluation/_evaluators/_multimodal/_hate_unfairness.py +0 -100
  42. azure/ai/evaluation/_evaluators/_multimodal/_protected_material.py +0 -124
  43. azure/ai/evaluation/_evaluators/_multimodal/_self_harm.py +0 -100
  44. azure/ai/evaluation/_evaluators/_multimodal/_sexual.py +0 -100
  45. azure/ai/evaluation/_evaluators/_multimodal/_violence.py +0 -100
  46. {azure_ai_evaluation-1.1.0.dist-info → azure_ai_evaluation-1.3.0.dist-info}/NOTICE.txt +0 -0
  47. {azure_ai_evaluation-1.1.0.dist-info → azure_ai_evaluation-1.3.0.dist-info}/WHEEL +0 -0
  48. {azure_ai_evaluation-1.1.0.dist-info → azure_ai_evaluation-1.3.0.dist-info}/top_level.txt +0 -0
@@ -1,132 +0,0 @@
1
- # ---------------------------------------------------------
2
- # Copyright (c) Microsoft Corporation. All rights reserved.
3
- # ---------------------------------------------------------
4
- import logging
5
- from concurrent.futures import as_completed
6
- from typing import Callable, Dict, List, Union
7
-
8
- from promptflow.tracing import ThreadPoolExecutorWithContext as ThreadPoolExecutor
9
- from azure.ai.evaluation._common._experimental import experimental
10
- from azure.ai.evaluation._common.utils import validate_conversation
11
- from ._hate_unfairness import HateUnfairnessMultimodalEvaluator
12
- from ._self_harm import SelfHarmMultimodalEvaluator
13
- from ._sexual import SexualMultimodalEvaluator
14
- from ._violence import ViolenceMultimodalEvaluator
15
-
16
-
17
- logger = logging.getLogger(__name__)
18
-
19
-
20
- @experimental
21
- class ContentSafetyMultimodalEvaluator:
22
- """
23
- Initialize a content safety multimodal evaluator configured to evaluate content safety metrics
24
- in a multimodal scenario.
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
- :param kwargs: Additional arguments to pass to the evaluator.
32
- :type kwargs: Any
33
-
34
- :return: A function that evaluates multimodal chat messages and generates content safety metrics.
35
-
36
- **Usage Example**
37
-
38
- .. code-block:: python
39
-
40
- azure_ai_project = {
41
- "subscription_id": "<subscription_id>",
42
- "resource_group_name": "<resource_group_name>",
43
- "project_name": "<project_name>",
44
- }
45
- eval_fn = ContentSafetyMultimodalEvaluator(azure_ai_project)
46
- result = eval_fn(conversation=
47
- {
48
- "messages": [
49
- {
50
- "role": "user",
51
- "content": [
52
- {
53
- "type": "text",
54
- "text": "What's in this image?"
55
- },
56
- {
57
- "type": "image_url",
58
- "image_url": {
59
- "url": "<image url or base64 encoded image>"
60
- }
61
- }
62
- ]
63
- },
64
- {
65
- "role": "assistant",
66
- "content": "This picture shows an astronaut standing in the desert."
67
- }
68
- ]
69
- }
70
- )
71
-
72
- **Output Format**
73
-
74
- .. code-block:: json
75
-
76
- {
77
- "violence": "Medium",
78
- "violence_score": 5.0,
79
- "violence_reason": "Some reason",
80
- "sexual": "Medium",
81
- "sexual_score": 5.0,
82
- "sexual_reason": "Some reason",
83
- "self_harm": "Medium",
84
- "self_harm_score": 5.0,
85
- "self_harm_reason": "Some reason",
86
- "hate_unfairness": "Medium",
87
- "hate_unfairness_score": 5.0,
88
- "hate_unfairness_reason": "Some reason"
89
- }
90
-
91
- """
92
-
93
- id = "content_safety_multimodal"
94
- """Evaluator identifier, experimental and to be used only with evaluation in cloud."""
95
-
96
- def __init__(self, credential, azure_ai_project, **kwargs):
97
- self._parallel = kwargs.pop("_parallel", False)
98
- self._evaluators: List[Callable[..., Dict[str, Union[str, float]]]] = [
99
- ViolenceMultimodalEvaluator(credential=credential, azure_ai_project=azure_ai_project),
100
- SexualMultimodalEvaluator(credential=credential, azure_ai_project=azure_ai_project),
101
- SelfHarmMultimodalEvaluator(credential=credential, azure_ai_project=azure_ai_project),
102
- HateUnfairnessMultimodalEvaluator(credential=credential, azure_ai_project=azure_ai_project),
103
- ]
104
-
105
- def __call__(self, *, conversation, **kwargs):
106
- """
107
- Evaluates content-safety metrics for list of messages.
108
-
109
- :keyword conversation: The conversation contains list of messages to be evaluated.
110
- Each message should have "role" and "content" keys. It supports single turn only.
111
- :paramtype conversation: ~azure.ai.evaluation.Conversation
112
- :return: The evaluation score based on the Content Safety Metrics.
113
- :rtype: Dict[str, Union[float, str]]
114
- """
115
- # validate inputs
116
- validate_conversation(conversation)
117
- results: Dict[str, Union[str, float]] = {}
118
- if self._parallel:
119
- with ThreadPoolExecutor() as executor:
120
- futures = {
121
- executor.submit(evaluator, conversation=conversation, **kwargs): evaluator
122
- for evaluator in self._evaluators
123
- }
124
-
125
- for future in as_completed(futures):
126
- results.update(future.result())
127
- else:
128
- for evaluator in self._evaluators:
129
- result = evaluator(conversation=conversation, **kwargs)
130
- results.update(result)
131
-
132
- return results
@@ -1,55 +0,0 @@
1
- # ---------------------------------------------------------
2
- # Copyright (c) Microsoft Corporation. All rights reserved.
3
- # ---------------------------------------------------------
4
- from abc import ABC
5
- from typing import Union
6
- from azure.ai.evaluation._common.rai_service import evaluate_with_rai_service_multimodal
7
- from azure.ai.evaluation._common.constants import EvaluationMetrics, _InternalEvaluationMetrics
8
- from azure.ai.evaluation._common.utils import validate_conversation
9
- from azure.core.credentials import TokenCredential
10
-
11
-
12
- class ContentSafetyMultimodalEvaluatorBase(ABC):
13
- """
14
- Initialize a evaluator for a specified Evaluation Metric. Base class that is not
15
- meant to be instantiated by users.
16
-
17
- :param metric: The metric to be evaluated.
18
- :type metric: ~azure.ai.evaluation._evaluators._content_safety.flow.constants.EvaluationMetrics
19
- :param credential: The credential for connecting to Azure AI project. Required
20
- :type credential: ~azure.core.credentials.TokenCredential
21
- :param azure_ai_project: The scope of the Azure AI project.
22
- It contains subscription id, resource group, and project name.
23
- :type azure_ai_project: ~azure.ai.evaluation.AzureAIProject
24
- """
25
-
26
- def __init__(
27
- self,
28
- metric: Union[EvaluationMetrics, _InternalEvaluationMetrics],
29
- credential: TokenCredential,
30
- azure_ai_project,
31
- ):
32
- self._metric = metric
33
- self._azure_ai_project = azure_ai_project
34
- self._credential = credential
35
-
36
- async def __call__(self, *, conversation, **kwargs):
37
- """
38
- Evaluates content according to this evaluator's metric.
39
- :keyword conversation: The conversation contains list of messages to be evaluated.
40
- Each message should have "role" and "content" keys.
41
- :paramtype conversation: ~azure.ai.evaluation.Conversation
42
- :return: The evaluation score computation based on the Content Safety metric (self.metric).
43
- :rtype: Dict[str, Union[float, str]]
44
- """
45
- # validate inputs
46
- validate_conversation(conversation)
47
- messages = conversation["messages"]
48
- # Run score computation based on supplied metric.
49
- result = await evaluate_with_rai_service_multimodal(
50
- messages=messages,
51
- metric_name=self._metric,
52
- project_scope=self._azure_ai_project,
53
- credential=self._credential,
54
- )
55
- 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 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)
@@ -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)