-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathsample_evaluations.py
82 lines (69 loc) · 3.1 KB
/
sample_evaluations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# pylint: disable=line-too-long,useless-suppression
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
"""
DESCRIPTION:
Given an AIProjectClient, this sample demonstrates how to use the synchronous
`.evaluations` methods to create, get and list evaluations.
USAGE:
python sample_evaluations.py
Before running the sample:
pip install azure-ai-projects azure-identity
Set these environment variables with your own values:
1) PROJECT_ENDPOINT - Required. The Azure AI Project endpoint, as found in the overview page of your
Azure AI Foundry project.
2) DATASET_NAME - Required. The name of the Dataset to create and use in this sample.
"""
import os
from azure.identity import DefaultAzureCredential
from azure.ai.projects.onedp import AIProjectClient
from azure.ai.projects.onedp.models import Evaluation, InputDataset, EvaluatorConfiguration, EvaluationMetrics
from dotenv import load_dotenv
load_dotenv()
endpoint = os.environ["PROJECT_ENDPOINT"]
dataset_name = os.environ["DATASET_NAME"]
with AIProjectClient(
endpoint=endpoint,
credential=DefaultAzureCredential(exclude_interactive_browser_credential=False),
) as project_client:
# [START evaluations_sample]
print(
"Upload a single file and create a new Dataset to reference the file. Here we explicitly specify the dataset version."
)
# dataset: DatasetVersion = project_client.datasets.upload_file_and_create(
# name=dataset_name,
# version="1",
# file="./samples_folder/sample_data_evaluation.jsonl",
# )
# print(dataset)
print("Create an evaluation")
# evaluation = Evaluation(
# display_name="Sample Evaluation",
# data=InputDataset(id="azureml://locations/centraluseuap/workspaces/abc/data/abc/versions/11"),
# evaluators={
# "relevance": EvaluatorConfiguration(
# id=f"aiservices:{EvaluationMetrics.Relevance.value}",
# # id="azureml://registries/azureml/models/Retrieval-Evaluator/versions/4",
# # either client or service (TBD) resolves to azureml://registries/azureml/models/Retrieval-Evaluator/versions/...
# init_params={
# "deployment_name": "gpt-4o",
# },
# ),
# "hate_unfairness": EvaluatorConfiguration(
# # id=f"aiservices:{EvaluationMetrics.HateUnfairness.value}",
# id="azureml://registries/azureml/models/Retrieval-Evaluator/versions/4",
# # either client or service (TBD) resolves to azureml://registries/azureml/models/Hate-Unfairness-Evaluator/versions/...
# init_params={
# "azure_ai_project": endpoint,
# },
# ),
# },
# )
#
# evaluation_respone = project_client.evaluations.create_run(evaluation)
print("Get evaluation")
# get_evaluation_response = project_client.evaluations.get(evaluation_respone.id)
# print(get_evaluation_response)
# [END evaluations_sample]