Skip to content

Commit a0ac02d

Browse files
w-javedsingankit
andauthored
Red Team Upload changes (Azure#40895)
* Red Team Upload changes * Upload RedTeam fix * upload sample fix --------- Co-authored-by: Ankit Singhal <[email protected]>
1 parent 6a76d31 commit a0ac02d

File tree

6 files changed

+334
-135
lines changed

6 files changed

+334
-135
lines changed

sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/_common/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from .rai_service import evaluate_with_rai_service
1010
from .utils import get_harm_severity_level
1111
from .evaluation_onedp_client import EvaluationServiceOneDPClient
12-
from .onedp.models import EvaluationUpload, EvaluationResult
12+
from .onedp.models import EvaluationUpload, EvaluationResult, RedTeamUpload, ResultType
1313

1414
__all__ = [
1515
"get_harm_severity_level",
@@ -18,4 +18,6 @@
1818
"EvaluationServiceOneDPClient",
1919
"EvaluationResult",
2020
"EvaluationUpload",
21+
"RedTeamUpload",
22+
"ResultType",
2123
]

sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/_common/evaluation_onedp_client.py

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from azure.core.credentials import AzureKeyCredential, TokenCredential
88
from azure.ai.evaluation._common.onedp import AIProjectClient as RestEvaluationServiceClient
99
from azure.ai.evaluation._common.onedp.models import (PendingUploadRequest, PendingUploadType, EvaluationResult,
10-
ResultType, AssetCredentialRequest, EvaluationUpload, InputDataset)
10+
ResultType, AssetCredentialRequest, EvaluationUpload, InputDataset, RedTeamUpload)
1111
from azure.storage.blob import ContainerClient
1212
from .utils import upload
1313

@@ -22,7 +22,8 @@ def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCr
2222
**kwargs,
2323
)
2424

25-
def create_evaluation_result(self, *, name: str, path: str, version=1, metrics: Dict[str, int]=None, **kwargs) -> EvaluationResult:
25+
def create_evaluation_result(
26+
self, *, name: str, path: str, version=1, metrics: Dict[str, int]=None, result_type: ResultType=ResultType.EVALUATION, **kwargs) -> EvaluationResult:
2627
"""Create and upload evaluation results to Azure evaluation service.
2728
2829
This method uploads evaluation results from a local path to Azure Blob Storage
@@ -39,14 +40,16 @@ def create_evaluation_result(self, *, name: str, path: str, version=1, metrics:
3940
:param version: The version number for the evaluation results, defaults to 1
4041
:type version: int, optional
4142
:param metrics: Metrics to be added to evaluation result
42-
:type version: Dict[str, int], optional
43+
:type metrics: Dict[str, int], optional
44+
:param result_type: Evaluation Result Type to create
45+
:type result_type: ResultType, optional
4346
:param kwargs: Additional keyword arguments to pass to the underlying API calls
4447
:return: The response from creating the evaluation result version
4548
:rtype: EvaluationResult
4649
:raises: Various exceptions from the underlying API calls or upload process
4750
"""
4851

49-
LOGGER.debug(f"Creating evaluation result for {name} with version {version} from path {path}")
52+
LOGGER.debug(f"Creating evaluation result for {name} with version {version} type {result_type} from path {path}")
5053
start_pending_upload_response = self.rest_client.evaluation_results.start_pending_upload(
5154
name=name,
5255
version=version,
@@ -63,7 +66,7 @@ def create_evaluation_result(self, *, name: str, path: str, version=1, metrics:
6366
create_version_response = self.rest_client.evaluation_results.create_or_update_version(
6467
body=EvaluationResult(
6568
blob_uri=start_pending_upload_response.blob_reference_for_consumption.blob_uri,
66-
result_type=ResultType.EVALUATION,
69+
result_type=result_type,
6770
name=name,
6871
version=version,
6972
metrics=metrics,
@@ -115,4 +118,46 @@ def update_evaluation_run(self, *, name: str, evaluation: EvaluationUpload, **kw
115118
**kwargs
116119
)
117120

121+
return update_run_response
122+
123+
def start_red_team_run(self, *, red_team: RedTeamUpload, **kwargs):
124+
"""Start a new red team run in the Azure evaluation service.
125+
126+
This method creates a new red team run with the provided configuration details.
127+
128+
:param red_team: The red team configuration to upload
129+
:type red_team: ~azure.ai.evaluation._common.onedp.models.RedTeamUpload
130+
:param kwargs: Additional keyword arguments to pass to the underlying API calls
131+
:return: The created red team run object
132+
:rtype: ~azure.ai.evaluation._common.onedp.models.RedTeamUpload
133+
:raises: Various exceptions from the underlying API calls
134+
"""
135+
upload_run_response = self.rest_client.red_teams.upload_run(
136+
redteam=red_team,
137+
**kwargs
138+
)
139+
140+
return upload_run_response
141+
142+
def update_red_team_run(self, *, name: str, red_team: RedTeamUpload, **kwargs):
143+
"""Update an existing red team run in the Azure evaluation service.
144+
145+
This method updates a red team run with new information such as status changes,
146+
result references, or other metadata.
147+
148+
:param name: The identifier of the red team run to update
149+
:type name: str
150+
:param red_team: The updated red team configuration
151+
:type red_team: ~azure.ai.evaluation._common.onedp.models.RedTeamUpload
152+
:param kwargs: Additional keyword arguments to pass to the underlying API calls
153+
:return: The updated red team run object
154+
:rtype: ~azure.ai.evaluation._common.onedp.models.RedTeamUpload
155+
:raises: Various exceptions from the underlying API calls
156+
"""
157+
update_run_response = self.rest_client.red_teams.upload_update_run(
158+
name=name,
159+
redteam=red_team,
160+
**kwargs
161+
)
162+
118163
return update_run_response

sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/_common/onedp/operations/_operations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4267,7 +4267,7 @@ def upload_update_run(
42674267
if isinstance(redteam, (IOBase, bytes)):
42684268
_content = redteam
42694269
else:
4270-
_content = json.dumps(redteam, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore
4270+
_content = json.dumps(redteam, cls=SdkJSONEncoder, exclude_readonly=False) # type: ignore
42714271

42724272
_request = build_red_teams_upload_update_run_request(
42734273
name=name,

0 commit comments

Comments
 (0)