Skip to content

Commit

Permalink
Adding more custom dimensions (#3356)
Browse files Browse the repository at this point in the history
# Description

Please add an informative description that covers that changes made by
the pull request and link all relevant issues.

# All Promptflow Contribution checklist:
- [ ] **The pull request does not introduce [breaking changes].**
- [ ] **CHANGELOG is updated for new features, bug fixes or other
significant changes.**
- [ ] **I have read the [contribution guidelines](../CONTRIBUTING.md).**
- [ ] **Create an issue and link to the pull request to get dedicated
review from promptflow team. Learn more: [suggested
workflow](../CONTRIBUTING.md#suggested-workflow).**

## General Guidelines and Best Practices
- [ ] Title of the pull request is clear and informative.
- [ ] There are a small number of commits, each of which have an
informative message. This means that previously merged commits do not
appear in the history of the PR. For more information on cleaning up the
commits in your PR, [see this
page](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/cleaning-up-commits.md).

### Testing Guidelines
- [ ] Pull request includes test coverage for the included changes.
  • Loading branch information
nagkumar91 authored May 31, 2024
1 parent 0f381b4 commit 78d8ada
Showing 1 changed file with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# ---------------------------------------------------------
# noqa: E501
import asyncio
import functools
import logging
import random
from typing import Any, Callable, Dict, List
Expand All @@ -27,6 +28,29 @@
logger = logging.getLogger(__name__)


def monitor_adversarial_scenario(func):
@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)
jailbreak = kwargs.get("jailbreak", None)
decorated_func = monitor_operation(
activity_name="adversarial.simulator.call",
activity_type=ActivityType.PUBLICAPI,
custom_dimensions={
"scenario": scenario,
"max_conversation_turns": max_conversation_turns,
"max_simulation_results": max_simulation_results,
"jailbreak": jailbreak,
},
)(func)

return decorated_func(*args, **kwargs)

return wrapper


class AdversarialSimulator:
def __init__(self, *, azure_ai_project: Dict[str, Any]):
"""
Expand Down Expand Up @@ -66,7 +90,7 @@ def _ensure_service_dependencies(self):
if self.rai_client is None:
raise ValueError("Simulation options require rai services but ai client is not provided.")

@monitor_operation(activity_name="adversarial.simulator.call", activity_type=ActivityType.PUBLICAPI)
@monitor_adversarial_scenario
async def __call__(
self,
*,
Expand Down

0 comments on commit 78d8ada

Please sign in to comment.