azure-ai-evaluation 0.0.0b0__py3-none-any.whl → 1.0.0__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.
Files changed (122) hide show
  1. azure/ai/evaluation/__init__.py +82 -0
  2. azure/ai/evaluation/_common/__init__.py +16 -0
  3. azure/ai/evaluation/_common/_experimental.py +172 -0
  4. azure/ai/evaluation/_common/constants.py +72 -0
  5. azure/ai/evaluation/_common/math.py +89 -0
  6. azure/ai/evaluation/_common/rai_service.py +632 -0
  7. azure/ai/evaluation/_common/utils.py +445 -0
  8. azure/ai/evaluation/_constants.py +72 -0
  9. azure/ai/evaluation/_evaluate/__init__.py +3 -0
  10. azure/ai/evaluation/_evaluate/_batch_run/__init__.py +9 -0
  11. azure/ai/evaluation/_evaluate/_batch_run/code_client.py +188 -0
  12. azure/ai/evaluation/_evaluate/_batch_run/eval_run_context.py +89 -0
  13. azure/ai/evaluation/_evaluate/_batch_run/proxy_client.py +99 -0
  14. azure/ai/evaluation/_evaluate/_batch_run/target_run_context.py +46 -0
  15. azure/ai/evaluation/_evaluate/_eval_run.py +571 -0
  16. azure/ai/evaluation/_evaluate/_evaluate.py +850 -0
  17. azure/ai/evaluation/_evaluate/_telemetry/__init__.py +179 -0
  18. azure/ai/evaluation/_evaluate/_utils.py +298 -0
  19. azure/ai/evaluation/_evaluators/__init__.py +3 -0
  20. azure/ai/evaluation/_evaluators/_bleu/__init__.py +9 -0
  21. azure/ai/evaluation/_evaluators/_bleu/_bleu.py +72 -0
  22. azure/ai/evaluation/_evaluators/_coherence/__init__.py +7 -0
  23. azure/ai/evaluation/_evaluators/_coherence/_coherence.py +107 -0
  24. azure/ai/evaluation/_evaluators/_coherence/coherence.prompty +99 -0
  25. azure/ai/evaluation/_evaluators/_common/__init__.py +13 -0
  26. azure/ai/evaluation/_evaluators/_common/_base_eval.py +344 -0
  27. azure/ai/evaluation/_evaluators/_common/_base_prompty_eval.py +88 -0
  28. azure/ai/evaluation/_evaluators/_common/_base_rai_svc_eval.py +133 -0
  29. azure/ai/evaluation/_evaluators/_content_safety/__init__.py +17 -0
  30. azure/ai/evaluation/_evaluators/_content_safety/_content_safety.py +144 -0
  31. azure/ai/evaluation/_evaluators/_content_safety/_hate_unfairness.py +129 -0
  32. azure/ai/evaluation/_evaluators/_content_safety/_self_harm.py +123 -0
  33. azure/ai/evaluation/_evaluators/_content_safety/_sexual.py +125 -0
  34. azure/ai/evaluation/_evaluators/_content_safety/_violence.py +126 -0
  35. azure/ai/evaluation/_evaluators/_eci/__init__.py +0 -0
  36. azure/ai/evaluation/_evaluators/_eci/_eci.py +89 -0
  37. azure/ai/evaluation/_evaluators/_f1_score/__init__.py +9 -0
  38. azure/ai/evaluation/_evaluators/_f1_score/_f1_score.py +157 -0
  39. azure/ai/evaluation/_evaluators/_fluency/__init__.py +9 -0
  40. azure/ai/evaluation/_evaluators/_fluency/_fluency.py +104 -0
  41. azure/ai/evaluation/_evaluators/_fluency/fluency.prompty +86 -0
  42. azure/ai/evaluation/_evaluators/_gleu/__init__.py +9 -0
  43. azure/ai/evaluation/_evaluators/_gleu/_gleu.py +69 -0
  44. azure/ai/evaluation/_evaluators/_groundedness/__init__.py +9 -0
  45. azure/ai/evaluation/_evaluators/_groundedness/_groundedness.py +144 -0
  46. azure/ai/evaluation/_evaluators/_groundedness/groundedness_with_query.prompty +113 -0
  47. azure/ai/evaluation/_evaluators/_groundedness/groundedness_without_query.prompty +99 -0
  48. azure/ai/evaluation/_evaluators/_meteor/__init__.py +9 -0
  49. azure/ai/evaluation/_evaluators/_meteor/_meteor.py +90 -0
  50. azure/ai/evaluation/_evaluators/_multimodal/__init__.py +20 -0
  51. azure/ai/evaluation/_evaluators/_multimodal/_content_safety_multimodal.py +132 -0
  52. azure/ai/evaluation/_evaluators/_multimodal/_content_safety_multimodal_base.py +55 -0
  53. azure/ai/evaluation/_evaluators/_multimodal/_hate_unfairness.py +100 -0
  54. azure/ai/evaluation/_evaluators/_multimodal/_protected_material.py +124 -0
  55. azure/ai/evaluation/_evaluators/_multimodal/_self_harm.py +100 -0
  56. azure/ai/evaluation/_evaluators/_multimodal/_sexual.py +100 -0
  57. azure/ai/evaluation/_evaluators/_multimodal/_violence.py +100 -0
  58. azure/ai/evaluation/_evaluators/_protected_material/__init__.py +5 -0
  59. azure/ai/evaluation/_evaluators/_protected_material/_protected_material.py +113 -0
  60. azure/ai/evaluation/_evaluators/_qa/__init__.py +9 -0
  61. azure/ai/evaluation/_evaluators/_qa/_qa.py +93 -0
  62. azure/ai/evaluation/_evaluators/_relevance/__init__.py +9 -0
  63. azure/ai/evaluation/_evaluators/_relevance/_relevance.py +114 -0
  64. azure/ai/evaluation/_evaluators/_relevance/relevance.prompty +100 -0
  65. azure/ai/evaluation/_evaluators/_retrieval/__init__.py +9 -0
  66. azure/ai/evaluation/_evaluators/_retrieval/_retrieval.py +112 -0
  67. azure/ai/evaluation/_evaluators/_retrieval/retrieval.prompty +93 -0
  68. azure/ai/evaluation/_evaluators/_rouge/__init__.py +10 -0
  69. azure/ai/evaluation/_evaluators/_rouge/_rouge.py +98 -0
  70. azure/ai/evaluation/_evaluators/_service_groundedness/__init__.py +9 -0
  71. azure/ai/evaluation/_evaluators/_service_groundedness/_service_groundedness.py +148 -0
  72. azure/ai/evaluation/_evaluators/_similarity/__init__.py +9 -0
  73. azure/ai/evaluation/_evaluators/_similarity/_similarity.py +140 -0
  74. azure/ai/evaluation/_evaluators/_similarity/similarity.prompty +66 -0
  75. azure/ai/evaluation/_evaluators/_xpia/__init__.py +5 -0
  76. azure/ai/evaluation/_evaluators/_xpia/xpia.py +125 -0
  77. azure/ai/evaluation/_exceptions.py +128 -0
  78. azure/ai/evaluation/_http_utils.py +466 -0
  79. azure/ai/evaluation/_model_configurations.py +123 -0
  80. azure/ai/evaluation/_user_agent.py +6 -0
  81. azure/ai/evaluation/_vendor/__init__.py +3 -0
  82. azure/ai/evaluation/_vendor/rouge_score/__init__.py +14 -0
  83. azure/ai/evaluation/_vendor/rouge_score/rouge_scorer.py +328 -0
  84. azure/ai/evaluation/_vendor/rouge_score/scoring.py +63 -0
  85. azure/ai/evaluation/_vendor/rouge_score/tokenize.py +63 -0
  86. azure/ai/evaluation/_vendor/rouge_score/tokenizers.py +53 -0
  87. azure/ai/evaluation/_version.py +5 -0
  88. azure/ai/evaluation/py.typed +0 -0
  89. azure/ai/evaluation/simulator/__init__.py +16 -0
  90. azure/ai/evaluation/simulator/_adversarial_scenario.py +46 -0
  91. azure/ai/evaluation/simulator/_adversarial_simulator.py +471 -0
  92. azure/ai/evaluation/simulator/_constants.py +27 -0
  93. azure/ai/evaluation/simulator/_conversation/__init__.py +316 -0
  94. azure/ai/evaluation/simulator/_conversation/_conversation.py +178 -0
  95. azure/ai/evaluation/simulator/_conversation/constants.py +30 -0
  96. azure/ai/evaluation/simulator/_data_sources/__init__.py +3 -0
  97. azure/ai/evaluation/simulator/_data_sources/grounding.json +1150 -0
  98. azure/ai/evaluation/simulator/_direct_attack_simulator.py +218 -0
  99. azure/ai/evaluation/simulator/_helpers/__init__.py +4 -0
  100. azure/ai/evaluation/simulator/_helpers/_language_suffix_mapping.py +17 -0
  101. azure/ai/evaluation/simulator/_helpers/_simulator_data_classes.py +96 -0
  102. azure/ai/evaluation/simulator/_indirect_attack_simulator.py +220 -0
  103. azure/ai/evaluation/simulator/_model_tools/__init__.py +23 -0
  104. azure/ai/evaluation/simulator/_model_tools/_identity_manager.py +195 -0
  105. azure/ai/evaluation/simulator/_model_tools/_proxy_completion_model.py +244 -0
  106. azure/ai/evaluation/simulator/_model_tools/_rai_client.py +168 -0
  107. azure/ai/evaluation/simulator/_model_tools/_template_handler.py +201 -0
  108. azure/ai/evaluation/simulator/_model_tools/models.py +614 -0
  109. azure/ai/evaluation/simulator/_prompty/__init__.py +0 -0
  110. azure/ai/evaluation/simulator/_prompty/task_query_response.prompty +65 -0
  111. azure/ai/evaluation/simulator/_prompty/task_simulate.prompty +37 -0
  112. azure/ai/evaluation/simulator/_simulator.py +716 -0
  113. azure/ai/evaluation/simulator/_tracing.py +89 -0
  114. azure/ai/evaluation/simulator/_utils.py +132 -0
  115. azure_ai_evaluation-1.0.0.dist-info/METADATA +595 -0
  116. azure_ai_evaluation-1.0.0.dist-info/NOTICE.txt +70 -0
  117. azure_ai_evaluation-1.0.0.dist-info/RECORD +119 -0
  118. {azure_ai_evaluation-0.0.0b0.dist-info → azure_ai_evaluation-1.0.0.dist-info}/WHEEL +1 -1
  119. azure_ai_evaluation-1.0.0.dist-info/top_level.txt +1 -0
  120. azure_ai_evaluation-0.0.0b0.dist-info/METADATA +0 -7
  121. azure_ai_evaluation-0.0.0b0.dist-info/RECORD +0 -4
  122. azure_ai_evaluation-0.0.0b0.dist-info/top_level.txt +0 -1
