Skip to content

Commit 02c88cf

Browse files
authored
README Update for Evaluation (Azure#38551)
* Update README.md * Update sample_evaluations.py * Update README.md * Update README.md
1 parent ed5fd4d commit 02c88cf

File tree

2 files changed

+118
-2
lines changed

2 files changed

+118
-2
lines changed

sdk/ai/azure-ai-projects/README.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,119 @@ print("Deleted agent")
718718

719719
<!-- END SNIPPET -->
720720

721+
### Evaluation
722+
723+
Evaluation in Azure AI Project client library is designed to assess the performance of generative AI applications in the cloud. The output of Generative AI application is quantitively 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.
724+
725+
#### Evaluator
726+
727+
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.
728+
729+
Evaluators are made available via [azure-ai-evaluation][azure_ai_evaluation] SDK for local experience and also in [Evaluator Library][evaluator_library] in Azure AI Studio for using them in the cloud.
730+
731+
More details on built-in and custom evaluators can be found [here][evaluators].
732+
733+
#### Run Evaluation in cloud:
734+
735+
To run evaluation in cloud the following are needed:
736+
737+
- Evaluators
738+
- Data to be evaluated
739+
- [Optional] Azure Open AI model.
740+
741+
##### Evaluators
742+
743+
For running evaluator in cloud, evaluator `ID` is needed. To get it via code you use [azure-ai-evaluation][azure_ai_evaluation]
744+
745+
```
746+
# pip install azure-ai-evaluation
747+
748+
from azure.ai.evaluation import RelevanceEvaluator
749+
750+
evaluator_id = RelevanceEvaluator.id
751+
```
752+
753+
##### Data to be evaluated
754+
755+
Evaluation in the cloud supports data in form of `jsonl` file. Data can be uploaded via the helper method `upload_file` on the project client.
756+
757+
```python
758+
# Upload data for evaluation and get dataset id
759+
data_id, _ = project_client.upload_file("<data_file.jsonl>")
760+
```
761+
762+
##### [Optional] Azure OpenAI Model
763+
764+
Azure AI Studio project comes with a default Azure Open AI endpoint which can be easily accessed using following code. This gives you the endpoint details for you Azure OpenAI endpoint. Some of the evaluators need model that supports chat completion.
765+
766+
```python
767+
default_connection = project_client.connections.get_default(connection_type=ConnectionType.AZURE_OPEN_AI)
768+
```
769+
770+
##### Example Remote Evaluation
771+
772+
```python
773+
import os
774+
from azure.ai.projects import AIProjectClient
775+
from azure.identity import DefaultAzureCredential
776+
from azure.ai.projects.models import Evaluation, Dataset, EvaluatorConfiguration, ConnectionType
777+
from azure.ai.evaluation import F1ScoreEvaluator, RelevanceEvaluator, HateUnfairnessEvaluator
778+
779+
780+
# Create project client
781+
project_client = AIProjectClient.from_connection_string(
782+
credential=DefaultAzureCredential(),
783+
conn_str=os.environ["PROJECT_CONNECTION_STRING"],
784+
)
785+
786+
# Upload data for evaluation and get dataset id
787+
data_id, _ = project_client.upload_file("<data_file.jsonl>")
788+
789+
deployment_name = "<deployment_name>"
790+
api_version = "<api_version>"
791+
792+
# Create an evaluation
793+
evaluation = Evaluation(
794+
display_name="Remote Evaluation",
795+
description="Evaluation of dataset",
796+
data=Dataset(id=data_id),
797+
evaluators={
798+
"f1_score": EvaluatorConfiguration(
799+
id=F1ScoreEvaluator.id,
800+
),
801+
"relevance": EvaluatorConfiguration(
802+
id=RelevanceEvaluator.id,
803+
init_params={
804+
"model_config": default_connection.to_evaluator_model_config(
805+
deployment_name=deployment_name, api_version=api_version
806+
)
807+
},
808+
),
809+
"violence": EvaluatorConfiguration(
810+
id=ViolenceEvaluator.id,
811+
init_params={"azure_ai_project": project_client.scope},
812+
),
813+
},
814+
)
815+
816+
817+
evaluation_response = project_client.evaluations.create(
818+
evaluation=evaluation,
819+
)
820+
821+
# Get evaluation
822+
get_evaluation_response = project_client.evaluations.get(evaluation_response.id)
823+
824+
print("----------------------------------------------------------------")
825+
print("Created evaluation, evaluation ID: ", get_evaluation_response.id)
826+
print("Evaluation status: ", get_evaluation_response.status)
827+
if isinstance(get_evaluation_response.properties, dict):
828+
print("AI Studio URI: ", get_evaluation_response.properties["AiStudioEvaluationUri"])
829+
print("----------------------------------------------------------------")
830+
```
831+
832+
NOTE: For running evaluators locally refer to [Evaluate with the Azure AI Evaluation SDK][evaluators].
833+
721834
#### Tracing
722835

723836
You can add an Application Insights Azure resource to your Azure AI Studio project. See the Tracing tab in your studio. If one was enabled, you can get the Application Insights connection string, configure your Agents, and observe the full execution path through Azure Monitor. Typically, you might want to start tracing before you create an Agent.
@@ -873,3 +986,6 @@ additional questions or comments.
873986
[default_azure_credential]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#defaultazurecredential
874987
[pip]: https://pypi.org/project/pip/
875988
[azure_sub]: https://azure.microsoft.com/free/
989+
[evaluators]: https://learn.microsoft.com/azure/ai-studio/how-to/develop/evaluate-sdk
990+
[azure_ai_evaluation]: https://learn.microsoft.com/python/api/overview/azure/ai-evaluation-readme?view=azure-python-preview
991+
[evaluator_library]: https://learn.microsoft.com/azure/ai-studio/how-to/evaluate-generative-ai-app#view-and-manage-the-evaluators-in-the-evaluator-library

sdk/ai/azure-ai-projects/samples/evaluations/sample_evaluations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
Before running the sample:
1515
1616
pip install azure-identity
17-
pip install "git+https://github.com/Azure/azure-sdk-for-python.git@users/singankit/ai_project_utils#egg=azure-ai-client&subdirectory=sdk/ai/azure-ai-client"
18-
pip install "git+https://github.com/Azure/azure-sdk-for-python.git@users/singankit/demo_evaluators_id#egg=azure-ai-evaluation&subdirectory=sdk/evaluation/azure-ai-evaluation"
17+
pip install azure-ai-projects
18+
pip install azure-ai-evaluation
1919
2020
Set this environment variables with your own values:
2121
PROJECT_CONNECTION_STRING - the Azure AI Project connection string, as found in your AI Studio Project.

0 commit comments

Comments
 (0)