azure-ai-evaluation 1.0.0__py3-none-any.whl → 1.0.0b1__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.

Files changed (108) hide show
  1. azure/ai/evaluation/__init__.py +4 -26
  2. azure/ai/evaluation/_common/constants.py +2 -9
  3. azure/ai/evaluation/_common/rai_service.py +122 -302
  4. azure/ai/evaluation/_common/utils.py +35 -393
  5. azure/ai/evaluation/_constants.py +6 -28
  6. azure/ai/evaluation/_evaluate/{_batch_run → _batch_run_client}/__init__.py +2 -3
  7. azure/ai/evaluation/_evaluate/{_batch_run/eval_run_context.py → _batch_run_client/batch_run_context.py} +8 -25
  8. azure/ai/evaluation/_evaluate/{_batch_run → _batch_run_client}/code_client.py +30 -68
  9. azure/ai/evaluation/_evaluate/_batch_run_client/proxy_client.py +61 -0
  10. azure/ai/evaluation/_evaluate/_eval_run.py +40 -117
  11. azure/ai/evaluation/_evaluate/_evaluate.py +255 -416
  12. azure/ai/evaluation/_evaluate/_telemetry/__init__.py +19 -24
  13. azure/ai/evaluation/_evaluate/_utils.py +47 -108
  14. azure/ai/evaluation/_evaluators/_bleu/_bleu.py +19 -18
  15. azure/ai/evaluation/_evaluators/{_retrieval → _chat}/__init__.py +2 -2
  16. azure/ai/evaluation/_evaluators/_chat/_chat.py +350 -0
  17. azure/ai/evaluation/_evaluators/{_service_groundedness → _chat/retrieval}/__init__.py +2 -2
  18. azure/ai/evaluation/_evaluators/_chat/retrieval/_retrieval.py +163 -0
  19. azure/ai/evaluation/_evaluators/_chat/retrieval/retrieval.prompty +48 -0
  20. azure/ai/evaluation/_evaluators/_coherence/_coherence.py +93 -78
  21. azure/ai/evaluation/_evaluators/_coherence/coherence.prompty +39 -76
  22. azure/ai/evaluation/_evaluators/_content_safety/__init__.py +4 -0
  23. azure/ai/evaluation/_evaluators/_content_safety/_content_safety.py +68 -104
  24. azure/ai/evaluation/_evaluators/{_multimodal/_content_safety_multimodal_base.py → _content_safety/_content_safety_base.py} +35 -24
  25. azure/ai/evaluation/_evaluators/_content_safety/_content_safety_chat.py +296 -0
  26. azure/ai/evaluation/_evaluators/_content_safety/_hate_unfairness.py +54 -105
  27. azure/ai/evaluation/_evaluators/_content_safety/_self_harm.py +52 -99
  28. azure/ai/evaluation/_evaluators/_content_safety/_sexual.py +52 -101
  29. azure/ai/evaluation/_evaluators/_content_safety/_violence.py +51 -101
  30. azure/ai/evaluation/_evaluators/_eci/_eci.py +55 -45
  31. azure/ai/evaluation/_evaluators/_f1_score/_f1_score.py +20 -36
  32. azure/ai/evaluation/_evaluators/_fluency/_fluency.py +94 -76
  33. azure/ai/evaluation/_evaluators/_fluency/fluency.prompty +41 -66
  34. azure/ai/evaluation/_evaluators/_gleu/_gleu.py +17 -15
  35. azure/ai/evaluation/_evaluators/_groundedness/_groundedness.py +92 -113
  36. azure/ai/evaluation/_evaluators/_groundedness/groundedness.prompty +54 -0
  37. azure/ai/evaluation/_evaluators/_meteor/_meteor.py +27 -21
  38. azure/ai/evaluation/_evaluators/_protected_material/_protected_material.py +80 -89
  39. azure/ai/evaluation/_evaluators/_protected_materials/__init__.py +5 -0
  40. azure/ai/evaluation/_evaluators/_protected_materials/_protected_materials.py +104 -0
  41. azure/ai/evaluation/_evaluators/_qa/_qa.py +43 -25
  42. azure/ai/evaluation/_evaluators/_relevance/_relevance.py +101 -84
  43. azure/ai/evaluation/_evaluators/_relevance/relevance.prompty +47 -78
  44. azure/ai/evaluation/_evaluators/_rouge/_rouge.py +27 -27
  45. azure/ai/evaluation/_evaluators/_similarity/_similarity.py +45 -55
  46. azure/ai/evaluation/_evaluators/_similarity/similarity.prompty +5 -0
  47. azure/ai/evaluation/_evaluators/_xpia/xpia.py +106 -91
  48. azure/ai/evaluation/_exceptions.py +7 -28
  49. azure/ai/evaluation/_http_utils.py +134 -205
  50. azure/ai/evaluation/_model_configurations.py +8 -104
  51. azure/ai/evaluation/_version.py +1 -1
  52. azure/ai/evaluation/simulator/__init__.py +2 -3
  53. azure/ai/evaluation/simulator/_adversarial_scenario.py +1 -20
  54. azure/ai/evaluation/simulator/_adversarial_simulator.py +95 -116
  55. azure/ai/evaluation/simulator/_constants.py +1 -11
  56. azure/ai/evaluation/simulator/_conversation/__init__.py +13 -14
  57. azure/ai/evaluation/simulator/_conversation/_conversation.py +20 -20
  58. azure/ai/evaluation/simulator/_direct_attack_simulator.py +68 -34
  59. azure/ai/evaluation/simulator/_helpers/__init__.py +1 -1
  60. azure/ai/evaluation/simulator/_helpers/_simulator_data_classes.py +28 -31
  61. azure/ai/evaluation/simulator/_indirect_attack_simulator.py +95 -108
  62. azure/ai/evaluation/simulator/_model_tools/_identity_manager.py +22 -70
  63. azure/ai/evaluation/simulator/_model_tools/_proxy_completion_model.py +14 -30
  64. azure/ai/evaluation/simulator/_model_tools/_rai_client.py +14 -25
  65. azure/ai/evaluation/simulator/_model_tools/_template_handler.py +24 -68
  66. azure/ai/evaluation/simulator/_model_tools/models.py +21 -19
  67. azure/ai/evaluation/simulator/_prompty/task_query_response.prompty +10 -6
  68. azure/ai/evaluation/simulator/_prompty/task_simulate.prompty +5 -6
  69. azure/ai/evaluation/simulator/_tracing.py +28 -25
  70. azure/ai/evaluation/simulator/_utils.py +13 -34
  71. azure/ai/evaluation/simulator/simulator.py +579 -0
  72. azure_ai_evaluation-1.0.0b1.dist-info/METADATA +377 -0
  73. azure_ai_evaluation-1.0.0b1.dist-info/RECORD +97 -0
  74. {azure_ai_evaluation-1.0.0.dist-info → azure_ai_evaluation-1.0.0b1.dist-info}/WHEEL +1 -1
  75. azure/ai/evaluation/_common/_experimental.py +0 -172
  76. azure/ai/evaluation/_common/math.py +0 -89
  77. azure/ai/evaluation/_evaluate/_batch_run/proxy_client.py +0 -99
  78. azure/ai/evaluation/_evaluate/_batch_run/target_run_context.py +0 -46
  79. azure/ai/evaluation/_evaluators/_common/__init__.py +0 -13
  80. azure/ai/evaluation/_evaluators/_common/_base_eval.py +0 -344
  81. azure/ai/evaluation/_evaluators/_common/_base_prompty_eval.py +0 -88
  82. azure/ai/evaluation/_evaluators/_common/_base_rai_svc_eval.py +0 -133
  83. azure/ai/evaluation/_evaluators/_groundedness/groundedness_with_query.prompty +0 -113
  84. azure/ai/evaluation/_evaluators/_groundedness/groundedness_without_query.prompty +0 -99
  85. azure/ai/evaluation/_evaluators/_multimodal/__init__.py +0 -20
  86. azure/ai/evaluation/_evaluators/_multimodal/_content_safety_multimodal.py +0 -132
  87. azure/ai/evaluation/_evaluators/_multimodal/_hate_unfairness.py +0 -100
  88. azure/ai/evaluation/_evaluators/_multimodal/_protected_material.py +0 -124
  89. azure/ai/evaluation/_evaluators/_multimodal/_self_harm.py +0 -100
  90. azure/ai/evaluation/_evaluators/_multimodal/_sexual.py +0 -100
  91. azure/ai/evaluation/_evaluators/_multimodal/_violence.py +0 -100
  92. azure/ai/evaluation/_evaluators/_retrieval/_retrieval.py +0 -112
  93. azure/ai/evaluation/_evaluators/_retrieval/retrieval.prompty +0 -93
  94. azure/ai/evaluation/_evaluators/_service_groundedness/_service_groundedness.py +0 -148
  95. azure/ai/evaluation/_vendor/__init__.py +0 -3
  96. azure/ai/evaluation/_vendor/rouge_score/__init__.py +0 -14
  97. azure/ai/evaluation/_vendor/rouge_score/rouge_scorer.py +0 -328
  98. azure/ai/evaluation/_vendor/rouge_score/scoring.py +0 -63
  99. azure/ai/evaluation/_vendor/rouge_score/tokenize.py +0 -63
  100. azure/ai/evaluation/_vendor/rouge_score/tokenizers.py +0 -53
  101. azure/ai/evaluation/simulator/_data_sources/__init__.py +0 -3
  102. azure/ai/evaluation/simulator/_data_sources/grounding.json +0 -1150
  103. azure/ai/evaluation/simulator/_prompty/__init__.py +0 -0
  104. azure/ai/evaluation/simulator/_simulator.py +0 -716
  105. azure_ai_evaluation-1.0.0.dist-info/METADATA +0 -595
  106. azure_ai_evaluation-1.0.0.dist-info/NOTICE.txt +0 -70
  107. azure_ai_evaluation-1.0.0.dist-info/RECORD +0 -119
  108. {azure_ai_evaluation-1.0.0.dist-info → azure_ai_evaluation-1.0.0b1.dist-info}/top_level.txt +0 -0