@@ -0,0 +1,466 @@
1
+ # ---------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # ---------------------------------------------------------
4
+
5
+
6
+ from typing import Any, Dict, MutableMapping, Optional, TypedDict, cast
7
+
8
+ from typing_extensions import Self, Unpack
9
+
10
+ from azure.ai.evaluation._user_agent import USER_AGENT
11
+ from azure.core.configuration import Configuration
12
+ from azure.core.pipeline import AsyncPipeline, Pipeline
13
+ from azure.core.pipeline.policies import (
14
+ AsyncRedirectPolicy,
15
+ AsyncRetryPolicy,
16
+ CustomHookPolicy,
17
+ HeadersPolicy,
18
+ HttpLoggingPolicy,
19
+ NetworkTraceLoggingPolicy,
20
+ ProxyPolicy,
21
+ RedirectPolicy,
22
+ RetryPolicy,
23
+ UserAgentPolicy,
24
+ )
25
+ from azure.core.pipeline.transport import ( # pylint: disable=non-abstract-transport-import,no-name-in-module
26
+ AsyncHttpTransport,
27
+ AsyncioRequestsTransport,
28
+ HttpTransport,
29
+ RequestsTransport,
30
+ )
31
+ from azure.core.rest import AsyncHttpResponse, HttpRequest, HttpResponse
32
+ from azure.core.rest._rest_py3 import ContentType, FilesType, ParamsType
33
+
34
+
35
+ class RequestKwargs(TypedDict, total=False):
36
+ """Keyword arguments for request-style http request functions
37
+
38
+ .. note::
39
+
40
+ Ideally, we'd be able to express that these are the known subset of kwargs, but it's possible to provide
41
+ others. But that currently isn't possible; there's no way currently to express a TypedDict that expects
42
+ a known set of keys and an unknown set of keys.
43
+
44
+ PEP 728 - TypedDict with Typed Extra Items (https://peps.python.org/pep-0728/) would rectify this but it's
45
+ still in Draft status.
46
+ """
47
+
48
+ params: ParamsType
49
+ headers: MutableMapping[str, str]
50
+ json: Any
51
+ content: ContentType
52
+ data: Dict[str, Any]
53
+ files: FilesType
54
+
55
+
56
+ class HttpPipeline(Pipeline):
57
+ """A *very* thin wrapper over azure.core.pipeline.Pipeline that facilitates sending miscellaneous http requests by
58
+ adding:
59
+
60
+ * A requests-style api for sending http requests
61
+ * Facilities for populating policies for the client, include defaults,
62
+ and re-using policies from an existing client.
63
+ """
64
+
65
+ def __init__(
66
+ self,
67
+ *,
68
+ transport: Optional[HttpTransport] = None,
69
+ config: Optional[Configuration] = None,
70
+ user_agent_policy: Optional[UserAgentPolicy] = None,
71
+ headers_policy: Optional[HeadersPolicy] = None,
72
+ proxy_policy: Optional[ProxyPolicy] = None,
73
+ logging_policy: Optional[NetworkTraceLoggingPolicy] = None,
74
+ http_logging_policy: Optional[HttpLoggingPolicy] = None,
75
+ retry_policy: Optional[RetryPolicy] = None,
76
+ custom_hook_policy: Optional[CustomHookPolicy] = None,
77
+ redirect_policy: Optional[RedirectPolicy] = None,
78
+ **kwargs,
79
+ ):
80
+ """
81
+
82
+ :param HttpTransport transport: Http Transport used for requests, defaults to RequestsTransport
83
+ :param Configuration config:
84
+ :param UserAgentPolicy user_agent_policy:
85
+ :param HeadersPolicy headers_policy:
86
+ :param ProxyPolicy proxy_policy:
87
+ :param NetworkTraceLoggingPolicy logging_policy:
88
+ :param HttpLoggingPolicy http_logging_policy:
89
+ :param RetryPolicy retry_policy:
90
+ :param CustomHookPolicy custom_hook_policy:
91
+ :param RedirectPolicy redirect_policy:
92
+ """
93
+ config = config or Configuration()
94
+ config.headers_policy = (
95
+ headers_policy or cast(Optional[HeadersPolicy], config.headers_policy) or HeadersPolicy(**kwargs)
96
+ )
97
+ config.proxy_policy = proxy_policy or cast(Optional[ProxyPolicy], config.proxy_policy) or ProxyPolicy(**kwargs)
98
+ config.redirect_policy = (
99
+ redirect_policy or cast(Optional[RedirectPolicy], config.redirect_policy) or RedirectPolicy(**kwargs)
100
+ )
101
+ config.retry_policy = retry_policy or cast(Optional[RetryPolicy], config.retry_policy) or RetryPolicy(**kwargs)
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
+ )
120
+ config.polling_interval = kwargs.get("polling_interval", 30)
121
+
122
+ super().__init__(
123
+ # RequestsTransport normally should not be imported outside of azure.core, since transports
124
+ # are meant to be user configurable.
125
+ # RequestsTransport is only used in this file as the default transport when not user specified.
126
+ transport=transport or RequestsTransport(**kwargs),
127
+ policies=[
128
+ config.headers_policy,
129
+ config.user_agent_policy,
130
+ config.proxy_policy,
131
+ config.redirect_policy,
132
+ config.retry_policy,
133
+ config.custom_hook_policy,
134
+ config.logging_policy,
135
+ ],
136
+ )
137
+
138
+ self._config = config
139
+
140
+ def with_policies(self, **kwargs) -> Self:
141
+ """A named constructor which facilitates creating a new pipeline using an existing one as a base.
142
+
143
+ Accepts the same parameters as __init__
144
+
145
+ :return: new Pipeline object with combined config of current object
146
+ and specified overrides
147
+ :rtype: Self
148
+ """
149
+ cls = self.__class__
150
+ return cls(config=self._config, transport=kwargs.pop("transport", self._transport), **kwargs)
151
+
152
+ def request(
153
+ self,
154
+ method: str,
155
+ url: str,
156
+ *,
157
+ params: Optional[ParamsType] = None,
158
+ headers: Optional[MutableMapping[str, str]] = None,
159
+ json: Any = None,
160
+ content: Optional[ContentType] = None,
161
+ data: Optional[Dict[str, Any]] = None,
162
+ files: Optional[FilesType] = None,
163
+ **kwargs,
164
+ ) -> HttpResponse:
165
+ request = HttpRequest(
166
+ method,
167
+ url,
168
+ params=params,
169
+ headers=headers,
170
+ json=json,
171
+ content=content,
172
+ data=data,
173
+ files=files,
174
+ )
175
+
176
+ return self.run(request, **kwargs).http_response
177
+
178
+ def delete(self: "HttpPipeline", url: str, **kwargs: Unpack[RequestKwargs]) -> HttpResponse:
179
+ """Send a DELETE request.
180
+
181
+ :param str url: The request url
182
+ :returns: The request response
183
+ :rtype: HttpResponse
184
+ """
185
+
186
+ return self.request(self.delete.__name__.upper(), url, **kwargs)
187
+
188
+ def put(self: "HttpPipeline", url: str, **kwargs: Unpack[RequestKwargs]) -> HttpResponse:
189
+ """Send a PUT request.
190
+
191
+ :param str url: The request url
192
+ :returns: The request response
193
+ :rtype: HttpResponse
194
+ """
195
+
196
+ return self.request(self.put.__name__.upper(), url, **kwargs)
197
+
198
+ def get(self: "HttpPipeline", url: str, **kwargs: Unpack[RequestKwargs]) -> HttpResponse:
199
+ """Send a GET request.
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__())
250
+
251
+
252
+ class AsyncHttpPipeline(AsyncPipeline):
253
+ """A *very* thin wrapper over azure.core.pipeline.AsyncPipeline that facilitates sending miscellaneous
254
+ http requests by adding:
255
+
256
+ * A requests-style api for sending http requests
257
+ * Facilities for populating policies for the client, include defaults,
258
+ and re-using policies from an existing client.
259
+ """
260
+
261
+ def __init__(
262
+ self,
263
+ *,
264
+ transport: Optional[AsyncHttpTransport] = None,
265
+ config: Optional[Configuration] = None,
266
+ user_agent_policy: Optional[UserAgentPolicy] = None,
267
+ headers_policy: Optional[HeadersPolicy] = None,
268
+ proxy_policy: Optional[ProxyPolicy] = None,
269
+ logging_policy: Optional[NetworkTraceLoggingPolicy] = None,
270
+ http_logging_policy: Optional[HttpLoggingPolicy] = None,
271
+ retry_policy: Optional[AsyncRetryPolicy] = None,
272
+ custom_hook_policy: Optional[CustomHookPolicy] = None,
273
+ redirect_policy: Optional[AsyncRedirectPolicy] = None,
274
+ **kwargs,
275
+ ):
276
+ """
277
+
278
+ :param HttpTransport transport: Http Transport used for requests, defaults to RequestsTransport
279
+ :param Configuration config:
280
+ :param UserAgentPolicy user_agent_policy:
281
+ :param HeadersPolicy headers_policy:
282
+ :param ProxyPolicy proxy_policy:
283
+ :param NetworkTraceLoggingPolicy logging_policy:
284
+ :param HttpLoggingPolicy http_logging_policy:
285
+ :param AsyncRetryPolicy retry_policy:
286
+ :param CustomHookPolicy custom_hook_policy:
287
+ :param AsyncRedirectPolicy redirect_policy:
288
+ """
289
+ config = config or Configuration()
290
+ config.headers_policy = (
291
+ headers_policy or cast(Optional[HeadersPolicy], config.headers_policy) or HeadersPolicy(**kwargs)
292
+ )
293
+ config.proxy_policy = proxy_policy or cast(Optional[ProxyPolicy], config.proxy_policy) or ProxyPolicy(**kwargs)
294
+ config.redirect_policy = (
295
+ redirect_policy
296
+ or cast(Optional[AsyncRedirectPolicy], config.redirect_policy)
297
+ or AsyncRedirectPolicy(**kwargs)
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
+ )
320
+ config.polling_interval = kwargs.get("polling_interval", 30)
321
+
322
+ super().__init__(
323
+ # AsyncioRequestsTransport normally should not be imported outside of azure.core, since transports
324
+ # are meant to be user configurable.
325
+ # AsyncioRequestsTransport is only used in this file as the default transport when not user specified.
326
+ transport=transport or AsyncioRequestsTransport(**kwargs),
327
+ policies=[
328
+ config.headers_policy,
329
+ config.user_agent_policy,
330
+ config.proxy_policy,
331
+ config.redirect_policy,
332
+ config.retry_policy,
333
+ config.custom_hook_policy,
334
+ config.logging_policy,
335
+ ],
336
+ )
337
+
338
+ self._config = config
339
+
340
+ def with_policies(self, **kwargs) -> Self:
341
+ """A named constructor which facilitates creating a new pipeline using an existing one as a base.
342
+
343
+ Accepts the same parameters as __init__
344
+
345
+ :return: new Pipeline object with combined config of current object
346
+ and specified overrides
347
+ :rtype: Self
348
+ """
349
+ cls = self.__class__
350
+ return cls(config=self._config, transport=kwargs.pop("transport", self._transport), **kwargs)
351
+
352
+ async def request(
353
+ self,
354
+ method: str,
355
+ url: str,
356
+ *,
357
+ params: Optional[ParamsType] = None,
358
+ headers: Optional[MutableMapping[str, str]] = None,
359
+ json: Any = None,
360
+ content: Optional[ContentType] = None,
361
+ data: Optional[Dict[str, Any]] = None,
362
+ files: Optional[FilesType] = None,
363
+ **kwargs,
364
+ ) -> AsyncHttpResponse:
365
+ request = HttpRequest(
366
+ method,
367
+ url,
368
+ params=params,
369
+ headers=headers,
370
+ json=json,
371
+ content=content,
372
+ data=data,
373
+ files=files,
374
+ )
375
+
376
+ return (await self.run(request, **kwargs)).http_response
377
+
378
+ async def delete(self: "AsyncHttpPipeline", url: str, **kwargs: Unpack[RequestKwargs]) -> AsyncHttpResponse:
379
+ """Send a DELETE request.
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.
419
+
420
+ :param str url: The request url
421
+ :returns: The request response
422
+ :rtype: AsyncHttpResponse
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.
429
+
430
+ :param str url: The request url
431
+ :returns: The request response
432
+ :rtype: AsyncHttpResponse
433
+ """
434
+
435
+ return await self.request(self.options.__name__.upper(), url, **kwargs)
436
+
437
+ async def patch(self: "AsyncHttpPipeline", url: str, **kwargs: Unpack[RequestKwargs]) -> AsyncHttpResponse:
438
+ """Send a PATCH request.
439
+
440
+ :param str url: The request url
441
+ :returns: The request response
442
+ :rtype: AsyncHttpResponse
443
+ """
444
+
445
+ return await self.request(self.patch.__name__.upper(), url, **kwargs)
446
+
447
+ async def __aenter__(self) -> Self:
448
+ return cast(Self, await super().__aenter__())
449
+
450
+
451
+ def get_http_client() -> HttpPipeline:
452
+ """Get an HttpPipeline configured with common policies.
453
+
454
+ :returns: An HttpPipeline with a set of applied policies:
455
+ :rtype: HttpPipeline
456
+ """
457
+ return HttpPipeline(user_agent_policy=UserAgentPolicy(base_user_agent=USER_AGENT))
458
+
459
+
460
+ def get_async_http_client() -> AsyncHttpPipeline:
461
+ """Get an AsyncHttpPipeline configured with common policies.
462
+
463
+ :returns: An AsyncHttpPipeline with a set of applied policies:
464
+ :rtype: AsyncHttpPipeline
465
+ """
466
+ return AsyncHttpPipeline(user_agent_policy=UserAgentPolicy(base_user_agent=USER_AGENT))
@@ -0,0 +1,123 @@
1
+ # ---------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # ---------------------------------------------------------
4
+
5
+ from typing import Any, Dict, List, Literal, TypedDict, Union
6
+
7
+ from typing_extensions import NotRequired
8
+
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"]]
36
+ azure_deployment: str
37
+ azure_endpoint: str
38
+ """Endpoint of Azure OpenAI resource to make request to"""
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]
57
+
58
+ .. admonition:: Example:
59
+
60
+ .. literalinclude:: ../samples/evaluation_samples_common.py
61
+ :start-after: [START create_OAI_model_config]
62
+ :end-before: [END create_OAI_model_config]
63
+ :language: python
64
+ :dedent: 8
65
+ :caption: Creating an OpenAIModelConfiguration object.
66
+
67
+ """
68
+
69
+ type: NotRequired[Literal["openai"]]
70
+ api_key: str
71
+ model: str
72
+ base_url: NotRequired[str]
73
+ organization: NotRequired[str]
74
+
75
+
76
+ 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
+ subscription_id: str
98
+ resource_group_name: str
99
+ 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]
@@ -0,0 +1,6 @@
1
+ # ---------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # ---------------------------------------------------------
4
+ from azure.ai.evaluation._version import VERSION
5
+
6
+ USER_AGENT = "{}/{}".format("azure-ai-evaluation", VERSION)
@@ -0,0 +1,3 @@
1
+ # ---------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # ---------------------------------------------------------
@@ -0,0 +1,14 @@
1
+ # coding=utf-8
2
+ # Copyright 2024 The Google Research Authors.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.