azure-ai-evaluation 1.0.0__py3-none-any.whl → 1.0.0b2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of azure-ai-evaluation might be problematic. Click here for more details.
- azure/ai/evaluation/__init__.py +5 -31
- azure/ai/evaluation/_common/constants.py +2 -9
- azure/ai/evaluation/_common/rai_service.py +120 -300
- azure/ai/evaluation/_common/utils.py +23 -381
- azure/ai/evaluation/_constants.py +6 -19
- azure/ai/evaluation/_evaluate/{_batch_run → _batch_run_client}/__init__.py +2 -3
- azure/ai/evaluation/_evaluate/{_batch_run/eval_run_context.py → _batch_run_client/batch_run_context.py} +7 -23
- azure/ai/evaluation/_evaluate/{_batch_run → _batch_run_client}/code_client.py +17 -33
- azure/ai/evaluation/_evaluate/{_batch_run → _batch_run_client}/proxy_client.py +4 -32
- azure/ai/evaluation/_evaluate/_eval_run.py +24 -81
- azure/ai/evaluation/_evaluate/_evaluate.py +239 -393
- azure/ai/evaluation/_evaluate/_telemetry/__init__.py +17 -17
- azure/ai/evaluation/_evaluate/_utils.py +28 -82
- azure/ai/evaluation/_evaluators/_bleu/_bleu.py +18 -17
- azure/ai/evaluation/_evaluators/{_retrieval → _chat}/__init__.py +2 -2
- azure/ai/evaluation/_evaluators/_chat/_chat.py +357 -0
- azure/ai/evaluation/_evaluators/{_service_groundedness → _chat/retrieval}/__init__.py +2 -2
- azure/ai/evaluation/_evaluators/_chat/retrieval/_retrieval.py +157 -0
- azure/ai/evaluation/_evaluators/_chat/retrieval/retrieval.prompty +48 -0
- azure/ai/evaluation/_evaluators/_coherence/_coherence.py +88 -78
- azure/ai/evaluation/_evaluators/_coherence/coherence.prompty +39 -76
- azure/ai/evaluation/_evaluators/_content_safety/__init__.py +4 -0
- azure/ai/evaluation/_evaluators/_content_safety/_content_safety.py +67 -105
- azure/ai/evaluation/_evaluators/{_multimodal/_content_safety_multimodal_base.py → _content_safety/_content_safety_base.py} +34 -24
- azure/ai/evaluation/_evaluators/_content_safety/_content_safety_chat.py +301 -0
- azure/ai/evaluation/_evaluators/_content_safety/_hate_unfairness.py +54 -105
- azure/ai/evaluation/_evaluators/_content_safety/_self_harm.py +52 -99
- azure/ai/evaluation/_evaluators/_content_safety/_sexual.py +52 -101
- azure/ai/evaluation/_evaluators/_content_safety/_violence.py +51 -101
- azure/ai/evaluation/_evaluators/_eci/_eci.py +54 -44
- azure/ai/evaluation/_evaluators/_f1_score/_f1_score.py +19 -34
- azure/ai/evaluation/_evaluators/_fluency/_fluency.py +89 -76
- azure/ai/evaluation/_evaluators/_fluency/fluency.prompty +41 -66
- azure/ai/evaluation/_evaluators/_gleu/_gleu.py +16 -14
- azure/ai/evaluation/_evaluators/_groundedness/_groundedness.py +87 -113
- azure/ai/evaluation/_evaluators/_groundedness/groundedness.prompty +54 -0
- azure/ai/evaluation/_evaluators/_meteor/_meteor.py +27 -20
- azure/ai/evaluation/_evaluators/_protected_material/_protected_material.py +80 -89
- azure/ai/evaluation/_evaluators/_protected_materials/__init__.py +5 -0
- azure/ai/evaluation/_evaluators/_protected_materials/_protected_materials.py +104 -0
- azure/ai/evaluation/_evaluators/_qa/_qa.py +30 -23
- azure/ai/evaluation/_evaluators/_relevance/_relevance.py +96 -84
- azure/ai/evaluation/_evaluators/_relevance/relevance.prompty +47 -78
- azure/ai/evaluation/_evaluators/_rouge/_rouge.py +27 -26
- azure/ai/evaluation/_evaluators/_similarity/_similarity.py +38 -53
- azure/ai/evaluation/_evaluators/_similarity/similarity.prompty +5 -0
- azure/ai/evaluation/_evaluators/_xpia/xpia.py +105 -91
- azure/ai/evaluation/_exceptions.py +7 -28
- azure/ai/evaluation/_http_utils.py +132 -203
- azure/ai/evaluation/_model_configurations.py +8 -104
- azure/ai/evaluation/_version.py +1 -1
- azure/ai/evaluation/simulator/__init__.py +1 -2
- azure/ai/evaluation/simulator/_adversarial_scenario.py +1 -20
- azure/ai/evaluation/simulator/_adversarial_simulator.py +92 -111
- azure/ai/evaluation/simulator/_constants.py +1 -11
- azure/ai/evaluation/simulator/_conversation/__init__.py +12 -13
- azure/ai/evaluation/simulator/_conversation/_conversation.py +4 -4
- azure/ai/evaluation/simulator/_direct_attack_simulator.py +67 -33
- azure/ai/evaluation/simulator/_helpers/__init__.py +2 -1
- azure/ai/evaluation/{_common → simulator/_helpers}/_experimental.py +9 -24
- azure/ai/evaluation/simulator/_helpers/_simulator_data_classes.py +5 -26
- azure/ai/evaluation/simulator/_indirect_attack_simulator.py +94 -107
- azure/ai/evaluation/simulator/_model_tools/_identity_manager.py +22 -70
- azure/ai/evaluation/simulator/_model_tools/_proxy_completion_model.py +11 -28
- azure/ai/evaluation/simulator/_model_tools/_rai_client.py +4 -8
- azure/ai/evaluation/simulator/_model_tools/_template_handler.py +24 -68
- azure/ai/evaluation/simulator/_model_tools/models.py +10 -10
- azure/ai/evaluation/simulator/_prompty/task_query_response.prompty +10 -6
- azure/ai/evaluation/simulator/_prompty/task_simulate.prompty +5 -6
- azure/ai/evaluation/simulator/_simulator.py +207 -277
- azure/ai/evaluation/simulator/_tracing.py +4 -4
- azure/ai/evaluation/simulator/_utils.py +13 -31
- azure_ai_evaluation-1.0.0b2.dist-info/METADATA +449 -0
- azure_ai_evaluation-1.0.0b2.dist-info/RECORD +99 -0
- {azure_ai_evaluation-1.0.0.dist-info → azure_ai_evaluation-1.0.0b2.dist-info}/WHEEL +1 -1
- azure/ai/evaluation/_common/math.py +0 -89
- azure/ai/evaluation/_evaluate/_batch_run/target_run_context.py +0 -46
- azure/ai/evaluation/_evaluators/_common/__init__.py +0 -13
- azure/ai/evaluation/_evaluators/_common/_base_eval.py +0 -344
- azure/ai/evaluation/_evaluators/_common/_base_prompty_eval.py +0 -88
- azure/ai/evaluation/_evaluators/_common/_base_rai_svc_eval.py +0 -133
- azure/ai/evaluation/_evaluators/_groundedness/groundedness_with_query.prompty +0 -113
- azure/ai/evaluation/_evaluators/_groundedness/groundedness_without_query.prompty +0 -99
- azure/ai/evaluation/_evaluators/_multimodal/__init__.py +0 -20
- azure/ai/evaluation/_evaluators/_multimodal/_content_safety_multimodal.py +0 -132
- azure/ai/evaluation/_evaluators/_multimodal/_hate_unfairness.py +0 -100
- azure/ai/evaluation/_evaluators/_multimodal/_protected_material.py +0 -124
- azure/ai/evaluation/_evaluators/_multimodal/_self_harm.py +0 -100
- azure/ai/evaluation/_evaluators/_multimodal/_sexual.py +0 -100
- azure/ai/evaluation/_evaluators/_multimodal/_violence.py +0 -100
- azure/ai/evaluation/_evaluators/_retrieval/_retrieval.py +0 -112
- azure/ai/evaluation/_evaluators/_retrieval/retrieval.prompty +0 -93
- azure/ai/evaluation/_evaluators/_service_groundedness/_service_groundedness.py +0 -148
- azure/ai/evaluation/_vendor/__init__.py +0 -3
- azure/ai/evaluation/_vendor/rouge_score/__init__.py +0 -14
- azure/ai/evaluation/_vendor/rouge_score/rouge_scorer.py +0 -328
- azure/ai/evaluation/_vendor/rouge_score/scoring.py +0 -63
- azure/ai/evaluation/_vendor/rouge_score/tokenize.py +0 -63
- azure/ai/evaluation/_vendor/rouge_score/tokenizers.py +0 -53
- azure/ai/evaluation/simulator/_data_sources/__init__.py +0 -3
- azure/ai/evaluation/simulator/_data_sources/grounding.json +0 -1150
- azure_ai_evaluation-1.0.0.dist-info/METADATA +0 -595
- azure_ai_evaluation-1.0.0.dist-info/NOTICE.txt +0 -70
- azure_ai_evaluation-1.0.0.dist-info/RECORD +0 -119
- {azure_ai_evaluation-1.0.0.dist-info → azure_ai_evaluation-1.0.0b2.dist-info}/top_level.txt +0 -0
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
# ---------------------------------------------------------
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
from
|
|
6
|
+
from functools import wraps
|
|
7
|
+
from typing import Any, Awaitable, Callable, Dict, MutableMapping, Optional
|
|
7
8
|
|
|
8
|
-
from typing_extensions import Self
|
|
9
|
+
from typing_extensions import Self
|
|
9
10
|
|
|
10
11
|
from azure.ai.evaluation._user_agent import USER_AGENT
|
|
11
12
|
from azure.core.configuration import Configuration
|
|
@@ -32,25 +33,78 @@ from azure.core.rest import AsyncHttpResponse, HttpRequest, HttpResponse
|
|
|
32
33
|
from azure.core.rest._rest_py3 import ContentType, FilesType, ParamsType
|
|
33
34
|
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
"""
|
|
36
|
+
def _request_fn(f: Callable[["HttpPipeline"], None]):
|
|
37
|
+
"""Decorator to generate convenience methods for HTTP method.
|
|
37
38
|
|
|
38
|
-
|
|
39
|
+
:param Callable[["HttpPipeline"],None] f: A HttpPipeline classmethod to wrap.
|
|
40
|
+
The f.__name__ is the HTTP method used
|
|
41
|
+
:return: A wrapped callable that sends a `f.__name__` request
|
|
42
|
+
:rtype: Callable
|
|
43
|
+
"""
|
|
39
44
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
45
|
+
@wraps(f)
|
|
46
|
+
def request_fn(
|
|
47
|
+
self: "HttpPipeline",
|
|
48
|
+
url: str,
|
|
49
|
+
*,
|
|
50
|
+
params: Optional[ParamsType] = None,
|
|
51
|
+
headers: Optional[MutableMapping[str, str]] = None,
|
|
52
|
+
json: Any = None,
|
|
53
|
+
content: Optional[ContentType] = None,
|
|
54
|
+
data: Optional[Dict[str, Any]] = None,
|
|
55
|
+
files: Optional[FilesType] = None,
|
|
56
|
+
**kwargs,
|
|
57
|
+
) -> HttpResponse:
|
|
58
|
+
return self.request(
|
|
59
|
+
f.__name__.upper(),
|
|
60
|
+
url,
|
|
61
|
+
params=params,
|
|
62
|
+
headers=headers,
|
|
63
|
+
json=json,
|
|
64
|
+
content=content,
|
|
65
|
+
data=data,
|
|
66
|
+
files=files,
|
|
67
|
+
**kwargs,
|
|
68
|
+
)
|
|
43
69
|
|
|
44
|
-
|
|
45
|
-
|
|
70
|
+
return request_fn
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _async_request_fn(f: Callable[["AsyncHttpPipeline"], Awaitable[None]]):
|
|
74
|
+
"""Decorator to generate convenience methods for HTTP method.
|
|
75
|
+
|
|
76
|
+
:param Callable[["HttpPipeline"],None] f: A HttpPipeline classmethod to wrap.
|
|
77
|
+
The f.__name__ is the HTTP method used
|
|
78
|
+
:return: A wrapped callable that sends a `f.__name__` request
|
|
79
|
+
:rtype: Callable
|
|
46
80
|
"""
|
|
47
81
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
82
|
+
@wraps(f)
|
|
83
|
+
async def request_fn(
|
|
84
|
+
self: "AsyncHttpPipeline",
|
|
85
|
+
url: str,
|
|
86
|
+
*,
|
|
87
|
+
params: Optional[ParamsType] = None,
|
|
88
|
+
headers: Optional[MutableMapping[str, str]] = None,
|
|
89
|
+
json: Any = None,
|
|
90
|
+
content: Optional[ContentType] = None,
|
|
91
|
+
data: Optional[Dict[str, Any]] = None,
|
|
92
|
+
files: Optional[FilesType] = None,
|
|
93
|
+
**kwargs,
|
|
94
|
+
) -> AsyncHttpResponse:
|
|
95
|
+
return await self.request(
|
|
96
|
+
f.__name__.upper(),
|
|
97
|
+
url,
|
|
98
|
+
params=params,
|
|
99
|
+
headers=headers,
|
|
100
|
+
json=json,
|
|
101
|
+
content=content,
|
|
102
|
+
data=data,
|
|
103
|
+
files=files,
|
|
104
|
+
**kwargs,
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
return request_fn
|
|
54
108
|
|
|
55
109
|
|
|
56
110
|
class HttpPipeline(Pipeline):
|
|
@@ -91,32 +145,14 @@ class HttpPipeline(Pipeline):
|
|
|
91
145
|
:param RedirectPolicy redirect_policy:
|
|
92
146
|
"""
|
|
93
147
|
config = config or Configuration()
|
|
94
|
-
config.headers_policy = (
|
|
95
|
-
|
|
96
|
-
)
|
|
97
|
-
config.
|
|
98
|
-
config.
|
|
99
|
-
|
|
100
|
-
)
|
|
101
|
-
config.
|
|
102
|
-
config.custom_hook_policy = (
|
|
103
|
-
custom_hook_policy
|
|
104
|
-
or cast(Optional[CustomHookPolicy], config.custom_hook_policy)
|
|
105
|
-
or CustomHookPolicy(**kwargs)
|
|
106
|
-
)
|
|
107
|
-
config.logging_policy = (
|
|
108
|
-
logging_policy
|
|
109
|
-
or cast(Optional[NetworkTraceLoggingPolicy], config.logging_policy)
|
|
110
|
-
or NetworkTraceLoggingPolicy(**kwargs)
|
|
111
|
-
)
|
|
112
|
-
config.http_logging_policy = (
|
|
113
|
-
http_logging_policy
|
|
114
|
-
or cast(Optional[HttpLoggingPolicy], config.http_logging_policy)
|
|
115
|
-
or HttpLoggingPolicy(**kwargs)
|
|
116
|
-
)
|
|
117
|
-
config.user_agent_policy = (
|
|
118
|
-
user_agent_policy or cast(Optional[UserAgentPolicy], config.user_agent_policy) or UserAgentPolicy(**kwargs)
|
|
119
|
-
)
|
|
148
|
+
config.headers_policy = headers_policy or config.headers_policy or HeadersPolicy(**kwargs)
|
|
149
|
+
config.proxy_policy = proxy_policy or config.proxy_policy or ProxyPolicy(**kwargs)
|
|
150
|
+
config.redirect_policy = redirect_policy or config.redirect_policy or RedirectPolicy(**kwargs)
|
|
151
|
+
config.retry_policy = retry_policy or config.retry_policy or RetryPolicy(**kwargs)
|
|
152
|
+
config.custom_hook_policy = custom_hook_policy or config.custom_hook_policy or CustomHookPolicy(**kwargs)
|
|
153
|
+
config.logging_policy = logging_policy or config.logging_policy or NetworkTraceLoggingPolicy(**kwargs)
|
|
154
|
+
config.http_logging_policy = http_logging_policy or config.http_logging_policy or HttpLoggingPolicy(**kwargs)
|
|
155
|
+
config.user_agent_policy = user_agent_policy or config.user_agent_policy or UserAgentPolicy(**kwargs)
|
|
120
156
|
config.polling_interval = kwargs.get("polling_interval", 30)
|
|
121
157
|
|
|
122
158
|
super().__init__(
|
|
@@ -130,6 +166,7 @@ class HttpPipeline(Pipeline):
|
|
|
130
166
|
config.proxy_policy,
|
|
131
167
|
config.redirect_policy,
|
|
132
168
|
config.retry_policy,
|
|
169
|
+
config.authentication_policy,
|
|
133
170
|
config.custom_hook_policy,
|
|
134
171
|
config.logging_policy,
|
|
135
172
|
],
|
|
@@ -162,6 +199,7 @@ class HttpPipeline(Pipeline):
|
|
|
162
199
|
files: Optional[FilesType] = None,
|
|
163
200
|
**kwargs,
|
|
164
201
|
) -> HttpResponse:
|
|
202
|
+
|
|
165
203
|
request = HttpRequest(
|
|
166
204
|
method,
|
|
167
205
|
url,
|
|
@@ -175,78 +213,33 @@ class HttpPipeline(Pipeline):
|
|
|
175
213
|
|
|
176
214
|
return self.run(request, **kwargs).http_response
|
|
177
215
|
|
|
178
|
-
|
|
179
|
-
|
|
216
|
+
@_request_fn
|
|
217
|
+
def delete(self) -> None:
|
|
218
|
+
"""Send a DELETE request."""
|
|
180
219
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
"""
|
|
220
|
+
@_request_fn
|
|
221
|
+
def put(self) -> None:
|
|
222
|
+
"""Send a PUT request."""
|
|
185
223
|
|
|
186
|
-
|
|
224
|
+
@_request_fn
|
|
225
|
+
def get(self) -> None:
|
|
226
|
+
"""Send a GET request."""
|
|
187
227
|
|
|
188
|
-
|
|
189
|
-
|
|
228
|
+
@_request_fn
|
|
229
|
+
def post(self) -> None:
|
|
230
|
+
"""Send a POST request."""
|
|
190
231
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
"""
|
|
232
|
+
@_request_fn
|
|
233
|
+
def head(self) -> None:
|
|
234
|
+
"""Send a HEAD request."""
|
|
195
235
|
|
|
196
|
-
|
|
236
|
+
@_request_fn
|
|
237
|
+
def options(self) -> None:
|
|
238
|
+
"""Send a OPTIONS request."""
|
|
197
239
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
:param str url: The request url
|
|
202
|
-
:returns: The request response
|
|
203
|
-
:rtype: HttpResponse
|
|
204
|
-
"""
|
|
205
|
-
|
|
206
|
-
return self.request(self.get.__name__.upper(), url, **kwargs)
|
|
207
|
-
|
|
208
|
-
def post(self: "HttpPipeline", url: str, **kwargs: Unpack[RequestKwargs]) -> HttpResponse:
|
|
209
|
-
"""Send a POST request.
|
|
210
|
-
|
|
211
|
-
:param str url: The request url
|
|
212
|
-
:returns: The request response
|
|
213
|
-
:rtype: HttpResponse
|
|
214
|
-
"""
|
|
215
|
-
|
|
216
|
-
return self.request(self.post.__name__.upper(), url, **kwargs)
|
|
217
|
-
|
|
218
|
-
def head(self: "HttpPipeline", url: str, **kwargs: Unpack[RequestKwargs]) -> HttpResponse:
|
|
219
|
-
"""Send a HEAD request.
|
|
220
|
-
|
|
221
|
-
:param str url: The request url
|
|
222
|
-
:returns: The request response
|
|
223
|
-
:rtype: HttpResponse
|
|
224
|
-
"""
|
|
225
|
-
|
|
226
|
-
return self.request(self.head.__name__.upper(), url, **kwargs)
|
|
227
|
-
|
|
228
|
-
def options(self: "HttpPipeline", url: str, **kwargs: Unpack[RequestKwargs]) -> HttpResponse:
|
|
229
|
-
"""Send a OPTIONS request.
|
|
230
|
-
|
|
231
|
-
:param str url: The request url
|
|
232
|
-
:returns: The request response
|
|
233
|
-
:rtype: HttpResponse
|
|
234
|
-
"""
|
|
235
|
-
|
|
236
|
-
return self.request(self.options.__name__.upper(), url, **kwargs)
|
|
237
|
-
|
|
238
|
-
def patch(self: "HttpPipeline", url: str, **kwargs: Unpack[RequestKwargs]) -> HttpResponse:
|
|
239
|
-
"""Send a PATCH request.
|
|
240
|
-
|
|
241
|
-
:param str url: The request url
|
|
242
|
-
:returns: The request response
|
|
243
|
-
:rtype: HttpResponse
|
|
244
|
-
"""
|
|
245
|
-
|
|
246
|
-
return self.request(self.patch.__name__.upper(), url, **kwargs)
|
|
247
|
-
|
|
248
|
-
def __enter__(self) -> Self:
|
|
249
|
-
return cast(Self, super().__enter__())
|
|
240
|
+
@_request_fn
|
|
241
|
+
def patch(self) -> None:
|
|
242
|
+
"""Send a PATCH request."""
|
|
250
243
|
|
|
251
244
|
|
|
252
245
|
class AsyncHttpPipeline(AsyncPipeline):
|
|
@@ -287,36 +280,14 @@ class AsyncHttpPipeline(AsyncPipeline):
|
|
|
287
280
|
:param AsyncRedirectPolicy redirect_policy:
|
|
288
281
|
"""
|
|
289
282
|
config = config or Configuration()
|
|
290
|
-
config.headers_policy = (
|
|
291
|
-
|
|
292
|
-
)
|
|
293
|
-
config.
|
|
294
|
-
config.
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
)
|
|
299
|
-
config.retry_policy = (
|
|
300
|
-
retry_policy or cast(Optional[AsyncRetryPolicy], config.retry_policy) or AsyncRetryPolicy(**kwargs)
|
|
301
|
-
)
|
|
302
|
-
config.custom_hook_policy = (
|
|
303
|
-
custom_hook_policy
|
|
304
|
-
or cast(Optional[CustomHookPolicy], config.custom_hook_policy)
|
|
305
|
-
or CustomHookPolicy(**kwargs)
|
|
306
|
-
)
|
|
307
|
-
config.logging_policy = (
|
|
308
|
-
logging_policy
|
|
309
|
-
or cast(Optional[NetworkTraceLoggingPolicy], config.logging_policy)
|
|
310
|
-
or NetworkTraceLoggingPolicy(**kwargs)
|
|
311
|
-
)
|
|
312
|
-
config.http_logging_policy = (
|
|
313
|
-
http_logging_policy
|
|
314
|
-
or cast(Optional[HttpLoggingPolicy], config.http_logging_policy)
|
|
315
|
-
or HttpLoggingPolicy(**kwargs)
|
|
316
|
-
)
|
|
317
|
-
config.user_agent_policy = (
|
|
318
|
-
user_agent_policy or cast(Optional[UserAgentPolicy], config.user_agent_policy) or UserAgentPolicy(**kwargs)
|
|
319
|
-
)
|
|
283
|
+
config.headers_policy = headers_policy or config.headers_policy or HeadersPolicy(**kwargs)
|
|
284
|
+
config.proxy_policy = proxy_policy or config.proxy_policy or ProxyPolicy(**kwargs)
|
|
285
|
+
config.redirect_policy = redirect_policy or config.redirect_policy or AsyncRedirectPolicy(**kwargs)
|
|
286
|
+
config.retry_policy = retry_policy or config.retry_policy or AsyncRetryPolicy(**kwargs)
|
|
287
|
+
config.custom_hook_policy = custom_hook_policy or config.custom_hook_policy or CustomHookPolicy(**kwargs)
|
|
288
|
+
config.logging_policy = logging_policy or config.logging_policy or NetworkTraceLoggingPolicy(**kwargs)
|
|
289
|
+
config.http_logging_policy = http_logging_policy or config.http_logging_policy or HttpLoggingPolicy(**kwargs)
|
|
290
|
+
config.user_agent_policy = user_agent_policy or config.user_agent_policy or UserAgentPolicy(**kwargs)
|
|
320
291
|
config.polling_interval = kwargs.get("polling_interval", 30)
|
|
321
292
|
|
|
322
293
|
super().__init__(
|
|
@@ -330,6 +301,7 @@ class AsyncHttpPipeline(AsyncPipeline):
|
|
|
330
301
|
config.proxy_policy,
|
|
331
302
|
config.redirect_policy,
|
|
332
303
|
config.retry_policy,
|
|
304
|
+
config.authentication_policy,
|
|
333
305
|
config.custom_hook_policy,
|
|
334
306
|
config.logging_policy,
|
|
335
307
|
],
|
|
@@ -362,6 +334,7 @@ class AsyncHttpPipeline(AsyncPipeline):
|
|
|
362
334
|
files: Optional[FilesType] = None,
|
|
363
335
|
**kwargs,
|
|
364
336
|
) -> AsyncHttpResponse:
|
|
337
|
+
|
|
365
338
|
request = HttpRequest(
|
|
366
339
|
method,
|
|
367
340
|
url,
|
|
@@ -375,77 +348,33 @@ class AsyncHttpPipeline(AsyncPipeline):
|
|
|
375
348
|
|
|
376
349
|
return (await self.run(request, **kwargs)).http_response
|
|
377
350
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
:param str url: The request url
|
|
382
|
-
:returns: The request response
|
|
383
|
-
:rtype: AsyncHttpResponse
|
|
384
|
-
"""
|
|
385
|
-
return await self.request(self.delete.__name__.upper(), url, **kwargs)
|
|
386
|
-
|
|
387
|
-
async def put(self: "AsyncHttpPipeline", url: str, **kwargs: Unpack[RequestKwargs]) -> AsyncHttpResponse:
|
|
388
|
-
"""Send a PUT request.
|
|
389
|
-
|
|
390
|
-
:param str url: The request url
|
|
391
|
-
:returns: The request response
|
|
392
|
-
:rtype: AsyncHttpResponse
|
|
393
|
-
"""
|
|
394
|
-
|
|
395
|
-
return await self.request(self.put.__name__.upper(), url, **kwargs)
|
|
396
|
-
|
|
397
|
-
async def get(self: "AsyncHttpPipeline", url: str, **kwargs: Unpack[RequestKwargs]) -> AsyncHttpResponse:
|
|
398
|
-
"""Send a GET request.
|
|
399
|
-
|
|
400
|
-
:param str url: The request url
|
|
401
|
-
:returns: The request response
|
|
402
|
-
:rtype: AsyncHttpResponse
|
|
403
|
-
"""
|
|
404
|
-
|
|
405
|
-
return await self.request(self.get.__name__.upper(), url, **kwargs)
|
|
406
|
-
|
|
407
|
-
async def post(self: "AsyncHttpPipeline", url: str, **kwargs: Unpack[RequestKwargs]) -> AsyncHttpResponse:
|
|
408
|
-
"""Send a POST request.
|
|
409
|
-
|
|
410
|
-
:param str url: The request url
|
|
411
|
-
:returns: The request response
|
|
412
|
-
:rtype: AsyncHttpResponse
|
|
413
|
-
"""
|
|
414
|
-
|
|
415
|
-
return await self.request(self.post.__name__.upper(), url, **kwargs)
|
|
416
|
-
|
|
417
|
-
async def head(self: "AsyncHttpPipeline", url: str, **kwargs: Unpack[RequestKwargs]) -> AsyncHttpResponse:
|
|
418
|
-
"""Send a HEAD request.
|
|
351
|
+
@_async_request_fn
|
|
352
|
+
async def delete(self) -> None:
|
|
353
|
+
"""Send a DELETE request."""
|
|
419
354
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
"""
|
|
424
|
-
|
|
425
|
-
return await self.request(self.head.__name__.upper(), url, **kwargs)
|
|
426
|
-
|
|
427
|
-
async def options(self: "AsyncHttpPipeline", url: str, **kwargs: Unpack[RequestKwargs]) -> AsyncHttpResponse:
|
|
428
|
-
"""Send a OPTIONS request.
|
|
355
|
+
@_async_request_fn
|
|
356
|
+
async def put(self) -> None:
|
|
357
|
+
"""Send a PUT request."""
|
|
429
358
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
"""
|
|
434
|
-
|
|
435
|
-
return await self.request(self.options.__name__.upper(), url, **kwargs)
|
|
359
|
+
@_async_request_fn
|
|
360
|
+
async def get(self) -> None:
|
|
361
|
+
"""Send a GET request."""
|
|
436
362
|
|
|
437
|
-
|
|
438
|
-
|
|
363
|
+
@_async_request_fn
|
|
364
|
+
async def post(self) -> None:
|
|
365
|
+
"""Send a POST request."""
|
|
439
366
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
"""
|
|
367
|
+
@_async_request_fn
|
|
368
|
+
async def head(self) -> None:
|
|
369
|
+
"""Send a HEAD request."""
|
|
444
370
|
|
|
445
|
-
|
|
371
|
+
@_async_request_fn
|
|
372
|
+
async def options(self) -> None:
|
|
373
|
+
"""Send a OPTIONS request."""
|
|
446
374
|
|
|
447
|
-
|
|
448
|
-
|
|
375
|
+
@_async_request_fn
|
|
376
|
+
async def patch(self) -> None:
|
|
377
|
+
"""Send a PATCH request."""
|
|
449
378
|
|
|
450
379
|
|
|
451
380
|
def get_http_client() -> HttpPipeline:
|
|
@@ -2,122 +2,26 @@
|
|
|
2
2
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
3
|
# ---------------------------------------------------------
|
|
4
4
|
|
|
5
|
-
from typing import
|
|
5
|
+
from typing import TypedDict
|
|
6
6
|
|
|
7
|
-
from typing_extensions import NotRequired
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
class AzureOpenAIModelConfiguration(TypedDict):
|
|
11
|
-
"""Model configuration for Azure OpenAI models
|
|
12
|
-
|
|
13
|
-
:param type: The type of the model configuration. Should be 'azure_openai' for AzureOpenAIModelConfiguration
|
|
14
|
-
:type type: NotRequired[Literal["azure_openai"]]
|
|
15
|
-
:param azure_deployment: Name of Azure OpenAI deployment to make requests to
|
|
16
|
-
:type azure_deployment: str
|
|
17
|
-
:param azure_endpoint: Endpoint of Azure OpenAI resource to make requests to
|
|
18
|
-
:type azure_endpoint: str
|
|
19
|
-
:param api_key: API key of Azure OpenAI resource
|
|
20
|
-
:type api_key: str
|
|
21
|
-
:param api_version: API version to use in request to Azure OpenAI deployment. Optional.
|
|
22
|
-
:type api_version: NotRequired[str]
|
|
23
|
-
|
|
24
|
-
.. admonition:: Example:
|
|
25
|
-
|
|
26
|
-
.. literalinclude:: ../samples/evaluation_samples_common.py
|
|
27
|
-
:start-after: [START create_AOAI_model_config]
|
|
28
|
-
:end-before: [END create_AOAI_model_config]
|
|
29
|
-
:language: python
|
|
30
|
-
:dedent: 8
|
|
31
|
-
:caption: Creating an AzureOpenAIModelConfiguration object.
|
|
32
|
-
|
|
33
|
-
"""
|
|
34
|
-
|
|
35
|
-
type: NotRequired[Literal["azure_openai"]]
|
|
8
|
+
class AzureOpenAIModelConfigurationBase(TypedDict):
|
|
36
9
|
azure_deployment: str
|
|
37
10
|
azure_endpoint: str
|
|
38
|
-
|
|
39
|
-
api_key: NotRequired[str]
|
|
40
|
-
"""API key of Azure OpenAI resource"""
|
|
41
|
-
api_version: NotRequired[str]
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
class OpenAIModelConfiguration(TypedDict):
|
|
45
|
-
"""Model configuration for OpenAI models
|
|
46
|
-
|
|
47
|
-
:param type: The type of the model configuration. Should be 'openai' for OpenAIModelConfiguration
|
|
48
|
-
:type type: NotRequired[Literal["openai"]]
|
|
49
|
-
:param api_key: API key needed to make requests to model
|
|
50
|
-
:type api_key: str
|
|
51
|
-
:param model: Name of model to be used in OpenAI request
|
|
52
|
-
:type model: str
|
|
53
|
-
:param base_url: Base URL to be used in OpenAI request. Optional.
|
|
54
|
-
:type base_url: NotRequired[str]
|
|
55
|
-
:param organization: OpenAI organization. Optional.
|
|
56
|
-
:type organization: NotRequired[str]
|
|
11
|
+
api_key: str
|
|
57
12
|
|
|
58
|
-
.. admonition:: Example:
|
|
59
13
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
:end-before: [END create_OAI_model_config]
|
|
63
|
-
:language: python
|
|
64
|
-
:dedent: 8
|
|
65
|
-
:caption: Creating an OpenAIModelConfiguration object.
|
|
14
|
+
class AzureOpenAIModelConfiguration(AzureOpenAIModelConfigurationBase, total=False):
|
|
15
|
+
api_version: str
|
|
66
16
|
|
|
67
|
-
"""
|
|
68
17
|
|
|
69
|
-
|
|
18
|
+
class OpenAIModelConfiguration(TypedDict):
|
|
70
19
|
api_key: str
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
organization: NotRequired[str]
|
|
20
|
+
base_url: str
|
|
21
|
+
organization: str
|
|
74
22
|
|
|
75
23
|
|
|
76
24
|
class AzureAIProject(TypedDict):
|
|
77
|
-
"""Information about the Azure AI project
|
|
78
|
-
|
|
79
|
-
:param subscription_id: ID of the Azure subscription the project is in
|
|
80
|
-
:type subscription_id: str
|
|
81
|
-
:param resource_group_name: Name of the Azure resource group the project is in
|
|
82
|
-
:type resource_group_name: str
|
|
83
|
-
:param project_name: Name of the Azure project
|
|
84
|
-
:type project_name: str
|
|
85
|
-
|
|
86
|
-
.. admonition:: Example:
|
|
87
|
-
|
|
88
|
-
.. literalinclude:: ../samples/evaluation_samples_common.py
|
|
89
|
-
:start-after: [START create_azure_ai_project_object]
|
|
90
|
-
:end-before: [END create_azure_ai_project_object]
|
|
91
|
-
:language: python
|
|
92
|
-
:dedent: 8
|
|
93
|
-
:caption: Creating an AzureAIProject object.
|
|
94
|
-
|
|
95
|
-
"""
|
|
96
|
-
|
|
97
25
|
subscription_id: str
|
|
98
26
|
resource_group_name: str
|
|
99
27
|
project_name: str
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
class EvaluatorConfig(TypedDict, total=False):
|
|
103
|
-
"""Configuration for an evaluator"""
|
|
104
|
-
|
|
105
|
-
column_mapping: Dict[str, str]
|
|
106
|
-
"""Dictionary mapping evaluator input name to column in data"""
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
class Message(TypedDict):
|
|
110
|
-
role: str
|
|
111
|
-
content: Union[str, List[Dict]]
|
|
112
|
-
context: NotRequired[Dict[str, Any]]
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
class Conversation(TypedDict):
|
|
116
|
-
messages: Union[List[Message], List[Dict]]
|
|
117
|
-
context: NotRequired[Dict[str, Any]]
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
class EvaluationResult(TypedDict):
|
|
121
|
-
metrics: Dict
|
|
122
|
-
studio_url: NotRequired[str]
|
|
123
|
-
rows: List[Dict]
|
azure/ai/evaluation/_version.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from ._adversarial_scenario import AdversarialScenario
|
|
1
|
+
from ._adversarial_scenario import AdversarialScenario
|
|
2
2
|
from ._adversarial_simulator import AdversarialSimulator
|
|
3
3
|
from ._constants import SupportedLanguages
|
|
4
4
|
from ._direct_attack_simulator import DirectAttackSimulator
|
|
@@ -8,7 +8,6 @@ from ._simulator import Simulator
|
|
|
8
8
|
__all__ = [
|
|
9
9
|
"AdversarialSimulator",
|
|
10
10
|
"AdversarialScenario",
|
|
11
|
-
"AdversarialScenarioJailbreak",
|
|
12
11
|
"DirectAttackSimulator",
|
|
13
12
|
"IndirectAttackSimulator",
|
|
14
13
|
"SupportedLanguages",
|
|
@@ -3,22 +3,10 @@
|
|
|
3
3
|
# ---------------------------------------------------------
|
|
4
4
|
|
|
5
5
|
from enum import Enum
|
|
6
|
-
from azure.ai.evaluation._common._experimental import experimental
|
|
7
6
|
|
|
8
7
|
|
|
9
|
-
@experimental
|
|
10
8
|
class AdversarialScenario(Enum):
|
|
11
|
-
"""Adversarial scenario types
|
|
12
|
-
|
|
13
|
-
.. admonition:: Example:
|
|
14
|
-
|
|
15
|
-
.. literalinclude:: ../samples/evaluation_samples_simulate.py
|
|
16
|
-
:start-after: [START adversarial_scenario]
|
|
17
|
-
:end-before: [END adversarial_scenario]
|
|
18
|
-
:language: python
|
|
19
|
-
:dedent: 8
|
|
20
|
-
:caption: Configure an AdversarialSimulator with an Adversarial Conversation scenario.
|
|
21
|
-
"""
|
|
9
|
+
"""Adversarial scenario types"""
|
|
22
10
|
|
|
23
11
|
ADVERSARIAL_QA = "adv_qa"
|
|
24
12
|
ADVERSARIAL_CONVERSATION = "adv_conversation"
|
|
@@ -28,16 +16,9 @@ class AdversarialScenario(Enum):
|
|
|
28
16
|
ADVERSARIAL_CONTENT_GEN_UNGROUNDED = "adv_content_gen_ungrounded"
|
|
29
17
|
ADVERSARIAL_CONTENT_GEN_GROUNDED = "adv_content_gen_grounded"
|
|
30
18
|
ADVERSARIAL_CONTENT_PROTECTED_MATERIAL = "adv_content_protected_material"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
@experimental
|
|
34
|
-
class AdversarialScenarioJailbreak(Enum):
|
|
35
|
-
"""Adversarial scenario types for XPIA Jailbreak"""
|
|
36
|
-
|
|
37
19
|
ADVERSARIAL_INDIRECT_JAILBREAK = "adv_xpia"
|
|
38
20
|
|
|
39
21
|
|
|
40
|
-
@experimental
|
|
41
22
|
class _UnstableAdversarialScenario(Enum):
|
|
42
23
|
"""Adversarial scenario types that we haven't published, but still want available for internal use
|
|
43
24
|
Values listed here are subject to potential change, and/or migration to the main enum over time.
|