|
1 | 1 | # ---------------------------------------------------------
|
2 | 2 | # Copyright (c) Microsoft Corporation. All rights reserved.
|
3 | 3 | # ---------------------------------------------------------
|
| 4 | +# pylint: disable=C0301,C0114,R0913,R0903 |
4 | 5 | # noqa: E501
|
5 |
| -import functools |
6 | 6 | import logging
|
7 | 7 | from random import randint
|
8 | 8 | from typing import Callable, Optional
|
9 | 9 |
|
10 |
| -from promptflow._sdk._telemetry import ActivityType, monitor_operation |
11 |
| - |
12 | 10 | from azure.ai.evaluation._exceptions import ErrorBlame, ErrorCategory, ErrorTarget, EvaluationException
|
13 | 11 | from azure.ai.evaluation._model_configurations import AzureAIProject
|
14 | 12 | from azure.ai.evaluation.simulator import AdversarialScenario
|
15 | 13 | from azure.identity import DefaultAzureCredential
|
16 | 14 |
|
17 | 15 | from ._adversarial_simulator import AdversarialSimulator
|
18 | 16 | from ._model_tools import AdversarialTemplateHandler, ManagedIdentityAPITokenManager, RAIClient, TokenScope
|
| 17 | +from ._helpers import experimental |
19 | 18 |
|
20 | 19 | logger = logging.getLogger(__name__)
|
21 | 20 |
|
22 | 21 |
|
23 |
| -def monitor_adversarial_scenario(func) -> Callable: |
24 |
| - """Decorator to monitor adversarial scenario. |
25 |
| -
|
26 |
| - :param func: The function to be decorated. |
27 |
| - :type func: Callable |
28 |
| - :return: The decorated function. |
29 |
| - :rtype: Callable |
30 |
| - """ |
31 |
| - |
32 |
| - @functools.wraps(func) |
33 |
| - def wrapper(*args, **kwargs): |
34 |
| - scenario = str(kwargs.get("scenario", None)) |
35 |
| - max_conversation_turns = kwargs.get("max_conversation_turns", None) |
36 |
| - max_simulation_results = kwargs.get("max_simulation_results", None) |
37 |
| - decorated_func = monitor_operation( |
38 |
| - activity_name="jailbreak.adversarial.simulator.call", |
39 |
| - activity_type=ActivityType.PUBLICAPI, |
40 |
| - custom_dimensions={ |
41 |
| - "scenario": scenario, |
42 |
| - "max_conversation_turns": max_conversation_turns, |
43 |
| - "max_simulation_results": max_simulation_results, |
44 |
| - }, |
45 |
| - )(func) |
46 |
| - |
47 |
| - return decorated_func(*args, **kwargs) |
48 |
| - |
49 |
| - return wrapper |
50 |
| - |
51 |
| - |
| 22 | +@experimental |
52 | 23 | class DirectAttackSimulator:
|
53 | 24 | """
|
54 | 25 | Initialize a UPIA (user prompt injected attack) jailbreak adversarial simulator with a project scope.
|
@@ -110,7 +81,6 @@ def _ensure_service_dependencies(self):
|
110 | 81 | blame=ErrorBlame.USER_ERROR,
|
111 | 82 | )
|
112 | 83 |
|
113 |
| - # @monitor_adversarial_scenario |
114 | 84 | async def __call__(
|
115 | 85 | self,
|
116 | 86 | *,
|
|
0 commit comments