7
7
from azure .core .credentials import AzureKeyCredential , TokenCredential
8
8
from azure .ai .evaluation ._common .onedp import AIProjectClient as RestEvaluationServiceClient
9
9
from azure .ai .evaluation ._common .onedp .models import (PendingUploadRequest , PendingUploadType , EvaluationResult ,
10
- ResultType , AssetCredentialRequest , EvaluationUpload , InputDataset )
10
+ ResultType , AssetCredentialRequest , EvaluationUpload , InputDataset , RedTeamUpload )
11
11
from azure .storage .blob import ContainerClient
12
12
from .utils import upload
13
13
@@ -22,7 +22,8 @@ def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCr
22
22
** kwargs ,
23
23
)
24
24
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 :
26
27
"""Create and upload evaluation results to Azure evaluation service.
27
28
28
29
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:
39
40
:param version: The version number for the evaluation results, defaults to 1
40
41
:type version: int, optional
41
42
: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
43
46
:param kwargs: Additional keyword arguments to pass to the underlying API calls
44
47
:return: The response from creating the evaluation result version
45
48
:rtype: EvaluationResult
46
49
:raises: Various exceptions from the underlying API calls or upload process
47
50
"""
48
51
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 } " )
50
53
start_pending_upload_response = self .rest_client .evaluation_results .start_pending_upload (
51
54
name = name ,
52
55
version = version ,
@@ -63,7 +66,7 @@ def create_evaluation_result(self, *, name: str, path: str, version=1, metrics:
63
66
create_version_response = self .rest_client .evaluation_results .create_or_update_version (
64
67
body = EvaluationResult (
65
68
blob_uri = start_pending_upload_response .blob_reference_for_consumption .blob_uri ,
66
- result_type = ResultType . EVALUATION ,
69
+ result_type = result_type ,
67
70
name = name ,
68
71
version = version ,
69
72
metrics = metrics ,
@@ -115,4 +118,46 @@ def update_evaluation_run(self, *, name: str, evaluation: EvaluationUpload, **kw
115
118
** kwargs
116
119
)
117
120
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
+
118
163
return update_run_response
0 commit comments