Skip to content

Commit ad7d015

Browse files
nagkumar91Nagkumar Arkalgud
and
Nagkumar Arkalgud
authored
Removing private parameter from __call__ of AdversarialSimulator (#37709)
* Update task_query_response.prompty remove required keys * Update task_simulate.prompty * Update task_query_response.prompty * Update task_simulate.prompty * Remove private variable and use kwargs * Add experimental tag to adv sim --------- Co-authored-by: Nagkumar Arkalgud <[email protected]>
1 parent 7b62acc commit ad7d015

File tree

5 files changed

+12
-71
lines changed

5 files changed

+12
-71
lines changed

sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/simulator/_adversarial_simulator.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@
2929
TokenScope,
3030
)
3131
from ._utils import JsonLineList
32+
from ._helpers import experimental
3233

3334
logger = logging.getLogger(__name__)
3435

3536

37+
@experimental
3638
class AdversarialSimulator:
3739
"""
3840
Initializes the adversarial simulator with a project scope.
@@ -92,7 +94,7 @@ def _ensure_service_dependencies(self):
9294
blame=ErrorBlame.USER_ERROR,
9395
)
9496

95-
# @monitor_adversarial_scenario
97+
# pylint: disable=too-many-locals
9698
async def __call__(
9799
self,
98100
*,
@@ -106,10 +108,10 @@ async def __call__(
106108
api_call_retry_sleep_sec: int = 1,
107109
api_call_delay_sec: int = 0,
108110
concurrent_async_task: int = 3,
109-
_jailbreak_type: Optional[str] = None,
110111
language: SupportedLanguages = SupportedLanguages.English,
111112
randomize_order: bool = True,
112113
randomization_seed: Optional[int] = None,
114+
**kwargs,
113115
):
114116
"""
115117
Executes the adversarial simulation against a specified target function asynchronously.
@@ -216,6 +218,7 @@ async def __call__(
216218
total_tasks,
217219
)
218220
total_tasks = min(total_tasks, max_simulation_results)
221+
_jailbreak_type = kwargs.get("_jailbreak_type", None)
219222
if _jailbreak_type:
220223
jailbreak_dataset = await self.rai_client.get_jailbreaks_dataset(type=_jailbreak_type)
221224
progress_bar = tqdm(

sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/simulator/_direct_attack_simulator.py

+3-33
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,25 @@
11
# ---------------------------------------------------------
22
# Copyright (c) Microsoft Corporation. All rights reserved.
33
# ---------------------------------------------------------
4+
# pylint: disable=C0301,C0114,R0913,R0903
45
# noqa: E501
5-
import functools
66
import logging
77
from random import randint
88
from typing import Callable, Optional
99

10-
from promptflow._sdk._telemetry import ActivityType, monitor_operation
11-
1210
from azure.ai.evaluation._exceptions import ErrorBlame, ErrorCategory, ErrorTarget, EvaluationException
1311
from azure.ai.evaluation._model_configurations import AzureAIProject
1412
from azure.ai.evaluation.simulator import AdversarialScenario
1513
from azure.identity import DefaultAzureCredential
1614

1715
from ._adversarial_simulator import AdversarialSimulator
1816
from ._model_tools import AdversarialTemplateHandler, ManagedIdentityAPITokenManager, RAIClient, TokenScope
17+
from ._helpers import experimental
1918

2019
logger = logging.getLogger(__name__)
2120

2221

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
5223
class DirectAttackSimulator:
5324
"""
5425
Initialize a UPIA (user prompt injected attack) jailbreak adversarial simulator with a project scope.
@@ -110,7 +81,6 @@ def _ensure_service_dependencies(self):
11081
blame=ErrorBlame.USER_ERROR,
11182
)
11283

113-
# @monitor_adversarial_scenario
11484
async def __call__(
11585
self,
11686
*,

sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/simulator/_indirect_attack_simulator.py

+3-34
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,23 @@
11
# ---------------------------------------------------------
22
# Copyright (c) Microsoft Corporation. All rights reserved.
33
# ---------------------------------------------------------
4+
# pylint: disable=C0301,C0114,R0913,R0903
45
# noqa: E501
5-
import functools
66
import logging
77
from typing import Callable
8-
9-
from promptflow._sdk._telemetry import ActivityType, monitor_operation
10-
118
from azure.ai.evaluation._exceptions import ErrorBlame, ErrorCategory, ErrorTarget, EvaluationException
129
from azure.ai.evaluation._model_configurations import AzureAIProject
1310
from azure.ai.evaluation.simulator import AdversarialScenario
1411
from azure.identity import DefaultAzureCredential
1512

1613
from ._adversarial_simulator import AdversarialSimulator
1714
from ._model_tools import AdversarialTemplateHandler, ManagedIdentityAPITokenManager, RAIClient, TokenScope
15+
from ._helpers import experimental
1816

1917
logger = logging.getLogger(__name__)
2018

2119

22-
def monitor_adversarial_scenario(func) -> Callable:
23-
"""Decorator to monitor adversarial scenario.
24-
25-
:param func: The function to be decorated.
26-
:type func: Callable
27-
:return: The decorated function.
28-
:rtype: Callable
29-
"""
30-
31-
@functools.wraps(func)
32-
def wrapper(*args, **kwargs):
33-
scenario = str(kwargs.get("scenario", None))
34-
max_conversation_turns = kwargs.get("max_conversation_turns", None)
35-
max_simulation_results = kwargs.get("max_simulation_results", None)
36-
decorated_func = monitor_operation(
37-
activity_name="xpia.adversarial.simulator.call",
38-
activity_type=ActivityType.PUBLICAPI,
39-
custom_dimensions={
40-
"scenario": scenario,
41-
"max_conversation_turns": max_conversation_turns,
42-
"max_simulation_results": max_simulation_results,
43-
},
44-
)(func)
45-
46-
return decorated_func(*args, **kwargs)
47-
48-
return wrapper
49-
50-
20+
@experimental
5121
class IndirectAttackSimulator:
5222
"""
5323
Initializes the XPIA (cross domain prompt injected attack) jailbreak adversarial simulator with a project scope.
@@ -107,7 +77,6 @@ def _ensure_service_dependencies(self):
10777
blame=ErrorBlame.USER_ERROR,
10878
)
10979

110-
# @monitor_adversarial_scenario
11180
async def __call__(
11281
self,
11382
*,

sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/simulator/_prompty/task_query_response.prompty

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ model:
66
configuration:
77
type: azure_openai
88
azure_deployment: ${env:AZURE_DEPLOYMENT}
9-
api_key: ${env:AZURE_OPENAI_API_KEY}
109
azure_endpoint: ${env:AZURE_OPENAI_ENDPOINT}
1110
parameters:
1211
temperature: 0.0

sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/simulator/_simulator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# flake8: noqa
2-
# pylint: disable=W0102,W0613,R0914,C0301,E0401,E0611
2+
# pylint: disable=W0102,W0613,R0914,C0301,E0401,E0611,C0114,R0913,E0702,R0903
33
# ---------------------------------------------------------
44
# Copyright (c) Microsoft Corporation. All rights reserved.
55
# ---------------------------------------------------------

0 commit comments

Comments
 (0)