diff --git a/sdk/ai/azure-ai-projects/samples/evaluation/sample_agent_evaluations.py b/sdk/ai/azure-ai-projects/samples/evaluation/sample_agent_evaluations.py index 4c33399b7acd..38e88dc778bc 100644 --- a/sdk/ai/azure-ai-projects/samples/evaluation/sample_agent_evaluations.py +++ b/sdk/ai/azure-ai-projects/samples/evaluation/sample_agent_evaluations.py @@ -21,7 +21,7 @@ Azure AI Foundry project. """ -import os +import os, time from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient @@ -31,22 +31,47 @@ EvaluatorIds, EvaluatorConfiguration, AgentEvaluationSamplingConfiguration, + AgentEvaluationRedactionConfiguration ) from dotenv import load_dotenv load_dotenv() endpoint = os.environ["PROJECT_ENDPOINT"] +model_deployment_name = os.environ["MODEL_DEPLOYMENT_NAME"] + with DefaultAzureCredential(exclude_interactive_browser_credential=False) as credential: with AIProjectClient(endpoint=endpoint, credential=credential) as project_client: # [START evaluations_agent_sample] + agent = project_client.agents.create_agent( + model=model_deployment_name, + name="my-agent", + instructions="You are helpful agent", + ) + print(f"Created agent, agent ID: {agent.id}") + + thread = project_client.agents.create_thread() + print(f"Created thread, thread ID: {thread.id}") + + message = project_client.agents.create_message(thread_id=thread.id, role="user", content="Hello, tell me a joke") + print(f"Created message, message ID: {message.id}") + + run = project_client.agents.create_run(thread_id=thread.id, agent_id=agent.id) + + # Poll the run as long as run status is queued or in progress + while run.status in ["queued", "in_progress", "requires_action"]: + # Wait for a second + time.sleep(1) + run = project_client.agents.get_run(thread_id=thread.id, run_id=run.id) + print(f"Run status: {run.status}") + agent_evaluation_request = AgentEvaluationRequest( - run_id="run-id", - thread_id="thread-id", + run_id=run.id, + thread_id=thread.id, evaluators={ "violence": EvaluatorConfiguration( id=EvaluatorIds.VIOLENCE, @@ -54,7 +79,11 @@ }, sampling_configuration=AgentEvaluationSamplingConfiguration( name="test", - sampling_percent=0.5, + sampling_percent=100, + max_request_rate=100, + ), + redaction_configuration=AgentEvaluationRedactionConfiguration( + redact_score_properties=False, ), app_insights_connection_string=project_client.telemetry.get_connection_string(), )