azure-ai-evaluation 1.0.0b4__py3-none-any.whl → 1.0.1__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.
- azure/ai/evaluation/__init__.py +22 -0
- azure/ai/evaluation/{simulator/_helpers → _common}/_experimental.py +4 -0
- azure/ai/evaluation/_common/constants.py +5 -0
- azure/ai/evaluation/_common/math.py +73 -2
- azure/ai/evaluation/_common/rai_service.py +250 -62
- azure/ai/evaluation/_common/utils.py +196 -23
- azure/ai/evaluation/_constants.py +7 -6
- azure/ai/evaluation/_evaluate/{_batch_run_client → _batch_run}/__init__.py +3 -2
- azure/ai/evaluation/_evaluate/{_batch_run_client/batch_run_context.py → _batch_run/eval_run_context.py} +13 -4
- azure/ai/evaluation/_evaluate/{_batch_run_client → _batch_run}/proxy_client.py +19 -6
- azure/ai/evaluation/_evaluate/_batch_run/target_run_context.py +46 -0
- azure/ai/evaluation/_evaluate/_eval_run.py +55 -14
- azure/ai/evaluation/_evaluate/_evaluate.py +312 -228
- azure/ai/evaluation/_evaluate/_telemetry/__init__.py +7 -6
- azure/ai/evaluation/_evaluate/_utils.py +46 -11
- azure/ai/evaluation/_evaluators/_bleu/_bleu.py +17 -18
- azure/ai/evaluation/_evaluators/_coherence/_coherence.py +67 -31
- azure/ai/evaluation/_evaluators/_coherence/coherence.prompty +76 -34
- azure/ai/evaluation/_evaluators/_common/_base_eval.py +37 -24
- azure/ai/evaluation/_evaluators/_common/_base_prompty_eval.py +21 -9
- azure/ai/evaluation/_evaluators/_common/_base_rai_svc_eval.py +52 -16
- azure/ai/evaluation/_evaluators/_content_safety/_content_safety.py +91 -48
- azure/ai/evaluation/_evaluators/_content_safety/_hate_unfairness.py +100 -26
- azure/ai/evaluation/_evaluators/_content_safety/_self_harm.py +94 -26
- azure/ai/evaluation/_evaluators/_content_safety/_sexual.py +96 -26
- azure/ai/evaluation/_evaluators/_content_safety/_violence.py +97 -26
- azure/ai/evaluation/_evaluators/_eci/_eci.py +31 -4
- azure/ai/evaluation/_evaluators/_f1_score/_f1_score.py +20 -13
- azure/ai/evaluation/_evaluators/_fluency/_fluency.py +67 -36
- azure/ai/evaluation/_evaluators/_fluency/fluency.prompty +66 -36
- azure/ai/evaluation/_evaluators/_gleu/_gleu.py +14 -16
- azure/ai/evaluation/_evaluators/_groundedness/_groundedness.py +106 -34
- azure/ai/evaluation/_evaluators/_groundedness/groundedness_with_query.prompty +113 -0
- azure/ai/evaluation/_evaluators/_groundedness/groundedness_without_query.prompty +99 -0
- azure/ai/evaluation/_evaluators/_meteor/_meteor.py +20 -27
- azure/ai/evaluation/_evaluators/_multimodal/__init__.py +20 -0
- azure/ai/evaluation/_evaluators/_multimodal/_content_safety_multimodal.py +132 -0
- azure/ai/evaluation/_evaluators/_multimodal/_content_safety_multimodal_base.py +55 -0
- azure/ai/evaluation/_evaluators/_multimodal/_hate_unfairness.py +100 -0
- azure/ai/evaluation/_evaluators/_multimodal/_protected_material.py +124 -0
- azure/ai/evaluation/_evaluators/_multimodal/_self_harm.py +100 -0
- azure/ai/evaluation/_evaluators/_multimodal/_sexual.py +100 -0
- azure/ai/evaluation/_evaluators/_multimodal/_violence.py +100 -0
- azure/ai/evaluation/_evaluators/_protected_material/_protected_material.py +87 -31
- azure/ai/evaluation/_evaluators/_qa/_qa.py +23 -31
- azure/ai/evaluation/_evaluators/_relevance/_relevance.py +72 -36
- azure/ai/evaluation/_evaluators/_relevance/relevance.prompty +78 -42
- azure/ai/evaluation/_evaluators/_retrieval/_retrieval.py +83 -125
- azure/ai/evaluation/_evaluators/_retrieval/retrieval.prompty +74 -24
- azure/ai/evaluation/_evaluators/_rouge/_rouge.py +26 -27
- azure/ai/evaluation/_evaluators/_service_groundedness/__init__.py +9 -0
- azure/ai/evaluation/_evaluators/_service_groundedness/_service_groundedness.py +148 -0
- azure/ai/evaluation/_evaluators/_similarity/_similarity.py +37 -28
- azure/ai/evaluation/_evaluators/_xpia/xpia.py +94 -33
- azure/ai/evaluation/_exceptions.py +19 -0
- azure/ai/evaluation/_model_configurations.py +83 -15
- azure/ai/evaluation/_version.py +1 -1
- azure/ai/evaluation/simulator/__init__.py +2 -1
- azure/ai/evaluation/simulator/_adversarial_scenario.py +20 -1
- azure/ai/evaluation/simulator/_adversarial_simulator.py +29 -35
- azure/ai/evaluation/simulator/_constants.py +11 -1
- azure/ai/evaluation/simulator/_data_sources/__init__.py +3 -0
- azure/ai/evaluation/simulator/_data_sources/grounding.json +1150 -0
- azure/ai/evaluation/simulator/_direct_attack_simulator.py +17 -9
- azure/ai/evaluation/simulator/_helpers/__init__.py +1 -2
- azure/ai/evaluation/simulator/_helpers/_simulator_data_classes.py +22 -1
- azure/ai/evaluation/simulator/_indirect_attack_simulator.py +90 -35
- azure/ai/evaluation/simulator/_model_tools/_identity_manager.py +4 -2
- azure/ai/evaluation/simulator/_model_tools/_rai_client.py +8 -4
- azure/ai/evaluation/simulator/_prompty/task_query_response.prompty +4 -4
- azure/ai/evaluation/simulator/_prompty/task_simulate.prompty +6 -1
- azure/ai/evaluation/simulator/_simulator.py +165 -105
- azure/ai/evaluation/simulator/_utils.py +31 -13
- azure_ai_evaluation-1.0.1.dist-info/METADATA +600 -0
- {azure_ai_evaluation-1.0.0b4.dist-info → azure_ai_evaluation-1.0.1.dist-info}/NOTICE.txt +20 -0
- azure_ai_evaluation-1.0.1.dist-info/RECORD +119 -0
- {azure_ai_evaluation-1.0.0b4.dist-info → azure_ai_evaluation-1.0.1.dist-info}/WHEEL +1 -1
- azure/ai/evaluation/_evaluators/_content_safety/_content_safety_chat.py +0 -322
- azure/ai/evaluation/_evaluators/_groundedness/groundedness.prompty +0 -49
- azure_ai_evaluation-1.0.0b4.dist-info/METADATA +0 -535
- azure_ai_evaluation-1.0.0b4.dist-info/RECORD +0 -106
- /azure/ai/evaluation/_evaluate/{_batch_run_client → _batch_run}/code_client.py +0 -0
- {azure_ai_evaluation-1.0.0b4.dist-info → azure_ai_evaluation-1.0.1.dist-info}/top_level.txt +0 -0
|
@@ -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)
|
|
@@ -1,57 +1,113 @@
|
|
|
1
1
|
# ---------------------------------------------------------
|
|
2
2
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
3
|
# ---------------------------------------------------------
|
|
4
|
-
from typing_extensions import override
|
|
5
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
|
|
6
10
|
from azure.ai.evaluation._common.constants import EvaluationMetrics
|
|
7
11
|
from azure.ai.evaluation._evaluators._common import RaiServiceEvaluatorBase
|
|
12
|
+
from azure.ai.evaluation._model_configurations import Conversation
|
|
8
13
|
|
|
9
14
|
|
|
10
|
-
|
|
15
|
+
@experimental
|
|
16
|
+
class ProtectedMaterialEvaluator(RaiServiceEvaluatorBase[Union[str, bool]]):
|
|
11
17
|
"""
|
|
12
|
-
|
|
13
|
-
is present in your AI system's response. Outputs True or False with AI-generated reasoning.
|
|
14
|
-
|
|
15
|
-
:param credential: The credential for connecting to Azure AI project. Required
|
|
16
|
-
:type credential: ~azure.core.credentials.TokenCredential
|
|
17
|
-
:param azure_ai_project: The scope of the Azure AI project.
|
|
18
|
-
It contains subscription id, resource group, and project name.
|
|
19
|
-
:type azure_ai_project: ~azure.ai.evaluation.AzureAIProject
|
|
20
|
-
:return: Whether or not protected material was found in the response, with AI-generated reasoning.
|
|
21
|
-
:rtype: Dict[str, str]
|
|
18
|
+
Evaluates the protected material score for a given query and response or a multi-turn conversation, with reasoning.
|
|
22
19
|
|
|
23
|
-
|
|
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.
|
|
24
23
|
|
|
25
|
-
|
|
24
|
+
The protected material score is a boolean value, where True indicates that protected material was detected.
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
eval_fn = ProtectedMaterialEvaluator(azure_ai_project)
|
|
33
|
-
result = eval_fn(query="What is the capital of France?", response="Paris.")
|
|
34
|
-
|
|
35
|
-
**Output format**
|
|
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
|
|
36
31
|
|
|
37
|
-
..
|
|
32
|
+
.. admonition:: Example:
|
|
38
33
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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.
|
|
43
40
|
"""
|
|
44
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
45
|
@override
|
|
46
46
|
def __init__(
|
|
47
47
|
self,
|
|
48
48
|
credential,
|
|
49
|
-
azure_ai_project
|
|
50
|
-
eval_last_turn: bool = False,
|
|
49
|
+
azure_ai_project,
|
|
51
50
|
):
|
|
52
51
|
super().__init__(
|
|
53
52
|
eval_metric=EvaluationMetrics.PROTECTED_MATERIAL,
|
|
54
53
|
azure_ai_project=azure_ai_project,
|
|
55
54
|
credential=credential,
|
|
56
|
-
eval_last_turn=eval_last_turn,
|
|
57
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)
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# ---------------------------------------------------------
|
|
4
4
|
|
|
5
5
|
from concurrent.futures import as_completed
|
|
6
|
-
from typing import Callable, Dict, List
|
|
6
|
+
from typing import Callable, Dict, List, Union
|
|
7
7
|
|
|
8
8
|
from promptflow.tracing import ThreadPoolExecutorWithContext as ThreadPoolExecutor
|
|
9
9
|
|
|
@@ -22,39 +22,33 @@ class QAEvaluator:
|
|
|
22
22
|
:param model_config: Configuration for the Azure OpenAI model.
|
|
23
23
|
:type model_config: Union[~azure.ai.evaluation.AzureOpenAIModelConfiguration,
|
|
24
24
|
~azure.ai.evaluation.OpenAIModelConfiguration]
|
|
25
|
-
:return: A
|
|
26
|
-
:
|
|
25
|
+
:return: A callable class that evaluates and generates metrics for "question-answering" scenario.
|
|
26
|
+
:param kwargs: Additional arguments to pass to the evaluator.
|
|
27
|
+
:type kwargs: Any
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
.. admonition:: Example:
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
.. literalinclude:: ../samples/evaluation_samples_evaluate.py
|
|
32
|
+
:start-after: [START qa_evaluator]
|
|
33
|
+
:end-before: [END qa_evaluator]
|
|
34
|
+
:language: python
|
|
35
|
+
:dedent: 8
|
|
36
|
+
:caption: Initialize and call a QAEvaluator.
|
|
31
37
|
|
|
32
|
-
|
|
33
|
-
result = qa_eval(
|
|
34
|
-
query="Tokyo is the capital of which country?",
|
|
35
|
-
response="Japan",
|
|
36
|
-
context="Tokyo is the capital of Japan.",
|
|
37
|
-
ground_truth="Japan"
|
|
38
|
-
)
|
|
38
|
+
.. note::
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
{
|
|
45
|
-
"gpt_groundedness": 3.5,
|
|
46
|
-
"gpt_relevance": 4.0,
|
|
47
|
-
"gpt_coherence": 1.5,
|
|
48
|
-
"gpt_fluency": 4.0,
|
|
49
|
-
"gpt_similarity": 3.0,
|
|
50
|
-
"f1_score": 0.42
|
|
51
|
-
}
|
|
40
|
+
To align with our support of a diverse set of models, keys without the `gpt_` prefix has been added.
|
|
41
|
+
To maintain backwards compatibility, the old keys with the `gpt_` prefix are still be present in the output;
|
|
42
|
+
however, it is recommended to use the new keys moving forward as the old keys will be deprecated in the future.
|
|
52
43
|
"""
|
|
53
44
|
|
|
54
|
-
|
|
55
|
-
|
|
45
|
+
id = "qa"
|
|
46
|
+
"""Evaluator identifier, experimental and to be used only with evaluation in cloud."""
|
|
47
|
+
|
|
48
|
+
def __init__(self, model_config, **kwargs):
|
|
49
|
+
self._parallel = kwargs.pop("_parallel", False)
|
|
56
50
|
|
|
57
|
-
self._evaluators: List[Callable[..., Dict[str, float]]] = [
|
|
51
|
+
self._evaluators: List[Union[Callable[..., Dict[str, Union[str, float]]], Callable[..., Dict[str, float]]]] = [
|
|
58
52
|
GroundednessEvaluator(model_config),
|
|
59
53
|
RelevanceEvaluator(model_config),
|
|
60
54
|
CoherenceEvaluator(model_config),
|
|
@@ -75,12 +69,10 @@ class QAEvaluator:
|
|
|
75
69
|
:paramtype context: str
|
|
76
70
|
:keyword ground_truth: The ground truth to be evaluated.
|
|
77
71
|
:paramtype ground_truth: str
|
|
78
|
-
:keyword parallel: Whether to evaluate in parallel. Defaults to True.
|
|
79
|
-
:paramtype parallel: bool
|
|
80
72
|
:return: The scores for QA scenario.
|
|
81
|
-
:rtype: Dict[str, float]
|
|
73
|
+
:rtype: Dict[str, Union[str, float]]
|
|
82
74
|
"""
|
|
83
|
-
results: Dict[str, float] = {}
|
|
75
|
+
results: Dict[str, Union[str, float]] = {}
|
|
84
76
|
if self._parallel:
|
|
85
77
|
with ThreadPoolExecutor() as executor:
|
|
86
78
|
futures = {
|