azure-ai-evaluation 1.0.1__py3-none-any.whl → 1.13.5__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.
Potentially problematic release.
This version of azure-ai-evaluation might be problematic. Click here for more details.
- azure/ai/evaluation/__init__.py +85 -14
- azure/ai/evaluation/_aoai/__init__.py +10 -0
- azure/ai/evaluation/_aoai/aoai_grader.py +140 -0
- azure/ai/evaluation/_aoai/label_grader.py +68 -0
- azure/ai/evaluation/_aoai/python_grader.py +86 -0
- azure/ai/evaluation/_aoai/score_model_grader.py +94 -0
- azure/ai/evaluation/_aoai/string_check_grader.py +66 -0
- azure/ai/evaluation/_aoai/text_similarity_grader.py +80 -0
- azure/ai/evaluation/_azure/__init__.py +3 -0
- azure/ai/evaluation/_azure/_clients.py +204 -0
- azure/ai/evaluation/_azure/_envs.py +207 -0
- azure/ai/evaluation/_azure/_models.py +227 -0
- azure/ai/evaluation/_azure/_token_manager.py +129 -0
- azure/ai/evaluation/_common/__init__.py +9 -1
- azure/ai/evaluation/_common/constants.py +124 -2
- azure/ai/evaluation/_common/evaluation_onedp_client.py +169 -0
- azure/ai/evaluation/_common/onedp/__init__.py +32 -0
- azure/ai/evaluation/_common/onedp/_client.py +166 -0
- azure/ai/evaluation/_common/onedp/_configuration.py +72 -0
- azure/ai/evaluation/_common/onedp/_model_base.py +1232 -0
- azure/ai/evaluation/_common/onedp/_patch.py +21 -0
- azure/ai/evaluation/_common/onedp/_serialization.py +2032 -0
- azure/ai/evaluation/_common/onedp/_types.py +21 -0
- azure/ai/evaluation/_common/onedp/_utils/__init__.py +6 -0
- azure/ai/evaluation/_common/onedp/_utils/model_base.py +1232 -0
- azure/ai/evaluation/_common/onedp/_utils/serialization.py +2032 -0
- azure/ai/evaluation/_common/onedp/_validation.py +66 -0
- azure/ai/evaluation/_common/onedp/_vendor.py +50 -0
- azure/ai/evaluation/_common/onedp/_version.py +9 -0
- azure/ai/evaluation/_common/onedp/aio/__init__.py +29 -0
- azure/ai/evaluation/_common/onedp/aio/_client.py +168 -0
- azure/ai/evaluation/_common/onedp/aio/_configuration.py +72 -0
- azure/ai/evaluation/_common/onedp/aio/_patch.py +21 -0
- azure/ai/evaluation/_common/onedp/aio/operations/__init__.py +49 -0
- azure/ai/evaluation/_common/onedp/aio/operations/_operations.py +7143 -0
- azure/ai/evaluation/_common/onedp/aio/operations/_patch.py +21 -0
- azure/ai/evaluation/_common/onedp/models/__init__.py +358 -0
- azure/ai/evaluation/_common/onedp/models/_enums.py +447 -0
- azure/ai/evaluation/_common/onedp/models/_models.py +5963 -0
- azure/ai/evaluation/_common/onedp/models/_patch.py +21 -0
- azure/ai/evaluation/_common/onedp/operations/__init__.py +49 -0
- azure/ai/evaluation/_common/onedp/operations/_operations.py +8951 -0
- azure/ai/evaluation/_common/onedp/operations/_patch.py +21 -0
- azure/ai/evaluation/_common/onedp/py.typed +1 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/__init__.py +1 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/aio/__init__.py +1 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/aio/operations/__init__.py +25 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/aio/operations/_operations.py +34 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/aio/operations/_patch.py +20 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/__init__.py +1 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/aio/__init__.py +1 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/aio/operations/__init__.py +22 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/aio/operations/_operations.py +29 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/aio/operations/_patch.py +20 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/operations/__init__.py +22 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/operations/_operations.py +29 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/operations/_patch.py +20 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/operations/__init__.py +25 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/operations/_operations.py +34 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/operations/_patch.py +20 -0
- azure/ai/evaluation/_common/rai_service.py +578 -69
- azure/ai/evaluation/_common/raiclient/__init__.py +34 -0
- azure/ai/evaluation/_common/raiclient/_client.py +128 -0
- azure/ai/evaluation/_common/raiclient/_configuration.py +87 -0
- azure/ai/evaluation/_common/raiclient/_model_base.py +1235 -0
- azure/ai/evaluation/_common/raiclient/_patch.py +20 -0
- azure/ai/evaluation/_common/raiclient/_serialization.py +2050 -0
- azure/ai/evaluation/_common/raiclient/_version.py +9 -0
- azure/ai/evaluation/_common/raiclient/aio/__init__.py +29 -0
- azure/ai/evaluation/_common/raiclient/aio/_client.py +130 -0
- azure/ai/evaluation/_common/raiclient/aio/_configuration.py +87 -0
- azure/ai/evaluation/_common/raiclient/aio/_patch.py +20 -0
- azure/ai/evaluation/_common/raiclient/aio/operations/__init__.py +25 -0
- azure/ai/evaluation/_common/raiclient/aio/operations/_operations.py +981 -0
- azure/ai/evaluation/_common/raiclient/aio/operations/_patch.py +20 -0
- azure/ai/evaluation/_common/raiclient/models/__init__.py +60 -0
- azure/ai/evaluation/_common/raiclient/models/_enums.py +18 -0
- azure/ai/evaluation/_common/raiclient/models/_models.py +651 -0
- azure/ai/evaluation/_common/raiclient/models/_patch.py +20 -0
- azure/ai/evaluation/_common/raiclient/operations/__init__.py +25 -0
- azure/ai/evaluation/_common/raiclient/operations/_operations.py +1238 -0
- azure/ai/evaluation/_common/raiclient/operations/_patch.py +20 -0
- azure/ai/evaluation/_common/raiclient/py.typed +1 -0
- azure/ai/evaluation/_common/utils.py +505 -27
- azure/ai/evaluation/_constants.py +147 -0
- azure/ai/evaluation/_converters/__init__.py +3 -0
- azure/ai/evaluation/_converters/_ai_services.py +899 -0
- azure/ai/evaluation/_converters/_models.py +467 -0
- azure/ai/evaluation/_converters/_sk_services.py +495 -0
- azure/ai/evaluation/_eval_mapping.py +87 -0
- azure/ai/evaluation/_evaluate/_batch_run/__init__.py +10 -2
- azure/ai/evaluation/_evaluate/_batch_run/_run_submitter_client.py +176 -0
- azure/ai/evaluation/_evaluate/_batch_run/batch_clients.py +82 -0
- azure/ai/evaluation/_evaluate/_batch_run/code_client.py +18 -12
- azure/ai/evaluation/_evaluate/_batch_run/eval_run_context.py +19 -6
- azure/ai/evaluation/_evaluate/_batch_run/proxy_client.py +47 -22
- azure/ai/evaluation/_evaluate/_batch_run/target_run_context.py +18 -2
- azure/ai/evaluation/_evaluate/_eval_run.py +32 -46
- azure/ai/evaluation/_evaluate/_evaluate.py +1809 -142
- azure/ai/evaluation/_evaluate/_evaluate_aoai.py +992 -0
- azure/ai/evaluation/_evaluate/_telemetry/__init__.py +5 -90
- azure/ai/evaluation/_evaluate/_utils.py +237 -42
- azure/ai/evaluation/_evaluator_definition.py +76 -0
- azure/ai/evaluation/_evaluators/_bleu/_bleu.py +80 -28
- azure/ai/evaluation/_evaluators/_code_vulnerability/__init__.py +5 -0
- azure/ai/evaluation/_evaluators/_code_vulnerability/_code_vulnerability.py +119 -0
- azure/ai/evaluation/_evaluators/_coherence/_coherence.py +40 -4
- azure/ai/evaluation/_evaluators/_common/__init__.py +2 -0
- azure/ai/evaluation/_evaluators/_common/_base_eval.py +430 -29
- azure/ai/evaluation/_evaluators/_common/_base_multi_eval.py +63 -0
- azure/ai/evaluation/_evaluators/_common/_base_prompty_eval.py +269 -12
- azure/ai/evaluation/_evaluators/_common/_base_rai_svc_eval.py +74 -9
- azure/ai/evaluation/_evaluators/_common/_conversation_aggregators.py +49 -0
- azure/ai/evaluation/_evaluators/_content_safety/_content_safety.py +73 -53
- azure/ai/evaluation/_evaluators/_content_safety/_hate_unfairness.py +35 -5
- azure/ai/evaluation/_evaluators/_content_safety/_self_harm.py +26 -5
- azure/ai/evaluation/_evaluators/_content_safety/_sexual.py +35 -5
- azure/ai/evaluation/_evaluators/_content_safety/_violence.py +34 -4
- azure/ai/evaluation/_evaluators/_document_retrieval/__init__.py +7 -0
- azure/ai/evaluation/_evaluators/_document_retrieval/_document_retrieval.py +442 -0
- azure/ai/evaluation/_evaluators/_eci/_eci.py +6 -3
- azure/ai/evaluation/_evaluators/_f1_score/_f1_score.py +97 -70
- azure/ai/evaluation/_evaluators/_fluency/_fluency.py +39 -3
- azure/ai/evaluation/_evaluators/_gleu/_gleu.py +80 -25
- azure/ai/evaluation/_evaluators/_groundedness/_groundedness.py +230 -20
- azure/ai/evaluation/_evaluators/_groundedness/groundedness_with_query.prompty +30 -29
- azure/ai/evaluation/_evaluators/_groundedness/groundedness_without_query.prompty +19 -14
- azure/ai/evaluation/_evaluators/_intent_resolution/__init__.py +7 -0
- azure/ai/evaluation/_evaluators/_intent_resolution/_intent_resolution.py +196 -0
- azure/ai/evaluation/_evaluators/_intent_resolution/intent_resolution.prompty +275 -0
- azure/ai/evaluation/_evaluators/_meteor/_meteor.py +89 -36
- azure/ai/evaluation/_evaluators/_protected_material/_protected_material.py +22 -4
- azure/ai/evaluation/_evaluators/_qa/_qa.py +94 -35
- azure/ai/evaluation/_evaluators/_relevance/_relevance.py +100 -4
- azure/ai/evaluation/_evaluators/_relevance/relevance.prompty +154 -56
- azure/ai/evaluation/_evaluators/_response_completeness/__init__.py +7 -0
- azure/ai/evaluation/_evaluators/_response_completeness/_response_completeness.py +202 -0
- azure/ai/evaluation/_evaluators/_response_completeness/response_completeness.prompty +84 -0
- azure/ai/evaluation/_evaluators/_retrieval/_retrieval.py +39 -3
- azure/ai/evaluation/_evaluators/_rouge/_rouge.py +166 -26
- azure/ai/evaluation/_evaluators/_service_groundedness/_service_groundedness.py +38 -7
- azure/ai/evaluation/_evaluators/_similarity/_similarity.py +81 -85
- azure/ai/evaluation/_evaluators/_task_adherence/__init__.py +7 -0
- azure/ai/evaluation/_evaluators/_task_adherence/_task_adherence.py +226 -0
- azure/ai/evaluation/_evaluators/_task_adherence/task_adherence.prompty +101 -0
- azure/ai/evaluation/_evaluators/_task_completion/__init__.py +7 -0
- azure/ai/evaluation/_evaluators/_task_completion/_task_completion.py +177 -0
- azure/ai/evaluation/_evaluators/_task_completion/task_completion.prompty +220 -0
- azure/ai/evaluation/_evaluators/_task_navigation_efficiency/__init__.py +7 -0
- azure/ai/evaluation/_evaluators/_task_navigation_efficiency/_task_navigation_efficiency.py +384 -0
- azure/ai/evaluation/_evaluators/_tool_call_accuracy/__init__.py +9 -0
- azure/ai/evaluation/_evaluators/_tool_call_accuracy/_tool_call_accuracy.py +298 -0
- azure/ai/evaluation/_evaluators/_tool_call_accuracy/tool_call_accuracy.prompty +166 -0
- azure/ai/evaluation/_evaluators/_tool_call_success/__init__.py +7 -0
- azure/ai/evaluation/_evaluators/_tool_call_success/_tool_call_success.py +306 -0
- azure/ai/evaluation/_evaluators/_tool_call_success/tool_call_success.prompty +321 -0
- azure/ai/evaluation/_evaluators/_tool_input_accuracy/__init__.py +9 -0
- azure/ai/evaluation/_evaluators/_tool_input_accuracy/_tool_input_accuracy.py +263 -0
- azure/ai/evaluation/_evaluators/_tool_input_accuracy/tool_input_accuracy.prompty +76 -0
- azure/ai/evaluation/_evaluators/_tool_output_utilization/__init__.py +7 -0
- azure/ai/evaluation/_evaluators/_tool_output_utilization/_tool_output_utilization.py +225 -0
- azure/ai/evaluation/_evaluators/_tool_output_utilization/tool_output_utilization.prompty +221 -0
- azure/ai/evaluation/_evaluators/_tool_selection/__init__.py +9 -0
- azure/ai/evaluation/_evaluators/_tool_selection/_tool_selection.py +266 -0
- azure/ai/evaluation/_evaluators/_tool_selection/tool_selection.prompty +104 -0
- azure/ai/evaluation/_evaluators/_ungrounded_attributes/__init__.py +5 -0
- azure/ai/evaluation/_evaluators/_ungrounded_attributes/_ungrounded_attributes.py +102 -0
- azure/ai/evaluation/_evaluators/_xpia/xpia.py +20 -4
- azure/ai/evaluation/_exceptions.py +24 -1
- azure/ai/evaluation/_http_utils.py +7 -5
- azure/ai/evaluation/_legacy/__init__.py +3 -0
- azure/ai/evaluation/_legacy/_adapters/__init__.py +7 -0
- azure/ai/evaluation/_legacy/_adapters/_check.py +17 -0
- azure/ai/evaluation/_legacy/_adapters/_configuration.py +45 -0
- azure/ai/evaluation/_legacy/_adapters/_constants.py +10 -0
- azure/ai/evaluation/_legacy/_adapters/_errors.py +29 -0
- azure/ai/evaluation/_legacy/_adapters/_flows.py +28 -0
- azure/ai/evaluation/_legacy/_adapters/_service.py +16 -0
- azure/ai/evaluation/_legacy/_adapters/client.py +51 -0
- azure/ai/evaluation/_legacy/_adapters/entities.py +26 -0
- azure/ai/evaluation/_legacy/_adapters/tracing.py +28 -0
- azure/ai/evaluation/_legacy/_adapters/types.py +15 -0
- azure/ai/evaluation/_legacy/_adapters/utils.py +31 -0
- azure/ai/evaluation/_legacy/_batch_engine/__init__.py +9 -0
- azure/ai/evaluation/_legacy/_batch_engine/_config.py +48 -0
- azure/ai/evaluation/_legacy/_batch_engine/_engine.py +477 -0
- azure/ai/evaluation/_legacy/_batch_engine/_exceptions.py +88 -0
- azure/ai/evaluation/_legacy/_batch_engine/_openai_injector.py +132 -0
- azure/ai/evaluation/_legacy/_batch_engine/_result.py +107 -0
- azure/ai/evaluation/_legacy/_batch_engine/_run.py +127 -0
- azure/ai/evaluation/_legacy/_batch_engine/_run_storage.py +128 -0
- azure/ai/evaluation/_legacy/_batch_engine/_run_submitter.py +262 -0
- azure/ai/evaluation/_legacy/_batch_engine/_status.py +25 -0
- azure/ai/evaluation/_legacy/_batch_engine/_trace.py +97 -0
- azure/ai/evaluation/_legacy/_batch_engine/_utils.py +97 -0
- azure/ai/evaluation/_legacy/_batch_engine/_utils_deprecated.py +131 -0
- azure/ai/evaluation/_legacy/_common/__init__.py +3 -0
- azure/ai/evaluation/_legacy/_common/_async_token_provider.py +117 -0
- azure/ai/evaluation/_legacy/_common/_logging.py +292 -0
- azure/ai/evaluation/_legacy/_common/_thread_pool_executor_with_context.py +17 -0
- azure/ai/evaluation/_legacy/prompty/__init__.py +36 -0
- azure/ai/evaluation/_legacy/prompty/_connection.py +119 -0
- azure/ai/evaluation/_legacy/prompty/_exceptions.py +139 -0
- azure/ai/evaluation/_legacy/prompty/_prompty.py +430 -0
- azure/ai/evaluation/_legacy/prompty/_utils.py +663 -0
- azure/ai/evaluation/_legacy/prompty/_yaml_utils.py +99 -0
- azure/ai/evaluation/_model_configurations.py +26 -0
- azure/ai/evaluation/_safety_evaluation/__init__.py +3 -0
- azure/ai/evaluation/_safety_evaluation/_generated_rai_client.py +0 -0
- azure/ai/evaluation/_safety_evaluation/_safety_evaluation.py +917 -0
- azure/ai/evaluation/_user_agent.py +32 -1
- azure/ai/evaluation/_vendor/rouge_score/rouge_scorer.py +0 -4
- azure/ai/evaluation/_vendor/rouge_score/scoring.py +0 -4
- azure/ai/evaluation/_vendor/rouge_score/tokenize.py +0 -4
- azure/ai/evaluation/_version.py +2 -1
- azure/ai/evaluation/red_team/__init__.py +22 -0
- azure/ai/evaluation/red_team/_agent/__init__.py +3 -0
- azure/ai/evaluation/red_team/_agent/_agent_functions.py +261 -0
- azure/ai/evaluation/red_team/_agent/_agent_tools.py +461 -0
- azure/ai/evaluation/red_team/_agent/_agent_utils.py +89 -0
- azure/ai/evaluation/red_team/_agent/_semantic_kernel_plugin.py +228 -0
- azure/ai/evaluation/red_team/_attack_objective_generator.py +268 -0
- azure/ai/evaluation/red_team/_attack_strategy.py +49 -0
- azure/ai/evaluation/red_team/_callback_chat_target.py +115 -0
- azure/ai/evaluation/red_team/_default_converter.py +21 -0
- azure/ai/evaluation/red_team/_evaluation_processor.py +505 -0
- azure/ai/evaluation/red_team/_mlflow_integration.py +430 -0
- azure/ai/evaluation/red_team/_orchestrator_manager.py +803 -0
- azure/ai/evaluation/red_team/_red_team.py +1717 -0
- azure/ai/evaluation/red_team/_red_team_result.py +661 -0
- azure/ai/evaluation/red_team/_result_processor.py +1708 -0
- azure/ai/evaluation/red_team/_utils/__init__.py +37 -0
- azure/ai/evaluation/red_team/_utils/_rai_service_eval_chat_target.py +128 -0
- azure/ai/evaluation/red_team/_utils/_rai_service_target.py +601 -0
- azure/ai/evaluation/red_team/_utils/_rai_service_true_false_scorer.py +114 -0
- azure/ai/evaluation/red_team/_utils/constants.py +72 -0
- azure/ai/evaluation/red_team/_utils/exception_utils.py +345 -0
- azure/ai/evaluation/red_team/_utils/file_utils.py +266 -0
- azure/ai/evaluation/red_team/_utils/formatting_utils.py +365 -0
- azure/ai/evaluation/red_team/_utils/logging_utils.py +139 -0
- azure/ai/evaluation/red_team/_utils/metric_mapping.py +73 -0
- azure/ai/evaluation/red_team/_utils/objective_utils.py +46 -0
- azure/ai/evaluation/red_team/_utils/progress_utils.py +252 -0
- azure/ai/evaluation/red_team/_utils/retry_utils.py +218 -0
- azure/ai/evaluation/red_team/_utils/strategy_utils.py +218 -0
- azure/ai/evaluation/simulator/_adversarial_scenario.py +6 -0
- azure/ai/evaluation/simulator/_adversarial_simulator.py +187 -80
- azure/ai/evaluation/simulator/_constants.py +1 -0
- azure/ai/evaluation/simulator/_conversation/__init__.py +138 -11
- azure/ai/evaluation/simulator/_conversation/_conversation.py +6 -2
- azure/ai/evaluation/simulator/_conversation/constants.py +1 -1
- azure/ai/evaluation/simulator/_direct_attack_simulator.py +37 -24
- azure/ai/evaluation/simulator/_helpers/_language_suffix_mapping.py +1 -0
- azure/ai/evaluation/simulator/_indirect_attack_simulator.py +56 -28
- azure/ai/evaluation/simulator/_model_tools/__init__.py +2 -1
- azure/ai/evaluation/simulator/_model_tools/_generated_rai_client.py +225 -0
- azure/ai/evaluation/simulator/_model_tools/_identity_manager.py +12 -10
- azure/ai/evaluation/simulator/_model_tools/_proxy_completion_model.py +100 -45
- azure/ai/evaluation/simulator/_model_tools/_rai_client.py +101 -3
- azure/ai/evaluation/simulator/_model_tools/_template_handler.py +31 -11
- azure/ai/evaluation/simulator/_model_tools/models.py +20 -17
- azure/ai/evaluation/simulator/_simulator.py +43 -19
- {azure_ai_evaluation-1.0.1.dist-info → azure_ai_evaluation-1.13.5.dist-info}/METADATA +378 -27
- azure_ai_evaluation-1.13.5.dist-info/RECORD +305 -0
- {azure_ai_evaluation-1.0.1.dist-info → azure_ai_evaluation-1.13.5.dist-info}/WHEEL +1 -1
- azure/ai/evaluation/_evaluators/_multimodal/__init__.py +0 -20
- azure/ai/evaluation/_evaluators/_multimodal/_content_safety_multimodal.py +0 -132
- azure/ai/evaluation/_evaluators/_multimodal/_content_safety_multimodal_base.py +0 -55
- azure/ai/evaluation/_evaluators/_multimodal/_hate_unfairness.py +0 -100
- azure/ai/evaluation/_evaluators/_multimodal/_protected_material.py +0 -124
- azure/ai/evaluation/_evaluators/_multimodal/_self_harm.py +0 -100
- azure/ai/evaluation/_evaluators/_multimodal/_sexual.py +0 -100
- azure/ai/evaluation/_evaluators/_multimodal/_violence.py +0 -100
- azure/ai/evaluation/simulator/_tracing.py +0 -89
- azure_ai_evaluation-1.0.1.dist-info/RECORD +0 -119
- {azure_ai_evaluation-1.0.1.dist-info → azure_ai_evaluation-1.13.5.dist-info/licenses}/NOTICE.txt +0 -0
- {azure_ai_evaluation-1.0.1.dist-info → azure_ai_evaluation-1.13.5.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
# ---------------------------------------------------------
|
|
2
2
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
3
|
# ---------------------------------------------------------
|
|
4
|
+
from contextlib import contextmanager
|
|
5
|
+
from typing import Iterator
|
|
6
|
+
|
|
4
7
|
from azure.ai.evaluation._version import VERSION
|
|
5
8
|
|
|
6
|
-
|
|
9
|
+
|
|
10
|
+
class UserAgentSingleton:
|
|
11
|
+
__BASE_USER_AGENT: str = "{}/{}".format("azure-ai-evaluation", VERSION)
|
|
12
|
+
|
|
13
|
+
@property
|
|
14
|
+
def value(self):
|
|
15
|
+
"""Get the user-agent"""
|
|
16
|
+
return self.__BASE_USER_AGENT
|
|
17
|
+
|
|
18
|
+
def __str__(self) -> str:
|
|
19
|
+
return self.value
|
|
20
|
+
|
|
21
|
+
@classmethod
|
|
22
|
+
@contextmanager
|
|
23
|
+
def add_useragent_product(cls, *product: str) -> Iterator[None]:
|
|
24
|
+
"""Appends a "product" (e.g. `name/version`) to the base user agent
|
|
25
|
+
|
|
26
|
+
:param product: User Agent products to append to the base user agent
|
|
27
|
+
|
|
28
|
+
..see-also::
|
|
29
|
+
|
|
30
|
+
`User-Agent section of RFC 9110, <https://www.rfc-editor.org/rfc/rfc9110#name-user-agent>`
|
|
31
|
+
"""
|
|
32
|
+
old_useragent = cls.__BASE_USER_AGENT
|
|
33
|
+
cls.__BASE_USER_AGENT = f"{old_useragent} {' '.join(product)}"
|
|
34
|
+
|
|
35
|
+
yield
|
|
36
|
+
|
|
37
|
+
cls.__BASE_USER_AGENT = old_useragent
|
|
@@ -32,10 +32,6 @@ ROUGE-1.5.5.pl -m -e data -n 2 -a settings.xml
|
|
|
32
32
|
In these examples settings.xml lists input files and formats.
|
|
33
33
|
"""
|
|
34
34
|
|
|
35
|
-
from __future__ import absolute_import
|
|
36
|
-
from __future__ import division
|
|
37
|
-
from __future__ import print_function
|
|
38
|
-
|
|
39
35
|
import collections
|
|
40
36
|
import re
|
|
41
37
|
|
|
@@ -21,10 +21,6 @@ Aggregation functions use bootstrap resampling to compute confidence intervals
|
|
|
21
21
|
as per the original ROUGE perl implementation.
|
|
22
22
|
"""
|
|
23
23
|
|
|
24
|
-
from __future__ import absolute_import
|
|
25
|
-
from __future__ import division
|
|
26
|
-
from __future__ import print_function
|
|
27
|
-
|
|
28
24
|
import abc
|
|
29
25
|
import collections
|
|
30
26
|
from typing import Dict
|
azure/ai/evaluation/_version.py
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# ---------------------------------------------------------
|
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
# ---------------------------------------------------------
|
|
4
|
+
|
|
5
|
+
try:
|
|
6
|
+
from ._red_team import RedTeam
|
|
7
|
+
from ._attack_strategy import AttackStrategy
|
|
8
|
+
from ._attack_objective_generator import RiskCategory, SupportedLanguages
|
|
9
|
+
from ._red_team_result import RedTeamResult
|
|
10
|
+
except ImportError:
|
|
11
|
+
raise ImportError(
|
|
12
|
+
"Could not import Pyrit. Please install the dependency with `pip install azure-ai-evaluation[redteam]`."
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"RedTeam",
|
|
18
|
+
"AttackStrategy",
|
|
19
|
+
"RiskCategory",
|
|
20
|
+
"RedTeamResult",
|
|
21
|
+
"SupportedLanguages",
|
|
22
|
+
]
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
# ------------------------------------
|
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
# ------------------------------------
|
|
4
|
+
|
|
5
|
+
"""
|
|
6
|
+
Red Team Tools as Functions for Azure AI Agent
|
|
7
|
+
This module provides functions that can be used as tools in Azure AI Agent for red teaming purposes.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
import asyncio
|
|
12
|
+
from typing import Any, Callable, Set, Optional
|
|
13
|
+
from azure.identity import DefaultAzureCredential
|
|
14
|
+
from azure.ai.evaluation.red_team._agent import RedTeamToolProvider
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# Initialize the credential and tool provider (will be created when first needed)
|
|
18
|
+
credential = None
|
|
19
|
+
tool_provider = None
|
|
20
|
+
azure_ai_project = None
|
|
21
|
+
target_function = None
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _get_tool_provider() -> RedTeamToolProvider:
|
|
25
|
+
"""Get or create the RedTeamToolProvider instance."""
|
|
26
|
+
global credential, tool_provider, azure_ai_project
|
|
27
|
+
if tool_provider is None:
|
|
28
|
+
credential = DefaultAzureCredential()
|
|
29
|
+
tool_provider = RedTeamToolProvider(
|
|
30
|
+
azure_ai_project=azure_ai_project,
|
|
31
|
+
credential=credential,
|
|
32
|
+
application_scenario="A customer service chatbot for a retail website", # Optional context
|
|
33
|
+
)
|
|
34
|
+
return tool_provider
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
# Dictionary to store fetched prompts for reference
|
|
38
|
+
fetched_prompts = {}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def red_team_fetch_harmful_prompt(
|
|
42
|
+
risk_category: str, strategy: str = "baseline", convert_with_strategy: Optional[str] = None
|
|
43
|
+
) -> str:
|
|
44
|
+
"""
|
|
45
|
+
Fetch a harmful prompt for a specific risk category to test content filters.
|
|
46
|
+
|
|
47
|
+
This function retrieves a prompt that could potentially trigger content filters
|
|
48
|
+
and can be used for red teaming AI systems.
|
|
49
|
+
|
|
50
|
+
:param risk_category (str): The risk category to get a harmful prompt for (e.g., 'violence', 'hate_unfairness', 'sexual', 'self_harm').
|
|
51
|
+
:param strategy (str, optional): The attack strategy to use (e.g., 'baseline', 'jailbreak'). Defaults to 'baseline'.
|
|
52
|
+
:param convert_with_strategy (Optional[str], optional): Optional strategy to convert the prompt (e.g., 'morse_converter', 'binary_converter'). Defaults to None.
|
|
53
|
+
:return: A JSON string containing the harmful prompt and related metadata.
|
|
54
|
+
:rtype: str
|
|
55
|
+
"""
|
|
56
|
+
provider = _get_tool_provider()
|
|
57
|
+
|
|
58
|
+
# Run the async method in a new event loop
|
|
59
|
+
result = asyncio.run(
|
|
60
|
+
provider.fetch_harmful_prompt(
|
|
61
|
+
risk_category_text=risk_category, strategy=strategy, convert_with_strategy=convert_with_strategy
|
|
62
|
+
)
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
# Store the prompt for later conversion if successful
|
|
66
|
+
if result["status"] == "success" and "prompt_id" in result:
|
|
67
|
+
prompt_id = result["prompt_id"]
|
|
68
|
+
if "prompt" in result:
|
|
69
|
+
fetched_prompts[prompt_id] = result["prompt"]
|
|
70
|
+
|
|
71
|
+
return json.dumps(result)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def red_team_convert_prompt(prompt_or_id: str, strategy: str) -> str:
|
|
75
|
+
"""
|
|
76
|
+
Convert a prompt or a previously fetched prompt ID using a specified strategy.
|
|
77
|
+
|
|
78
|
+
This function can be used to transform prompts in ways that might bypass content filters
|
|
79
|
+
for testing AI system defenses.
|
|
80
|
+
|
|
81
|
+
:param prompt_or_id (str): Either a prompt text or a prompt ID from a previous fetch_harmful_prompt call.
|
|
82
|
+
:param strategy (str): The strategy to use for conversion (e.g., 'morse_converter', 'binary_converter', 'base64_converter').
|
|
83
|
+
:return: A JSON string containing the original and converted prompt.
|
|
84
|
+
:rtype: str
|
|
85
|
+
"""
|
|
86
|
+
provider = _get_tool_provider()
|
|
87
|
+
|
|
88
|
+
# Check if input is a prompt ID we have stored
|
|
89
|
+
if prompt_or_id in fetched_prompts:
|
|
90
|
+
# Update the provider's cache
|
|
91
|
+
provider._fetched_prompts[prompt_or_id] = fetched_prompts[prompt_or_id]
|
|
92
|
+
|
|
93
|
+
# Run the async method in a new event loop
|
|
94
|
+
result = asyncio.run(provider.convert_prompt(prompt_or_id=prompt_or_id, strategy=strategy))
|
|
95
|
+
|
|
96
|
+
return json.dumps(result)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def red_team_unified(category: str, strategy: Optional[str] = None) -> str:
|
|
100
|
+
"""
|
|
101
|
+
Get a harmful prompt for a specific risk category and optionally convert it.
|
|
102
|
+
|
|
103
|
+
This function combines fetching and converting harmful prompts in one call,
|
|
104
|
+
making it easier to test AI system defenses.
|
|
105
|
+
|
|
106
|
+
:param category (str): The risk category to get a harmful prompt for (e.g., 'violence', 'hate_unfairness', 'sexual', 'self_harm').
|
|
107
|
+
:param strategy (Optional[str], optional): Optional strategy to convert the prompt (e.g., 'morse_converter', 'binary_converter'). Defaults to None.
|
|
108
|
+
:return: A JSON string containing the harmful prompt and related metadata.
|
|
109
|
+
:rtype: str
|
|
110
|
+
"""
|
|
111
|
+
provider = _get_tool_provider()
|
|
112
|
+
|
|
113
|
+
# Run the async method in a new event loop
|
|
114
|
+
result = asyncio.run(provider.red_team(category=category, strategy=strategy))
|
|
115
|
+
|
|
116
|
+
# Store the prompt for later conversion if it's a success and we didn't convert it
|
|
117
|
+
if result["status"] == "success":
|
|
118
|
+
if "prompt_id" in result and "prompt" in result:
|
|
119
|
+
prompt_id = result["prompt_id"]
|
|
120
|
+
fetched_prompts[prompt_id] = result["prompt"]
|
|
121
|
+
|
|
122
|
+
return json.dumps(result)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def red_team_get_available_strategies() -> str:
|
|
126
|
+
"""
|
|
127
|
+
Get a list of all available prompt conversion strategies.
|
|
128
|
+
|
|
129
|
+
This function lists all the strategies that can be used to convert prompts
|
|
130
|
+
for red teaming purposes.
|
|
131
|
+
|
|
132
|
+
:return: A JSON string containing a list of available conversion strategies.
|
|
133
|
+
:rtype: str
|
|
134
|
+
"""
|
|
135
|
+
provider = _get_tool_provider()
|
|
136
|
+
strategies = provider.get_available_strategies()
|
|
137
|
+
|
|
138
|
+
return json.dumps({"status": "success", "available_strategies": strategies})
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def red_team_explain_purpose() -> str:
|
|
142
|
+
"""
|
|
143
|
+
Explain the purpose and responsible use of red teaming tools.
|
|
144
|
+
|
|
145
|
+
This function provides information about the ethical use of red teaming tools
|
|
146
|
+
and their purpose in improving AI system safety.
|
|
147
|
+
|
|
148
|
+
:return: A JSON string containing information about responsible use of red teaming tools.
|
|
149
|
+
:rtype: str
|
|
150
|
+
"""
|
|
151
|
+
explanation = {
|
|
152
|
+
"purpose": "Red teaming tools are designed to test AI systems for vulnerabilities and safety issues.",
|
|
153
|
+
"responsible_use": [
|
|
154
|
+
"Only use these tools on systems you have permission to test.",
|
|
155
|
+
"Use the results to improve system safety and robustness.",
|
|
156
|
+
"Do not use these tools to cause harm or bypass legitimate safety measures in production systems.",
|
|
157
|
+
],
|
|
158
|
+
"risk_categories": {
|
|
159
|
+
"violence": "Content related to physical harm, weapons, or dangerous activities",
|
|
160
|
+
"hate_unfairness": "Content related to discrimination, bias, or prejudice",
|
|
161
|
+
"sexual": "Explicit sexual content",
|
|
162
|
+
"self_harm": "Content related to suicide, self-injury, or harmful behaviors",
|
|
163
|
+
},
|
|
164
|
+
"conversion_strategies": "Various encoding and obfuscation methods to test if harmful content can bypass detection",
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return json.dumps(explanation)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def red_team_send_to_target(prompt: str) -> str:
|
|
171
|
+
"""
|
|
172
|
+
Send a prompt to the target function (e.g., call_ollama) and return the response.
|
|
173
|
+
|
|
174
|
+
This function allows sending prompts to an external model or service for
|
|
175
|
+
evaluation.
|
|
176
|
+
|
|
177
|
+
:param prompt (str): The prompt text to send to the target function.
|
|
178
|
+
:return: A JSON string containing the response from the target function.
|
|
179
|
+
:rtype: str
|
|
180
|
+
"""
|
|
181
|
+
global target_function
|
|
182
|
+
|
|
183
|
+
if target_function is None:
|
|
184
|
+
return json.dumps(
|
|
185
|
+
{
|
|
186
|
+
"status": "error",
|
|
187
|
+
"message": "Target function not initialized. Make sure to pass a target_func to initialize_tool_provider.",
|
|
188
|
+
}
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
try:
|
|
192
|
+
# Call the target function with the prompt
|
|
193
|
+
response = target_function(prompt)
|
|
194
|
+
|
|
195
|
+
return json.dumps({"status": "success", "prompt": prompt, "response": response})
|
|
196
|
+
except Exception as e:
|
|
197
|
+
return json.dumps({"status": "error", "message": f"Error calling target function: {str(e)}", "prompt": prompt})
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
# Example User Input for Each Function
|
|
201
|
+
# 1. Red Team Fetch Harmful Prompt
|
|
202
|
+
# User Input: "Fetch a harmful prompt in the 'violence' category."
|
|
203
|
+
# User Input: "Fetch a harmful prompt in the 'hate_unfairness' category with a 'jailbreak' strategy."
|
|
204
|
+
# User Input: "Fetch a harmful prompt in the 'self_harm' category and convert it with 'base64_converter'."
|
|
205
|
+
|
|
206
|
+
# 2. Red Team Convert Prompt
|
|
207
|
+
# User Input: "Convert this prompt 'prompt_12345678' using the 'binary_converter' strategy."
|
|
208
|
+
# User Input: "Convert the text 'This is a test prompt' using the 'morse_converter' strategy."
|
|
209
|
+
|
|
210
|
+
# 3. Red Team Unified
|
|
211
|
+
# User Input: "Get a harmful prompt in the 'sexual' category."
|
|
212
|
+
# User Input: "Get a harmful prompt in the 'violence' category and convert it with 'leetspeak_converter'."
|
|
213
|
+
|
|
214
|
+
# 4. Red Team Get Available Strategies
|
|
215
|
+
# User Input: "What conversion strategies are available for red teaming?"
|
|
216
|
+
|
|
217
|
+
# 5. Red Team Explain Purpose
|
|
218
|
+
# User Input: "What is the purpose of red teaming tools and how should they be used responsibly?"
|
|
219
|
+
|
|
220
|
+
# Statically defined user functions for fast reference
|
|
221
|
+
user_functions: Set[Callable[..., Any]] = {
|
|
222
|
+
red_team_fetch_harmful_prompt,
|
|
223
|
+
red_team_convert_prompt,
|
|
224
|
+
red_team_unified,
|
|
225
|
+
red_team_get_available_strategies,
|
|
226
|
+
red_team_explain_purpose,
|
|
227
|
+
red_team_send_to_target,
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def initialize_tool_provider(
|
|
232
|
+
projects_connection_string: str,
|
|
233
|
+
target_func: Optional[Callable[[str], str]] = None,
|
|
234
|
+
) -> Set[Callable[..., Any]]:
|
|
235
|
+
"""
|
|
236
|
+
Initialize the RedTeamToolProvider with the Azure AI project and credential.
|
|
237
|
+
This function is called when the module is imported.
|
|
238
|
+
|
|
239
|
+
:param projects_connection_string: The Azure AI project connection string.
|
|
240
|
+
:param target_func: A function that takes a string prompt and returns a string response.
|
|
241
|
+
:return: A set of callable functions that can be used as tools.
|
|
242
|
+
"""
|
|
243
|
+
# projects_connection_string is in the format: connection_string;subscription_id;resource_group;project_name
|
|
244
|
+
# parse it to a dictionary called azure_ai_project
|
|
245
|
+
global azure_ai_project, credential, tool_provider, target_function
|
|
246
|
+
|
|
247
|
+
# Store the target function for later use
|
|
248
|
+
if target_func is not None:
|
|
249
|
+
globals()["target_function"] = target_func
|
|
250
|
+
azure_ai_project = {
|
|
251
|
+
"subscription_id": projects_connection_string.split(";")[1],
|
|
252
|
+
"resource_group_name": projects_connection_string.split(";")[2],
|
|
253
|
+
"project_name": projects_connection_string.split(";")[3],
|
|
254
|
+
}
|
|
255
|
+
if not credential:
|
|
256
|
+
credential = DefaultAzureCredential()
|
|
257
|
+
tool_provider = RedTeamToolProvider(
|
|
258
|
+
azure_ai_project=azure_ai_project,
|
|
259
|
+
credential=credential,
|
|
260
|
+
)
|
|
261
|
+
return user_functions
|