Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add experimental tag to adv sim
  • Loading branch information
Nagkumar Arkalgud committed Oct 3, 2024
commit 1c59d3e4182c817154de95b3a1adaa45f13d7876
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
TokenScope,
)
from ._utils import JsonLineList
from ._helpers import experimental

logger = logging.getLogger(__name__)


@experimental
class AdversarialSimulator:
"""
Initializes the adversarial simulator with a project scope.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,11 @@

from ._adversarial_simulator import AdversarialSimulator
from ._model_tools import AdversarialTemplateHandler, ManagedIdentityAPITokenManager, RAIClient, TokenScope

from ._helpers import experimental
logger = logging.getLogger(__name__)


def monitor_adversarial_scenario(func) -> Callable:
"""Decorator to monitor adversarial scenario.

:param func: The function to be decorated.
:type func: Callable
:return: The decorated function.
:rtype: Callable
"""

@functools.wraps(func)
def wrapper(*args, **kwargs):
scenario = str(kwargs.get("scenario", None))
max_conversation_turns = kwargs.get("max_conversation_turns", None)
max_simulation_results = kwargs.get("max_simulation_results", None)
decorated_func = monitor_operation(
activity_name="jailbreak.adversarial.simulator.call",
activity_type=ActivityType.PUBLICAPI,
custom_dimensions={
"scenario": scenario,
"max_conversation_turns": max_conversation_turns,
"max_simulation_results": max_simulation_results,
},
)(func)

return decorated_func(*args, **kwargs)

return wrapper


@experimental
class DirectAttackSimulator:
"""
Initialize a UPIA (user prompt injected attack) jailbreak adversarial simulator with a project scope.
Expand Down Expand Up @@ -110,7 +82,6 @@ def _ensure_service_dependencies(self):
blame=ErrorBlame.USER_ERROR,
)

# @monitor_adversarial_scenario
async def __call__(
self,
*,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,12 @@

from ._adversarial_simulator import AdversarialSimulator
from ._model_tools import AdversarialTemplateHandler, ManagedIdentityAPITokenManager, RAIClient, TokenScope
from ._helpers import experimental

logger = logging.getLogger(__name__)


def monitor_adversarial_scenario(func) -> Callable:
"""Decorator to monitor adversarial scenario.

:param func: The function to be decorated.
:type func: Callable
:return: The decorated function.
:rtype: Callable
"""

@functools.wraps(func)
def wrapper(*args, **kwargs):
scenario = str(kwargs.get("scenario", None))
max_conversation_turns = kwargs.get("max_conversation_turns", None)
max_simulation_results = kwargs.get("max_simulation_results", None)
decorated_func = monitor_operation(
activity_name="xpia.adversarial.simulator.call",
activity_type=ActivityType.PUBLICAPI,
custom_dimensions={
"scenario": scenario,
"max_conversation_turns": max_conversation_turns,
"max_simulation_results": max_simulation_results,
},
)(func)

return decorated_func(*args, **kwargs)

return wrapper


@experimental
class IndirectAttackSimulator:
"""
Initializes the XPIA (cross domain prompt injected attack) jailbreak adversarial simulator with a project scope.
Expand Down Expand Up @@ -107,7 +80,6 @@ def _ensure_service_dependencies(self):
blame=ErrorBlame.USER_ERROR,
)

# @monitor_adversarial_scenario
async def __call__(
self,
*,
Expand Down