-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Adding sample for agent evaluation #40844
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
singankit
merged 2 commits into
feature/azure-ai-projects-beta11
from
users/singankit/agent_eval_sample
May 5, 2025
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
sdk/ai/azure-ai-projects/samples/evaluation/sample_agent_evaluations.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # 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 submit evaluation for an agent run. | ||
|
|
||
| USAGE: | ||
| python sample_agent_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. | ||
| """ | ||
|
|
||
| import os | ||
|
|
||
| from azure.identity import DefaultAzureCredential | ||
| from azure.ai.projects import AIProjectClient | ||
| from azure.ai.projects.models import ( | ||
| AgentEvaluationRequest, | ||
| InputDataset, | ||
| EvaluatorIds, | ||
| EvaluatorConfiguration, | ||
| AgentEvaluationSamplingConfiguration | ||
| ) | ||
| from dotenv import load_dotenv | ||
|
|
||
| load_dotenv() | ||
|
|
||
| endpoint = os.environ["PROJECT_ENDPOINT"] | ||
|
|
||
| with DefaultAzureCredential(exclude_interactive_browser_credential=False) as credential: | ||
|
|
||
| with AIProjectClient(endpoint=endpoint, credential=credential) as project_client: | ||
|
|
||
| # [START evaluations_agent_sample] | ||
|
|
||
| agent_evaluation_request = AgentEvaluationRequest( | ||
| run_id="run-id", | ||
| thread_id="thread-id", | ||
| evaluators={ | ||
| "violence": EvaluatorConfiguration( | ||
| id=EvaluatorIds.VIOLENCE, | ||
| ) | ||
| }, | ||
| sampling_configuration=AgentEvaluationSamplingConfiguration( | ||
| name="test", | ||
| sampling_percent=0.5, | ||
| ), | ||
| app_insights_connection_string="connection-string", | ||
| ) | ||
|
|
||
| agent_evaluation_response = project_client.evaluations.create_agent_evaluation( | ||
| evaluation=agent_evaluation_request | ||
| ) | ||
|
|
||
| print(agent_evaluation_response) | ||
|
|
||
| # [END evaluations_agent_sample] | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.