@@ -1,595 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: azure-ai-evaluation
3
- Version: 1.0.0
4
- Summary: Microsoft Azure Evaluation Library for Python
5
- Home-page: https://github.com/Azure/azure-sdk-for-python
6
- Author: Microsoft Corporation
7
- Author-email: azuresdkengsysadmins@microsoft.com
8
- License: MIT License
9
- Project-URL: Bug Reports, https://github.com/Azure/azure-sdk-for-python/issues
10
- Project-URL: Source, https://github.com/Azure/azure-sdk-for-python
11
- Keywords: azure,azure sdk
12
- Classifier: Development Status :: 5 - Production/Stable
13
- Classifier: Programming Language :: Python
14
- Classifier: Programming Language :: Python :: 3
15
- Classifier: Programming Language :: Python :: 3 :: Only
16
- Classifier: Programming Language :: Python :: 3.8
17
- Classifier: Programming Language :: Python :: 3.9
18
- Classifier: Programming Language :: Python :: 3.10
19
- Classifier: Programming Language :: Python :: 3.11
20
- Classifier: License :: OSI Approved :: MIT License
21
- Classifier: Operating System :: OS Independent
22
- Requires-Python: >=3.8
23
- Description-Content-Type: text/markdown
24
- License-File: NOTICE.txt
25
- Requires-Dist: promptflow-devkit >=1.15.0
26
- Requires-Dist: promptflow-core >=1.15.0
27
- Requires-Dist: pyjwt >=2.8.0
28
- Requires-Dist: azure-identity >=1.16.0
29
- Requires-Dist: azure-core >=1.30.2
30
- Requires-Dist: nltk >=3.9.1
31
- Provides-Extra: remote
32
- Requires-Dist: promptflow-azure <2.0.0,>=1.15.0 ; extra == 'remote'
33
- Requires-Dist: azure-ai-inference >=1.0.0b4 ; extra == 'remote'
34
-
35
- # Azure AI Evaluation client library for Python
36
-
37
- Use Azure AI Evaluation SDK to assess the performance of your generative AI applications. Generative AI application generations are quantitatively measured with mathematical based metrics, AI-assisted quality and safety metrics. Metrics are defined as `evaluators`. Built-in or custom evaluators can provide comprehensive insights into the application's capabilities and limitations.
38
-
39
- Use Azure AI Evaluation SDK to:
40
- - Evaluate existing data from generative AI applications
41
- - Evaluate generative AI applications
42
- - Evaluate by generating mathematical, AI-assisted quality and safety metrics
43
-
44
- Azure AI SDK provides following to evaluate Generative AI Applications:
45
- - [Evaluators][evaluators] - Generate scores individually or when used together with `evaluate` API.
46
- - [Evaluate API][evaluate_api] - Python API to evaluate dataset or application using built-in or custom evaluators.
47
-
48
- [Source code][source_code]
49
- | [Package (PyPI)][evaluation_pypi]
50
- | [API reference documentation][evaluation_ref_docs]
51
- | [Product documentation][product_documentation]
52
- | [Samples][evaluation_samples]
53
-
54
-
55
- ## Getting started
56
-
57
- ### Prerequisites
58
-
59
- - Python 3.8 or later is required to use this package.
60
- - [Optional] You must have [Azure AI Project][ai_project] or [Azure Open AI][azure_openai] to use AI-assisted evaluators
61
-
62
- ### Install the package
63
-
64
- Install the Azure AI Evaluation SDK for Python with [pip][pip_link]:
65
-
66
- ```bash
67
- pip install azure-ai-evaluation
68
- ```
69
- If you want to track results in [AI Studio][ai_studio], install `remote` extra:
70
- ```python
71
- pip install azure-ai-evaluation[remote]
72
- ```
73
-
74
- ## Key concepts
75
-
76
- ### Evaluators
77
-
78
- Evaluators are custom or prebuilt classes or functions that are designed to measure the quality of the outputs from language models or generative AI applications.
79
-
80
- #### Built-in evaluators
81
-
82
- Built-in evaluators are out of box evaluators provided by Microsoft:
83
- | Category | Evaluator class |
84
- |-----------|------------------------------------------------------------------------------------------------------------------------------------|
85
- | [Performance and quality][performance_and_quality_evaluators] (AI-assisted) | `GroundednessEvaluator`, `RelevanceEvaluator`, `CoherenceEvaluator`, `FluencyEvaluator`, `SimilarityEvaluator`, `RetrievalEvaluator` |
86
- | [Performance and quality][performance_and_quality_evaluators] (NLP) | `F1ScoreEvaluator`, `RougeScoreEvaluator`, `GleuScoreEvaluator`, `BleuScoreEvaluator`, `MeteorScoreEvaluator`|
87
- | [Risk and safety][risk_and_safety_evaluators] (AI-assisted) | `ViolenceEvaluator`, `SexualEvaluator`, `SelfHarmEvaluator`, `HateUnfairnessEvaluator`, `IndirectAttackEvaluator`, `ProtectedMaterialEvaluator` |
88
- | [Composite][composite_evaluators] | `QAEvaluator`, `ContentSafetyEvaluator` |
89
-
90
- For more in-depth information on each evaluator definition and how it's calculated, see [Evaluation and monitoring metrics for generative AI][evaluation_metrics].
91
-
92
- ```python
93
- import os
94
-
95
- from azure.ai.evaluation import evaluate, RelevanceEvaluator, ViolenceEvaluator, BleuScoreEvaluator
96
-
97
- # NLP bleu score evaluator
98
- bleu_score_evaluator = BleuScoreEvaluator()
99
- result = bleu_score(
100
- response="Tokyo is the capital of Japan.",
101
- ground_truth="The capital of Japan is Tokyo."
102
- )
103
-
104
- # AI assisted quality evaluator
105
- model_config = {
106
- "azure_endpoint": os.environ.get("AZURE_OPENAI_ENDPOINT"),
107
- "api_key": os.environ.get("AZURE_OPENAI_API_KEY"),
108
- "azure_deployment": os.environ.get("AZURE_OPENAI_DEPLOYMENT"),
109
- }
110
-
111
- relevance_evaluator = RelevanceEvaluator(model_config)
112
- result = relevance_evaluator(
113
- query="What is the capital of Japan?",
114
- response="The capital of Japan is Tokyo."
115
- )
116
-
117
- # AI assisted safety evaluator
118
- azure_ai_project = {
119
- "subscription_id": "<subscription_id>",
120
- "resource_group_name": "<resource_group_name>",
121
- "project_name": "<project_name>",
122
- }
123
-
124
- violence_evaluator = ViolenceEvaluator(azure_ai_project)
125
- result = violence_evaluator(
126
- query="What is the capital of France?",
127
- response="Paris."
128
- )
129
- ```
130
-
131
- #### Custom evaluators
132
-
133
- Built-in evaluators are great out of the box to start evaluating your application's generations. However you can build your own code-based or prompt-based evaluator to cater to your specific evaluation needs.
134
-
135
- ```python
136
-
137
- # Custom evaluator as a function to calculate response length
138
- def response_length(response, **kwargs):
139
- return len(response)
140
-
141
- # Custom class based evaluator to check for blocked words
142
- class BlocklistEvaluator:
143
- def __init__(self, blocklist):
144
- self._blocklist = blocklist
145
-
146
- def __call__(self, *, response: str, **kwargs):
147
- score = any([word in answer for word in self._blocklist])
148
- return {"score": score}
149
-
150
- blocklist_evaluator = BlocklistEvaluator(blocklist=["bad, worst, terrible"])
151
-
152
- result = response_length("The capital of Japan is Tokyo.")
153
- result = blocklist_evaluator(answer="The capital of Japan is Tokyo.")
154
-
155
- ```
156
-
157
- ### Evaluate API
158
- The package provides an `evaluate` API which can be used to run multiple evaluators together to evaluate generative AI application response.
159
-
160
- #### Evaluate existing dataset
161
-
162
- ```python
163
- from azure.ai.evaluation import evaluate
164
-
165
- result = evaluate(
166
- data="data.jsonl", # provide your data here
167
- evaluators={
168
- "blocklist": blocklist_evaluator,
169
- "relevance": relevance_evaluator
170
- },
171
- # column mapping
172
- evaluator_config={
173
- "relevance": {
174
- "column_mapping": {
175
- "query": "${data.queries}"
176
- "ground_truth": "${data.ground_truth}"
177
- "response": "${outputs.response}"
178
- }
179
- }
180
- }
181
- # Optionally provide your AI Studio project information to track your evaluation results in your Azure AI Studio project
182
- azure_ai_project = azure_ai_project,
183
- # Optionally provide an output path to dump a json of metric summary, row level data and metric and studio URL
184
- output_path="./evaluation_results.json"
185
- )
186
- ```
187
- For more details refer to [Evaluate on test dataset using evaluate()][evaluate_dataset]
188
-
189
- #### Evaluate generative AI application
190
- ```python
191
- from askwiki import askwiki
192
-
193
- result = evaluate(
194
- data="data.jsonl",
195
- target=askwiki,
196
- evaluators={
197
- "relevance": relevance_eval
198
- },
199
- evaluator_config={
200
- "default": {
201
- "column_mapping": {
202
- "query": "${data.queries}"
203
- "context": "${outputs.context}"
204
- "response": "${outputs.response}"
205
- }
206
- }
207
- }
208
- )
209
- ```
210
- Above code snippet refers to askwiki application in this [sample][evaluate_app].
211
-
212
- For more details refer to [Evaluate on a target][evaluate_target]
213
-
214
- ### Simulator
215
-
216
-
217
- Simulators allow users to generate synthentic data using their application. Simulator expects the user to have a callback method that invokes their AI application. The intergration between your AI application and the simulator happens at the callback method. Here's how a sample callback would look like:
218
-
219
-
220
- ```python
221
- async def callback(
222
- messages: Dict[str, List[Dict]],
223
- stream: bool = False,
224
- session_state: Any = None,
225
- context: Optional[Dict[str, Any]] = None,
226
- ) -> dict:
227
- messages_list = messages["messages"]
228
- # Get the last message from the user
229
- latest_message = messages_list[-1]
230
- query = latest_message["content"]
231
- # Call your endpoint or AI application here
232
- # response should be a string
233
- response = call_to_your_application(query, messages_list, context)
234
- formatted_response = {
235
- "content": response,
236
- "role": "assistant",
237
- "context": "",
238
- }
239
- messages["messages"].append(formatted_response)
240
- return {"messages": messages["messages"], "stream": stream, "session_state": session_state, "context": context}
241
- ```
242
-
243
- The simulator initialization and invocation looks like this:
244
- ```python
245
- from azure.ai.evaluation.simulator import Simulator
246
- model_config = {
247
- "azure_endpoint": os.environ.get("AZURE_ENDPOINT"),
248
- "azure_deployment": os.environ.get("AZURE_DEPLOYMENT_NAME"),
249
- "api_version": os.environ.get("AZURE_API_VERSION"),
250
- }
251
- custom_simulator = Simulator(model_config=model_config)
252
- outputs = asyncio.run(custom_simulator(
253
- target=callback,
254
- conversation_turns=[
255
- [
256
- "What should I know about the public gardens in the US?",
257
- ],
258
- [
259
- "How do I simulate data against LLMs",
260
- ],
261
- ],
262
- max_conversation_turns=2,
263
- ))
264
- with open("simulator_output.jsonl", "w") as f:
265
- for output in outputs:
266
- f.write(output.to_eval_qr_json_lines())
267
- ```
268
-
269
- #### Adversarial Simulator
270
-
271
- ```python
272
- from azure.ai.evaluation.simulator import AdversarialSimulator, AdversarialScenario
273
- from azure.identity import DefaultAzureCredential
274
- azure_ai_project = {
275
- "subscription_id": <subscription_id>,
276
- "resource_group_name": <resource_group_name>,
277
- "project_name": <project_name>
278
- }
279
- scenario = AdversarialScenario.ADVERSARIAL_QA
280
- simulator = AdversarialSimulator(azure_ai_project=azure_ai_project, credential=DefaultAzureCredential())
281
-
282
- outputs = asyncio.run(
283
- simulator(
284
- scenario=scenario,
285
- max_conversation_turns=1,
286
- max_simulation_results=3,
287
- target=callback
288
- )
289
- )
290
-
291
- print(outputs.to_eval_qr_json_lines())
292
- ```
293
-
294
- For more details about the simulator, visit the following links:
295
- - [Adversarial Simulation docs][adversarial_simulation_docs]
296
- - [Adversarial scenarios][adversarial_simulation_scenarios]
297
- - [Simulating jailbreak attacks][adversarial_jailbreak]
298
-
299
- ## Examples
300
-
301
- In following section you will find examples of:
302
- - [Evaluate an application][evaluate_app]
303
- - [Evaluate different models][evaluate_models]
304
- - [Custom Evaluators][custom_evaluators]
305
- - [Adversarial Simulation][adversarial_simulation]
306
- - [Simulate with conversation starter][simulate_with_conversation_starter]
307
-
308
- More examples can be found [here][evaluate_samples].
309
-
310
- ## Troubleshooting
311
-
312
- ### General
313
-
314
- Please refer to [troubleshooting][evaluation_tsg] for common issues.
315
-
316
- ### Logging
317
-
318
- This library uses the standard
319
- [logging][python_logging] library for logging.
320
- Basic information about HTTP sessions (URLs, headers, etc.) is logged at INFO
321
- level.
322
-
323
- Detailed DEBUG level logging, including request/response bodies and unredacted
324
- headers, can be enabled on a client with the `logging_enable` argument.
325
-
326
- See full SDK logging documentation with examples [here][sdk_logging_docs].
327
-
328
- ## Next steps
329
-
330
- - View our [samples][evaluation_samples].
331
- - View our [documentation][product_documentation]
332
-
333
- ## Contributing
334
-
335
- This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit [cla.microsoft.com][cla].
336
-
337
- When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
338
-
339
- This project has adopted the [Microsoft Open Source Code of Conduct][code_of_conduct]. For more information see the [Code of Conduct FAQ][coc_faq] or contact [opencode@microsoft.com][coc_contact] with any additional questions or comments.
340
-
341
- <!-- LINKS -->
342
-
343
- [source_code]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/evaluation/azure-ai-evaluation
344
- [evaluation_pypi]: https://pypi.org/project/azure-ai-evaluation/
345
- [evaluation_ref_docs]: https://learn.microsoft.com/python/api/azure-ai-evaluation/azure.ai.evaluation?view=azure-python-preview
346
- [evaluation_samples]: https://github.com/Azure-Samples/azureai-samples/tree/main/scenarios
347
- [product_documentation]: https://learn.microsoft.com/azure/ai-studio/how-to/develop/evaluate-sdk
348
- [python_logging]: https://docs.python.org/3/library/logging.html
349
- [sdk_logging_docs]: https://docs.microsoft.com/azure/developer/python/azure-sdk-logging
350
- [azure_core_readme]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/core/azure-core/README.md
351
- [pip_link]: https://pypi.org/project/pip/
352
- [azure_core_ref_docs]: https://aka.ms/azsdk-python-core-policies
353
- [azure_core]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/core/azure-core/README.md
354
- [azure_identity]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity
355
- [cla]: https://cla.microsoft.com
356
- [code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
357
- [coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/
358
- [coc_contact]: mailto:opencode@microsoft.com
359
- [evaluate_target]: https://learn.microsoft.com/azure/ai-studio/how-to/develop/evaluate-sdk#evaluate-on-a-target
360
- [evaluate_dataset]: https://learn.microsoft.com/azure/ai-studio/how-to/develop/evaluate-sdk#evaluate-on-test-dataset-using-evaluate
361
- [evaluators]: https://learn.microsoft.com/python/api/azure-ai-evaluation/azure.ai.evaluation?view=azure-python-preview
362
- [evaluate_api]: https://learn.microsoft.com/python/api/azure-ai-evaluation/azure.ai.evaluation?view=azure-python-preview#azure-ai-evaluation-evaluate
363
- [evaluate_app]: https://github.com/Azure-Samples/azureai-samples/tree/main/scenarios/evaluate/evaluate_app
364
- [evaluation_tsg]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/evaluation/azure-ai-evaluation/TROUBLESHOOTING.md
365
- [ai_studio]: https://learn.microsoft.com/azure/ai-studio/what-is-ai-studio
366
- [ai_project]: https://learn.microsoft.com/azure/ai-studio/how-to/create-projects?tabs=ai-studio
367
- [azure_openai]: https://learn.microsoft.com/azure/ai-services/openai/
368
- [evaluate_models]: https://github.com/Azure-Samples/azureai-samples/tree/main/scenarios/evaluate/evaluate_endpoints
369
- [custom_evaluators]: https://github.com/Azure-Samples/azureai-samples/tree/main/scenarios/evaluate/evaluate_custom
370
- [evaluate_samples]: https://github.com/Azure-Samples/azureai-samples/tree/main/scenarios/evaluate
371
- [evaluation_metrics]: https://learn.microsoft.com/azure/ai-studio/concepts/evaluation-metrics-built-in
372
- [performance_and_quality_evaluators]: https://learn.microsoft.com/azure/ai-studio/how-to/develop/evaluate-sdk#performance-and-quality-evaluators
373
- [risk_and_safety_evaluators]: https://learn.microsoft.com/azure/ai-studio/how-to/develop/evaluate-sdk#risk-and-safety-evaluators
374
- [composite_evaluators]: https://learn.microsoft.com/azure/ai-studio/how-to/develop/evaluate-sdk#composite-evaluators
375
- [adversarial_simulation_docs]: https://learn.microsoft.com/azure/ai-studio/how-to/develop/simulator-interaction-data#generate-adversarial-simulations-for-safety-evaluation
376
- [adversarial_simulation_scenarios]: https://learn.microsoft.com/azure/ai-studio/how-to/develop/simulator-interaction-data#supported-adversarial-simulation-scenarios
377
- [adversarial_simulation]: https://github.com/Azure-Samples/azureai-samples/tree/main/scenarios/evaluate/simulate_adversarial
378
- [simulate_with_conversation_starter]: https://github.com/Azure-Samples/azureai-samples/tree/main/scenarios/evaluate/simulate_conversation_starter
379
- [adversarial_jailbreak]: https://learn.microsoft.com/azure/ai-studio/how-to/develop/simulator-interaction-data#simulating-jailbreak-attacks
380
-
381
-
382
- # Release History
383
-
384
- ## 1.0.0 (2024-11-13)
385
-
386
- ### Breaking Changes
387
- - The `parallel` parameter has been removed from composite evaluators: `QAEvaluator`, `ContentSafetyChatEvaluator`, and `ContentSafetyMultimodalEvaluator`. To control evaluator parallelism, you can now use the `_parallel` keyword argument, though please note that this private parameter may change in the future.
388
- - Parameters `query_response_generating_prompty_kwargs` and `user_simulator_prompty_kwargs` have been renamed to `query_response_generating_prompty_options` and `user_simulator_prompty_options` in the Simulator's __call__ method.
389
-
390
- ### Bugs Fixed
391
- - Fixed an issue where the `output_path` parameter in the `evaluate` API did not support relative path.
392
- - Output of adversarial simulators are of type `JsonLineList` and the helper function `to_eval_qr_json_lines` now outputs context from both user and assistant turns along with `category` if it exists in the conversation
393
- - Fixed an issue where during long-running simulations, API token expires causing "Forbidden" error. Instead, users can now set an environment variable `AZURE_TOKEN_REFRESH_INTERVAL` to refresh the token more frequently to prevent expiration and ensure continuous operation of the simulation.
394
- - Fix `evaluate` function not producing aggregated metrics if ANY values to be aggregated were None, NaN, or
395
- otherwise difficult to process. Such values are ignored fully, so the aggregated metric of `[1, 2, 3, NaN]`
396
- would be 2, not 1.5.
397
-
398
- ### Other Changes
399
- - Refined error messages for serviced-based evaluators and simulators.
400
- - Tracing has been disabled due to Cosmos DB initialization issue.
401
- - Introduced environment variable `AI_EVALS_DISABLE_EXPERIMENTAL_WARNING` to disable the warning message for experimental features.
402
- - Changed the randomization pattern for `AdversarialSimulator` such that there is an almost equal number of Adversarial harm categories (e.g. Hate + Unfairness, Self-Harm, Violence, Sex) represented in the `AdversarialSimulator` outputs. Previously, for 200 `max_simulation_results` a user might see 140 results belonging to the 'Hate + Unfairness' category and 40 results belonging to the 'Self-Harm' category. Now, user will see 50 results for each of Hate + Unfairness, Self-Harm, Violence, and Sex.
403
- - For the `DirectAttackSimulator`, the prompt templates used to generate simulated outputs for each Adversarial harm category will no longer be in a randomized order by default. To override this behavior, pass `randomize_order=True` when you call the `DirectAttackSimulator`, for example:
404
- ```python
405
- adversarial_simulator = DirectAttackSimulator(azure_ai_project=azure_ai_project, credential=DefaultAzureCredential())
406
- outputs = asyncio.run(
407
- adversarial_simulator(
408
- scenario=scenario,
409
- target=callback,
410
- randomize_order=True
411
- )
412
- )
413
- ```
414
-
415
- ## 1.0.0b5 (2024-10-28)
416
-
417
- ### Features Added
418
- - Added `GroundednessProEvaluator`, which is a service-based evaluator for determining response groundedness.
419
- - Groundedness detection in Non Adversarial Simulator via query/context pairs
420
- ```python
421
- import importlib.resources as pkg_resources
422
- package = "azure.ai.evaluation.simulator._data_sources"
423
- resource_name = "grounding.json"
424
- custom_simulator = Simulator(model_config=model_config)
425
- conversation_turns = []
426
- with pkg_resources.path(package, resource_name) as grounding_file:
427
- with open(grounding_file, "r") as file:
428
- data = json.load(file)
429
- for item in data:
430
- conversation_turns.append([item])
431
- outputs = asyncio.run(custom_simulator(
432
- target=callback,
433
- conversation_turns=conversation_turns,
434
- max_conversation_turns=1,
435
- ))
436
- ```
437
- - Adding evaluator for multimodal use cases
438
-
439
- ### Breaking Changes
440
- - Renamed environment variable `PF_EVALS_BATCH_USE_ASYNC` to `AI_EVALS_BATCH_USE_ASYNC`.
441
- - `RetrievalEvaluator` now requires a `context` input in addition to `query` in single-turn evaluation.
442
- - `RelevanceEvaluator` no longer takes `context` as an input. It now only takes `query` and `response` in single-turn evaluation.
443
- - `FluencyEvaluator` no longer takes `query` as an input. It now only takes `response` in single-turn evaluation.
444
- - AdversarialScenario enum does not include `ADVERSARIAL_INDIRECT_JAILBREAK`, invoking IndirectJailbreak or XPIA should be done with `IndirectAttackSimulator`
445
- - Outputs of `Simulator` and `AdversarialSimulator` previously had `to_eval_qa_json_lines` and now has `to_eval_qr_json_lines`. Where `to_eval_qa_json_lines` had:
446
- ```json
447
- {"question": <user_message>, "answer": <assistant_message>}
448
- ```
449
- `to_eval_qr_json_lines` now has:
450
- ```json
451
- {"query": <user_message>, "response": assistant_message}
452
- ```
453
-
454
- ### Bugs Fixed
455
- - Non adversarial simulator works with `gpt-4o` models using the `json_schema` response format
456
- - Fixed an issue where the `evaluate` API would fail with "[WinError 32] The process cannot access the file because it is being used by another process" when venv folder and target function file are in the same directory.
457
- - Fix evaluate API failure when `trace.destination` is set to `none`
458
- - Non adversarial simulator now accepts context from the callback
459
-
460
- ### Other Changes
461
- - Improved error messages for the `evaluate` API by enhancing the validation of input parameters. This update provides more detailed and actionable error descriptions.
462
- - `GroundednessEvaluator` now supports `query` as an optional input in single-turn evaluation. If `query` is provided, a different prompt template will be used for the evaluation.
463
- - To align with our support of a diverse set of models, the following evaluators will now have a new key in their result output without the `gpt_` prefix. To maintain backwards compatibility, the old key with the `gpt_` prefix will still be present in the output; however, it is recommended to use the new key moving forward as the old key will be deprecated in the future.
464
- - `CoherenceEvaluator`
465
- - `RelevanceEvaluator`
466
- - `FluencyEvaluator`
467
- - `GroundednessEvaluator`
468
- - `SimilarityEvaluator`
469
- - `RetrievalEvaluator`
470
- - The following evaluators will now have a new key in their result output including LLM reasoning behind the score. The new key will follow the pattern "<metric_name>_reason". The reasoning is the result of a more detailed prompt template being used to generate the LLM response. Note that this requires the maximum number of tokens used to run these evaluators to be increased.
471
-
472
- | Evaluator | New `max_token` for Generation |
473
- | --- | --- |
474
- | `CoherenceEvaluator` | 800 |
475
- | `RelevanceEvaluator` | 800 |
476
- | `FluencyEvaluator` | 800 |
477
- | `GroundednessEvaluator` | 800 |
478
- | `RetrievalEvaluator` | 1600 |
479
- - Improved the error message for storage access permission issues to provide clearer guidance for users.
480
-
481
- ## 1.0.0b4 (2024-10-16)
482
-
483
- ### Breaking Changes
484
-
485
- - Removed `numpy` dependency. All NaN values returned by the SDK have been changed to from `numpy.nan` to `math.nan`.
486
- - `credential` is now required to be passed in for all content safety evaluators and `ProtectedMaterialsEvaluator`. `DefaultAzureCredential` will no longer be chosen if a credential is not passed.
487
- - Changed package extra name from "pf-azure" to "remote".
488
-
489
- ### Bugs Fixed
490
- - Adversarial Conversation simulations would fail with `Forbidden`. Added logic to re-fetch token in the exponential retry logic to retrive RAI Service response.
491
- - Fixed an issue where the Evaluate API did not fail due to missing inputs when the target did not return columns required by the evaluators.
492
-
493
- ### Other Changes
494
- - Enhance the error message to provide clearer instruction when required packages for the remote tracking feature are missing.
495
- - Print the per-evaluator run summary at the end of the Evaluate API call to make troubleshooting row-level failures easier.
496
-
497
- ## 1.0.0b3 (2024-10-01)
498
-
499
- ### Features Added
500
-
501
- - Added `type` field to `AzureOpenAIModelConfiguration` and `OpenAIModelConfiguration`
502
- - The following evaluators now support `conversation` as an alternative input to their usual single-turn inputs:
503
- - `ViolenceEvaluator`
504
- - `SexualEvaluator`
505
- - `SelfHarmEvaluator`
506
- - `HateUnfairnessEvaluator`
507
- - `ProtectedMaterialEvaluator`
508
- - `IndirectAttackEvaluator`
509
- - `CoherenceEvaluator`
510
- - `RelevanceEvaluator`
511
- - `FluencyEvaluator`
512
- - `GroundednessEvaluator`
513
- - Surfaced `RetrievalScoreEvaluator`, formally an internal part of `ChatEvaluator` as a standalone conversation-only evaluator.
514
-
515
- ### Breaking Changes
516
-
517
- - Removed `ContentSafetyChatEvaluator` and `ChatEvaluator`
518
- - The `evaluator_config` parameter of `evaluate` now maps in evaluator name to a dictionary `EvaluatorConfig`, which is a `TypedDict`. The
519
- `column_mapping` between `data` or `target` and evaluator field names should now be specified inside this new dictionary:
520
-
521
- Before:
522
- ```python
523
- evaluate(
524
- ...,
525
- evaluator_config={
526
- "hate_unfairness": {
527
- "query": "${data.question}",
528
- "response": "${data.answer}",
529
- }
530
- },
531
- ...
532
- )
533
- ```
534
-
535
- After
536
- ```python
537
- evaluate(
538
- ...,
539
- evaluator_config={
540
- "hate_unfairness": {
541
- "column_mapping": {
542
- "query": "${data.question}",
543
- "response": "${data.answer}",
544
- }
545
- }
546
- },
547
- ...
548
- )
549
- ```
550
-
551
- - Simulator now requires a model configuration to call the prompty instead of an Azure AI project scope. This enables the usage of simulator with Entra ID based auth.
552
- Before:
553
- ```python
554
- azure_ai_project = {
555
- "subscription_id": os.environ.get("AZURE_SUBSCRIPTION_ID"),
556
- "resource_group_name": os.environ.get("RESOURCE_GROUP"),
557
- "project_name": os.environ.get("PROJECT_NAME"),
558
- }
559
- sim = Simulator(azure_ai_project=azure_ai_project, credentails=DefaultAzureCredentials())
560
- ```
561
- After:
562
- ```python
563
- model_config = {
564
- "azure_endpoint": os.environ.get("AZURE_OPENAI_ENDPOINT"),
565
- "azure_deployment": os.environ.get("AZURE_DEPLOYMENT"),
566
- }
567
- sim = Simulator(model_config=model_config)
568
- ```
569
- If `api_key` is not included in the `model_config`, the prompty runtime in `promptflow-core` will pick up `DefaultAzureCredential`.
570
-
571
- ### Bugs Fixed
572
-
573
- - Fixed issue where Entra ID authentication was not working with `AzureOpenAIModelConfiguration`
574
-
575
- ## 1.0.0b2 (2024-09-24)
576
-
577
- ### Breaking Changes
578
-
579
- - `data` and `evaluators` are now required keywords in `evaluate`.
580
-
581
- ## 1.0.0b1 (2024-09-20)
582
-
583
- ### Breaking Changes
584
-
585
- - The `synthetic` namespace has been renamed to `simulator`, and sub-namespaces under this module have been removed
586
- - The `evaluate` and `evaluators` namespaces have been removed, and everything previously exposed in those modules has been added to the root namespace `azure.ai.evaluation`
587
- - The parameter name `project_scope` in content safety evaluators have been renamed to `azure_ai_project` for consistency with evaluate API and simulators.
588
- - Model configurations classes are now of type `TypedDict` and are exposed in the `azure.ai.evaluation` module instead of coming from `promptflow.core`.
589
- - Updated the parameter names for `question` and `answer` in built-in evaluators to more generic terms: `query` and `response`.
590
-
591
- ### Features Added
592
-
593
- - First preview
594
- - This package is port of `promptflow-evals`. New features will be added only to this package moving forward.
595
- - Added a `TypedDict` for `AzureAIProject` that allows for better intellisense and type checking when passing in project information
@@ -1,70 +0,0 @@
1
- NOTICES AND INFORMATION
2
- Do Not Translate or Localize
3
-
4
- This software incorporates material from third parties.
5
- Microsoft makes certain open source code available at https://3rdpartysource.microsoft.com,
6
- or you may send a check or money order for US $5.00, including the product name,
7
- the open source component name, platform, and version number, to:
8
-
9
- Source Code Compliance Team
10
- Microsoft Corporation
11
- One Microsoft Way
12
- Redmond, WA 98052
13
- USA
14
-
15
- Notwithstanding any other terms, you may reverse engineer this software to the extent
16
- required to debug changes to any libraries licensed under the GNU Lesser General Public License.
17
-
18
- License notice for nltk
19
- ---------------------------------------------------------
20
-
21
- Copyright 2024 The NLTK Project
22
-
23
- Licensed under the Apache License, Version 2.0 (the "License");
24
- you may not use this file except in compliance with the License.
25
- You may obtain a copy of the License at
26
-
27
- http://www.apache.org/licenses/LICENSE-2.0
28
-
29
- Unless required by applicable law or agreed to in writing, software
30
- distributed under the License is distributed on an "AS IS" BASIS,
31
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32
- See the License for the specific language governing permissions and
33
- limitations under the License.
34
-
35
- License notice for rouge-score
36
- ---------------------------------------------------------
37
-
38
- Copyright 2024 The Google Research Authors
39
-
40
- Licensed under the Apache License, Version 2.0 (the "License");
41
- you may not use this file except in compliance with the License.
42
- You may obtain a copy of the License at
43
-
44
- http://www.apache.org/licenses/LICENSE-2.0
45
-
46
- Unless required by applicable law or agreed to in writing, software
47
- distributed under the License is distributed on an "AS IS" BASIS,
48
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
49
- See the License for the specific language governing permissions and
50
- limitations under the License.
51
-
52
-
53
- License notice for [Is GPT-4 a reliable rater? Evaluating consistency in GPT-4's text ratings](https://www.frontiersin.org/journals/education/articles/10.3389/feduc.2023.1272229/full)
54
- ------------------------------------------------------------------------------------------------------------------
55
- Copyright © 2023 Hackl, Müller, Granitzer and Sailer. This work is openly licensed via [CC BY 4.0](http://creativecommons.org/licenses/by/4.0/).
56
-
57
-
58
- License notice for [Is ChatGPT a Good NLG Evaluator? A Preliminary Study](https://aclanthology.org/2023.newsum-1.1) (Wang et al., NewSum 2023)
59
- ------------------------------------------------------------------------------------------------------------------
60
- Copyright © 2023. This work is openly licensed via [CC BY 4.0](http://creativecommons.org/licenses/by/4.0/).
61
-
62
-
63
- License notice for [SummEval: Re-evaluating Summarization Evaluation.](https://doi.org/10.1162/tacl_a_00373) (Fabbri et al.)
64
- ------------------------------------------------------------------------------------------------------------------
65
- © 2021 Association for Computational Linguistics. This work is openly licensed via [CC BY 4.0](http://creativecommons.org/licenses/by/4.0/).
66
-
67
-
68
- License notice for [Evaluation Metrics in the Era of GPT-4: Reliably Evaluating Large Language Models on Sequence to Sequence Tasks](https://aclanthology.org/2023.emnlp-main.543) (Sottana et al., EMNLP 2023)
69
- ------------------------------------------------------------------------------------------------------------------
70
- © 2023 Association for Computational Linguistics. This work is openly licensed via [CC BY 4.0](http://creativecommons.org/licenses/by/4.0/).